or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/coc.nvim@0.0.x

docs

index.md
tile.json

tessl/npm-coc-nvim

tessl install tessl/npm-coc-nvim@0.0.0

LSP based intellisense engine for neovim & vim8.

extensions.mddocs/core/

Extensions [Basic]

Complexity: Basic | Category: Core

Common Tasks: Install extensions | Update extensions | List extensions | Configure extensions

Extension management for coc.nvim including installation, updates, activation, and monitoring of extensions.

Table of Contents

  • Common Tasks
  • Commands
  • Global Variables
  • Functions
  • CocAction API
  • Using CocList
  • Extension Configuration
  • Utility Functions
  • Global Runtime Variables
  • Examples
  • Error Handling
  • Troubleshooting
  • See Also

Common Tasks

Install Extension

:CocInstall coc-json coc-tsserver

Install one or more extensions from npm.

Update All Extensions

:CocUpdate

Update all installed extensions asynchronously.

List Installed Extensions

:CocList extensions

Interactive list of extensions with actions.

Auto-Install Extensions

let g:coc_global_extensions = ['coc-json', 'coc-tsserver']

Extensions to auto-install on startup.

Check Extension Status

let stats = CocAction('extensionStats')
for ext in stats
  echo ext.id . ' - ' . ext.state
endfor

Commands

:CocInstall

:CocInstall [-terminal] [-sync] {extension}...

Install one or more extensions from npm. Extensions are installed to the extensions directory.

Options:

  • -terminal: Show installation progress in a terminal window
  • -sync: Run installation synchronously (blocks until complete)

Parameters:

  • {extension}...: One or more extension names (e.g., coc-json, coc-tsserver)

Example:

" Install single extension
:CocInstall coc-json

" Install multiple extensions
:CocInstall coc-tsserver coc-eslint coc-prettier

" Install with progress terminal
:CocInstall -terminal coc-python

" Install and wait for completion
:CocInstall -sync coc-rust-analyzer

:CocUninstall

:CocUninstall {extension}...

Uninstall one or more extensions.

Parameters:

  • {extension}...: One or more extension names to uninstall

Example:

:CocUninstall coc-java
:CocUninstall coc-css coc-html

:CocUpdate

:CocUpdate

Update all installed extensions asynchronously. Progress is shown in the status line.

Example:

:CocUpdate

" Map to key
nnoremap <silent> <leader>cu :CocUpdate<CR>

:CocUpdateSync

:CocUpdateSync

Update all installed extensions synchronously. Vim will be blocked until updates complete.

Example:

:CocUpdateSync

:CocRebuild

:CocRebuild

Rebuild all native modules for extensions. Use this after updating Node.js or when extensions fail to load due to native module issues.

Example:

:CocRebuild

" Rebuild after Node.js update
:CocRebuild

:CocWatch

:CocWatch {extension}

Watch an extension directory for changes during development. Changes trigger automatic recompilation.

Parameters:

  • {extension}: Extension name to watch

Example:

:CocWatch coc-tsserver

" Watch custom extension
:CocWatch my-custom-extension

Global Variables

g:coc_global_extensions

let g:coc_global_extensions = ['coc-json', 'coc-tsserver']

List of extensions to automatically install when coc.nvim starts. Extensions are only installed if not already present.

Type: List Default: []

Example:

" Essential extensions
let g:coc_global_extensions = [
  \ 'coc-json',
  \ 'coc-tsserver',
  \ 'coc-eslint',
  \ 'coc-prettier',
  \ 'coc-html',
  \ 'coc-css',
  \ 'coc-python',
  \ 'coc-rust-analyzer',
  \ 'coc-yaml',
  \ 'coc-snippets',
  \ 'coc-pairs'
  \ ]

Functions

coc#add_extension()

coc#add_extension(...names)

Add extensions to the auto-install list. This is deprecated in favor of g:coc_global_extensions.

Parameters:

  • ...names: Variable number of extension names

Example:

call coc#add_extension('coc-json', 'coc-tsserver')

coc#util#install_extension()

coc#util#install_extension(names)

Programmatically install extensions.

Parameters:

  • names: List of extension names to install

Example:

call coc#util#install_extension(['coc-json', 'coc-html'])

" Install if missing
let missing = ['coc-json', 'coc-css']
call coc#util#install_extension(missing)

coc#util#update_extensions()

coc#util#update_extensions([sync])

Update all extensions programmatically.

Parameters:

  • sync: Optional boolean, if 1 runs synchronously

Example:

" Async update
call coc#util#update_extensions()

" Sync update
call coc#util#update_extensions(1)

coc#util#rebuild()

coc#util#rebuild()

Rebuild native modules for all extensions.

Example:

call coc#util#rebuild()

CocAction API

extensionStats

CocAction('extensionStats')
" Returns: list

Get statistics for all installed extensions including version, state, and metadata.

Returns: List of extension stat objects with properties:

  • id: Extension name
  • version: Installed version
  • state: "activated", "disabled", or "unknown"
  • root: Installation directory

Example:

let stats = CocAction('extensionStats')
for ext in stats
  echo ext.id . ' v' . ext.version . ' - ' . ext.state
endfor

" Check specific extension
let tsserver = filter(copy(stats), 'v:val.id == "coc-tsserver"')[0]
echo tsserver.state

loadedExtensions

CocAction('loadedExtensions')
" Returns: list

Get list of currently loaded extension IDs.

Returns: List of extension names.

Example:

let loaded = CocAction('loadedExtensions')
echo 'Loaded extensions: ' . join(loaded, ', ')

" Check if specific extension loaded
if index(loaded, 'coc-tsserver') >= 0
  echo 'TypeScript server is loaded'
endif

activeExtension

CocAction('activeExtension', name)

Activate a specific extension.

Parameters:

  • name: Extension name to activate

Example:

call CocAction('activeExtension', 'coc-tsserver')

deactivateExtension

CocAction('deactivateExtension', name)

Deactivate a specific extension.

Parameters:

  • name: Extension name to deactivate

Example:

call CocAction('deactivateExtension', 'coc-tsserver')

toggleExtension

CocAction('toggleExtension', name)

Toggle an extension's activation state.

Parameters:

  • name: Extension name to toggle

Example:

call CocAction('toggleExtension', 'coc-eslint')

" Quick toggle mapping
nnoremap <silent> <leader>te :call CocAction('toggleExtension', 'coc-eslint')<CR>

reloadExtension

CocAction('reloadExtension', name)

Reload a specific extension. Useful during development.

Parameters:

  • name: Extension name to reload

Example:

call CocAction('reloadExtension', 'coc-tsserver')

" Reload after config changes
nnoremap <silent> <leader>re :call CocAction('reloadExtension', 'coc-tsserver')<CR>

uninstallExtension

CocAction('uninstallExtension', name)

Uninstall a specific extension.

Parameters:

  • name: Extension name to uninstall

Example:

call CocAction('uninstallExtension', 'coc-java')

Using CocList

:CocList extensions

:CocList extensions

Open an interactive list of installed extensions with actions:

  • Activate/Deactivate: Toggle extension state
  • Reload: Reload the extension
  • Disable: Disable the extension
  • Uninstall: Remove the extension
  • Open documentation: View extension README

Example:

" Open extensions list
:CocList extensions

" With preview
:CocList --normal extensions

" Map to key
nnoremap <silent> <leader>ce :CocList extensions<CR>

Extension Configuration

Extensions can be configured in coc-settings.json. Each extension may have its own configuration namespace.

{
  "tsserver.enable": true,
  "tsserver.formatOnType": true,
  "eslint.autoFixOnSave": true,
  "prettier.singleQuote": true,
  "python.linting.enabled": true,
  "python.linting.pylintEnabled": true,
  "rust-analyzer.cargo.loadOutDirsFromCheck": true
}

Access via:

:CocConfig

Utility Functions

coc#util#extension_root()

coc#util#extension_root()
" Returns: string

Get the absolute path to the extensions directory.

Returns: Path to extensions directory.

Example:

let ext_dir = coc#util#extension_root()
echo 'Extensions installed at: ' . ext_dir

" Check if directory exists
if isdirectory(ext_dir)
  echo 'Extension count: ' . len(readdir(ext_dir))
endif

Global Runtime Variables

g:coc_vim_commands

g:coc_vim_commands

List of Vim commands registered by extensions.

Type: List (read-only)

Example:

if exists('g:coc_vim_commands')
  echo 'Registered commands: ' . join(g:coc_vim_commands, ', ')
endif

Examples

Auto-Install Essential Extensions

" In your vimrc/init.vim
let g:coc_global_extensions = [
  \ 'coc-json',
  \ 'coc-tsserver',
  \ 'coc-eslint',
  \ 'coc-prettier',
  \ 'coc-html',
  \ 'coc-css',
  \ 'coc-python',
  \ 'coc-rust-analyzer',
  \ 'coc-yaml',
  \ 'coc-snippets',
  \ 'coc-pairs'
  \ ]

Manual Extension Management

" Install specific extensions
:CocInstall coc-snippets coc-pairs

" Update all extensions
:CocUpdate

" Check installed extensions
:CocList extensions

Extension Status Check

function! CheckExtensionStatus() abort
  let stats = CocAction('extensionStats')
  let active = 0
  let inactive = 0

  for ext in stats
    if ext.state == 'activated'
      let active += 1
    else
      let inactive += 1
    endif
  endfor

  echo 'Extensions: ' . len(stats) . ' total'
  echo 'Active: ' . active
  echo 'Inactive: ' . inactive
endfunction

command! CocExtensionStatus call CheckExtensionStatus()

Install Missing Extensions

function! InstallMissingExtensions() abort
  let required = g:coc_global_extensions
  let installed = CocAction('loadedExtensions')
  let missing = []

  for ext in required
    if index(installed, ext) < 0
      call add(missing, ext)
    endif
  endfor

  if len(missing) > 0
    echo 'Installing missing extensions: ' . join(missing, ', ')
    call coc#util#install_extension(missing)
  else
    echo 'All required extensions are installed'
  endif
endfunction

command! CocInstallMissing call InstallMissingExtensions()

Toggle Extension On/Off

" Quick toggle for common extensions
nnoremap <silent> <leader>te :call ToggleExtension('coc-eslint')<CR>
nnoremap <silent> <leader>tp :call ToggleExtension('coc-prettier')<CR>

function! ToggleExtension(name) abort
  call CocAction('toggleExtension', a:name)
  echo 'Toggled ' . a:name
endfunction

Development Workflow

" Watch extension during development
function! DevExtension(name) abort
  execute 'CocWatch ' . a:name
  echo 'Watching ' . a:name . ' for changes'
endfunction

" Reload extension after changes
function! ReloadDevExtension(name) abort
  call CocAction('reloadExtension', a:name)
  echo 'Reloaded ' . a:name
endfunction

" Development commands
command! -nargs=1 CocDev call DevExtension(<q-args>)
command! -nargs=1 CocReload call ReloadDevExtension(<q-args>)

Update Check

function! CheckExtensionUpdates() abort
  echo 'Checking for extension updates...'
  CocUpdateSync
  echo 'Extension update complete'
endfunction

" Auto-update weekly
autocmd VimEnter * call timer_start(60000 * 60 * 24 * 7, {-> CheckExtensionUpdates()})

Extension Information Display

function! ShowExtensionInfo() abort
  let stats = CocAction('extensionStats')

  echo "Installed Extensions:\n"
  for ext in stats
    let status = ext.state == 'activated' ? '✓' : '✗'
    echo status . ' ' . ext.id . ' (v' . ext.version . ')'
  endfor

  echo "\nExtensions directory: " . coc#util#extension_root()
endfunction

command! CocExtensionInfo call ShowExtensionInfo()

Conditional Extension Loading

" Load extensions based on filetype
function! LoadExtensionForFiletype() abort
  let ft = &filetype
  let ft_extensions = {
    \ 'javascript': 'coc-tsserver',
    \ 'typescript': 'coc-tsserver',
    \ 'python': 'coc-python',
    \ 'rust': 'coc-rust-analyzer',
    \ 'go': 'coc-go',
    \ 'java': 'coc-java'
    \ }

  if has_key(ft_extensions, ft)
    let ext = ft_extensions[ft]
    call CocAction('activeExtension', ext)
  endif
endfunction

autocmd FileType * call LoadExtensionForFiletype()

Cleanup Unused Extensions

