Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Using coc extensions

Heyward Fann edited this pageFeb 19, 2025 ·202 revisions

Why are coc extensions needed?

The main reason for having extensions is to achieve better user experience. Some language servers provided by the community are less straightforward and easy to use as VS Code extensions. Coc extensions can be forked from VS Code extensions and should provide similar or better user experience.

Compared to configured language servers, extensions allow more features.

  • Extensions can contribute properties to the schemacoc-settings.json, like in VS Code you can write the configuration with completion and validation support when you havecoc-json installed.

    Screen Shot 2019-06-26 at 3 22 05 PM
  • Extensions can contribute commands (like VS Code), you can use the coc commands in different ways:

    • Use the command:CocList commands to open the command list and choose one you need.

      screen shot 2018-09-07 at 4 53 12 pm
    • Use:CocCommand with<tab> for command line completion.

    • An example config to use the custom commandTsc fortsserver.watchBuild:

      command! -nargs=0 Tsc    :CocCommand tsserver.watchBuild
  • Extensions can contribute json schemas (loaded bycoc-json)

  • Extensions can contribute snippets that can be loaded bycoc-snippets extension.

  • Extensions can specify more client options, likefileEvents to watch files (requireswatchman installed), andmiddleware which can be used to fix results that return from the language server.

For a deeper dive into the purpose and implementation of coc extensions, please seeHow to write a coc.nvim extension.

Differences between coc extensions and VS Code extensions

  • Coc extensions usecoc.nvim as a dependency instead ofVS Code
  • Coc extensions support language server features by using the API from coc.nvim instead ofvscode-languageclient which can only be used with VS Code.
  • Coc extensions support some features of VS Code extensions:
    • activate anddeactivate api.
    • activationEvents in package.json.
    • Configuration support:contributes.configuration in package.json.
    • Commands support:contributes.commands.
    • JSON validation support via JSON Schema:contributes.jsonValidation.
    • Snippets support.

Manage coc extensions

Single file extensions

Coc.nvim will try to load javascript files in the folder$VIMCONFIG/coc-extensions, each javascript file should be extension of coc.nvim.

An example coc extension that convert character to unicode code point at cursor position.

const{ commands, workspace}=require('coc.nvim')exports.activate=context=>{let{ nvim}=workspacecontext.subscriptions.push(commands.registerCommand('code.convertCodePoint',async()=>{let[pos,line]=awaitnvim.eval('[coc#util#cursor(), getline(".")]')letcurr=pos[1]==0 ?'' :line.slice(pos[1],pos[1]+1)letcode=curr.codePointAt(0)letstr=code.toString(16)str=str.length==4 ?str :'0'.repeat(4-str.length)+strletresult=`${line.slice(0,pos[1])}${'\\u'+str}${line.slice(pos[1]+1)}`awaitnvim.call('setline',['.',result])}))}

Note: it's not possible to use package.json to add additional contributions for single file extensions.

Install extensions

Using:CocInstall:

:CocInstall coc-json coc-css

One or more extension names can be provided.

Note: VS Code extensions can't be used by coc.nvim for now.

Extensions will be loaded and activated after the install succeeds.

Note you can add extension names to theg:coc_global_extensions variable, and coc will install the missing extensions after coc.nvim service started.For example:

letg:coc_global_extensions= ['coc-json','coc-git']

To install extensions with shell script, use command like:

# install coc-json & coc-html and exitvim -c'CocInstall -sync coc-json coc-html|q'

Using custom registry

You can customize npm registry for coc.nvim by addcoc.nvim:registry in the file~/.npmrc:

coc.nvim:registry=https://registry.npmjs.org/

Installing specific versions (for rollback/revert/etc)

If you need to rollback/revert to a specific extension version, or you just want to install a specific version regardless, you can add@version to your install command.

Usingcoc-prettier as an example, in order to install the1.1.17 version, you type:

:CocInstall coc-prettier@1.1.17

Use vim's plugin manager for coc extension

You can manage coc extension by using a plugin manager for vim, likevim-plug, coc will try to load coc extensions from your&rtp

Example for coc-tsserver:

Plug'neoclide/coc-tsserver', {'do':'yarn install --frozen-lockfile'}

After adding this to your vimrc runPlugInstall.

Note: For coc extensions written with typescript, you have to build them when using git, most of time you should installyarn and useyarn install --frozen-lockfile in extension root.

This has the limitation that you can't uninstall the extension by using:CocUninstall and that automatic update support is not available.

Update extensions

Use the command:CocUpdate or:CocUpdateSync to update extensions installed by:CocInstall to the latest version.

For extensions loaded from vim'srtp, you will need update them by your plugin manager.

To enable automatic update, change configurationcoc.preferences.extensionUpdateCheck to"daily" or"weekly", which defaults to"never".

To upgrade extensions with shell script, use command like:

vim -c'CocUpdateSync|q'

Uninstall coc extension

Use vim commandCocUninstall for extensions installed by:CocInstall, for example:

:CocUninstall coc-css

Manage extensions with CocList

Run command:

:CocList extensions

to open CocList buffer, which looks like:

screen shot 2018-09-10 at 10 28 06 pm
  • ? means invalid extension
  • * means extension is activated
  • + means extension is loaded
  • - means extension is disabled

Supported actions (hit<Tab> to activate action menu):

  • toggle default action. activate/deactivate selected extension(s).
  • enable: enable selected extension(s).
  • disable: disable selected extension(s).
  • reload: reload selected extension(s).
  • uninstall: remove selected extension(s).
  • lock: toggle lock of extension, locked extension won't be updated by:CocUpdate

Debug coc extension

If an extension throws uncaught errors, you can get the error message by::messages.

For extensions using a language server, you can use the output channel. Check outhttps://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel.

Useconsole for log messages to log file of coc.nvim, supported methods includingdebuglogerrorinfowarn, checkout:h :CocOpenLog.

You can also use Chrome to debug extensions, checkouthttps://github.com/neoclide/coc.nvim/wiki/Debug-coc.nvim.

Implemented coc extensions

You can find available coc extensions by searchingcoc.nvim on npm, or usecoc-marketplace, which can search and install extensions in coc.nvim directly.

Tips: use:CocConfig to edit the configuration file. Completion & validation are supported aftercoc-json is installed.

REPL

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp