Spacevim: How to use coc.nvim in SpaceVim

Created on 9 Feb 2019  路  7Comments  路  Source: SpaceVim/SpaceVim

How can i add coc.nvim support for autocompletion/lsp to SpaceVim. Tried many times but failed each time. I use it mostluy React/ReactNative/Nodejs. Thanks for great project :)

usage

Most helpful comment

In init.toml put

[options]
  autocomplete_method = "coc"

# The lsp layer has to be enabled too. SpaceVim converts the configuration in the lsp layer and then passes it to coc.
# You can put your language servers here.
[[layers]] 
  name = 'lsp'
  filetypes = [
    'c',
    'cpp',
    'dart'
  ]
  [layers.override_cmd]
    c = ['ccls', '--log-file=/tmp/ccls.log']
    cpp = ['ccls', '--log-file=/tmp/ccls.log']

TIP: if you need to do some custom configuration with coc.nvim, instead of using coc-settings.json and putting it in $XDG_CONFIG_HOME/nvim or $HOME/.config/nvim by default锛坥r $HOME/.vim for vim), which, since you're using SpaceVim, is occupied by the SpaceVim repository, a good alternative would be that of calling coc#config inside your SpaceVim.d directory (e.g. inside SpaceVim.d/plugin/coc.vim).
This way you don't pollute SpaceVim's repository and future SpaceVim updates won't have problems
(Certainly you can do some clever git stuff to workaround the presence of coc-settings.json, but IMHO it's not worth it)

Here is my configuration in SpaceVim.d/plugin/coc.vim

inoremap <silent><expr> <c-space> coc#refresh()

call coc#config('coc.preferences', {
            \ "autoTrigger": "always",
            \ "maxCompleteItemCount": 10,
            \ "codeLens.enable": 1,
            \ "diagnostic.virtualText": 1,
            \})

let s:coc_extensions = [
            \ 'coc-dictionary',
            \ 'coc-json',
            \ 'coc-ultisnips',
            \ 'coc-tag',
            \]

for extension in s:coc_extensions
    call coc#add_extension(extension)
endfor

Note that I don't configure any language server, because the lsp layer's configuration in init.toml already passes the correct language server configuration to coc.

All 7 comments

In init.toml put

[options]
  autocomplete_method = "coc"

# The lsp layer has to be enabled too. SpaceVim converts the configuration in the lsp layer and then passes it to coc.
# You can put your language servers here.
[[layers]] 
  name = 'lsp'
  filetypes = [
    'c',
    'cpp',
    'dart'
  ]
  [layers.override_cmd]
    c = ['ccls', '--log-file=/tmp/ccls.log']
    cpp = ['ccls', '--log-file=/tmp/ccls.log']

TIP: if you need to do some custom configuration with coc.nvim, instead of using coc-settings.json and putting it in $XDG_CONFIG_HOME/nvim or $HOME/.config/nvim by default锛坥r $HOME/.vim for vim), which, since you're using SpaceVim, is occupied by the SpaceVim repository, a good alternative would be that of calling coc#config inside your SpaceVim.d directory (e.g. inside SpaceVim.d/plugin/coc.vim).
This way you don't pollute SpaceVim's repository and future SpaceVim updates won't have problems
(Certainly you can do some clever git stuff to workaround the presence of coc-settings.json, but IMHO it's not worth it)

Here is my configuration in SpaceVim.d/plugin/coc.vim

inoremap <silent><expr> <c-space> coc#refresh()

call coc#config('coc.preferences', {
            \ "autoTrigger": "always",
            \ "maxCompleteItemCount": 10,
            \ "codeLens.enable": 1,
            \ "diagnostic.virtualText": 1,
            \})

let s:coc_extensions = [
            \ 'coc-dictionary',
            \ 'coc-json',
            \ 'coc-ultisnips',
            \ 'coc-tag',
            \]

for extension in s:coc_extensions
    call coc#add_extension(extension)
endfor

Note that I don't configure any language server, because the lsp layer's configuration in init.toml already passes the correct language server configuration to coc.

@free-easy thanks

Kinda disappointing that I had to google for this; it's not listed in the documentation for available layers. Perhaps this should be placed there?

good

Here is my configuration in SpaceVim.d/plugin/coc.vim

Not using json make it impossible to have the completion, the automatic discovery and linting on the configuration file
Setting a custom gitignore is fine I think.

Still got a coc-settings.json under ~/.SpaceVim/ by default. Also, this file is not added into .gitignore.

For others who may want to know: Currently, you can change coc's config directory via let g:coc_config_home = '~/.SpaceVim.d/'.

In this way, coc-settings.json will not pollute SpaceVim.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jetm picture jetm  路  5Comments

wsdjeg picture wsdjeg  路  3Comments

zeroasterisk picture zeroasterisk  路  5Comments

wsdjeg picture wsdjeg  路  3Comments

s97712 picture s97712  路  4Comments