function! CleanupExtensions() abort
  let installed = CocAction('loadedExtensions')
  let required = g:coc_global_extensions
  let unused = []

  for ext in installed
    if index(required, ext) < 0
      call add(unused, ext)
    endif
  endfor

  if len(unused) > 0
    echo 'Unused extensions found:'
    for ext in unused
      echo '  - ' . ext
    endfor

    if confirm('Uninstall unused extensions?', "&Yes\n&No") == 1
      for ext in unused
        call CocAction('uninstallExtension', ext)
      endfor
    endif
  else
    echo 'No unused extensions'
  endif
endfunction

command! CocCleanup call CleanupExtensions()

Language-Specific Extension Sets

" Define extension sets per language
let g:coc_extension_sets = {
  \ 'web': ['coc-tsserver', 'coc-eslint', 'coc-prettier', 'coc-html', 'coc-css'],
  \ 'python': ['coc-python', 'coc-pylint'],
  \ 'rust': ['coc-rust-analyzer'],
  \ 'go': ['coc-go']
  \ }

function! InstallExtensionSet(name) abort
  if has_key(g:coc_extension_sets, a:name)
    call coc#util#install_extension(g:coc_extension_sets[a:name])
    echo 'Installing ' . a:name . ' extension set'
  else
    echo 'Unknown extension set: ' . a:name
  endif
endfunction

command! -nargs=1 CocInstallSet call InstallExtensionSet(<q-args>)

Error Handling

Installation Failures

If extension installation fails:

" Check network connectivity
:!curl -I https://registry.npmjs.org

" Try with terminal to see errors
:CocInstall -terminal coc-extension-name

" Check logs
:CocOpenLog

" Try sync installation
:CocInstall -sync coc-extension-name

Extension Won't Load

If an extension fails to load:

" Check extension status
let stats = CocAction('extensionStats')
let ext = filter(copy(stats), 'v:val.id == "coc-extension-name"')[0]
echo ext.state

" Try activating manually
call CocAction('activeExtension', 'coc-extension-name')

" Rebuild native modules
:CocRebuild

" Reinstall extension
:CocUninstall coc-extension-name
:CocInstall coc-extension-name

Native Module Errors

If you see native module errors:

" Rebuild all native modules
:CocRebuild

" Or programmatically
call coc#util#rebuild()

" Restart service
:CocRestart

Troubleshooting

Extension Not Installing

Problem: Extension installation fails or hangs.

Solutions:

  1. Check network: :!curl -I https://registry.npmjs.org
  2. Use terminal mode: :CocInstall -terminal extension-name
  3. Check logs: :CocOpenLog
  4. Verify extension name is correct
  5. Try installing manually with npm in extensions directory

Extension Not Loading

Problem: Extension installed but not appearing in :CocList extensions.

Solutions:

  1. Restart service: :CocRestart
  2. Check extension state: CocAction('extensionStats')
  3. Activate manually: call CocAction('activeExtension', 'name')
  4. Rebuild: :CocRebuild
  5. Check for conflicts in logs

Extension Commands Missing

Problem: Extension is loaded but commands don't work.

Solutions:

  1. Verify extension is activated: CocAction('loadedExtensions')
  2. Check registered commands: echo g:coc_vim_commands
  3. Reload extension: call CocAction('reloadExtension', 'name')
  4. Check extension documentation for command names
  5. Restart service: :CocRestart

Auto-Install Not Working

Problem: Extensions in g:coc_global_extensions don't install.

Solutions:

  1. Verify variable is set before coc loads
  2. Check syntax: echo g:coc_global_extensions
  3. Install manually: :CocInstall extension-name
  4. Check logs for installation errors: :CocOpenLog
  5. Verify extension names are correct (npm package names)

Update Failures

Problem: :CocUpdate fails or extensions won't update.

Solutions:

  1. Try sync update: :CocUpdateSync
  2. Update individually: :CocInstall extension-name (reinstalls latest)
  3. Check network connectivity
  4. Clear npm cache in extensions directory
  5. Check logs: :CocOpenLog

Extension Conflicts

Problem: Multiple extensions interfere with each other.

Solutions:

  1. Deactivate one: call CocAction('deactivateExtension', 'name')
  2. Check extension documentation for known conflicts
  3. Configure priority in coc-settings.json
  4. Disable specific features per extension
  5. Use :CocList extensions to toggle extensions

See Also

  • Configuration - Configure extensions via coc-settings.json
  • Service Management - Restart service when extensions misbehave
  • Variables - Extension-related variables
  • List Interface - Using CocList for extension management