mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 17:30:04 +08:00
Add: coc.nvim integration enhacements (#2415)
* Enhance coc.nvim integration * Update documentation
This commit is contained in:
parent
599cb08fa4
commit
edaecec3cf
@ -9,7 +9,9 @@
|
||||
function! SpaceVim#layers#lsp#plugins() abort
|
||||
let plugins = []
|
||||
|
||||
if has('nvim')
|
||||
if SpaceVim#layers#isLoaded("autocomplete") && get(g:, "spacevim_autocomplete_method") ==# 'coc'
|
||||
" nop
|
||||
elseif has('nvim')
|
||||
call add(plugins, ['autozimu/LanguageClient-neovim',
|
||||
\ { 'merged': 0, 'if': has('python3'), 'build' : 'bash install.sh' }])
|
||||
else
|
||||
|
@ -8,7 +8,69 @@
|
||||
|
||||
scriptencoding utf-8
|
||||
|
||||
if has('nvim')
|
||||
|
||||
if SpaceVim#layers#isLoaded("autocomplete") && get(g:, "spacevim_autocomplete_method") ==# 'coc'
|
||||
" use coc.nvim
|
||||
let s:coc_language_servers = {}
|
||||
let s:coc_language_servers_key_id_map = {}
|
||||
function! SpaceVim#lsp#reg_server(ft, cmds) abort
|
||||
" coc.nvim doesn't support key values containing dots
|
||||
" See https://github.com/neoclide/coc.nvim/issues/323
|
||||
" Since a:cmds[0], i.e. the language server command can be a full path,
|
||||
" which can potentially contain dots, we just take it's last part, if any
|
||||
" dots are present.
|
||||
"
|
||||
" Clearly, with this implementation, an edge case could be the following
|
||||
"
|
||||
" [layers.override_cmd]
|
||||
" c = ['/home/user/.local/.bin/ccls', '--log-file=/tmp/ccls.log']
|
||||
" cpp = ['/home/user/local/.bin/ccls', '--log-file=/tmp/ccls.log']
|
||||
"
|
||||
" the last part `bin/ccls` is the same, whereas the commands are not
|
||||
" actually the same.
|
||||
" We need to keep an id to distinguish among conflicting keys.
|
||||
|
||||
if stridx(a:cmds[0], ".") >= 0
|
||||
let l:key = split(a:cmds[0], "\\.")[-1]
|
||||
else
|
||||
let l:key = a:cmds[0]
|
||||
endif
|
||||
|
||||
for id in range(get(s:coc_language_servers_key_id_map, l:key, 0))
|
||||
if has_key(s:coc_language_servers, l:key . id) && s:coc_language_servers[l:key . id].command ==# a:cmds[0]
|
||||
call add(s:coc_language_servers[l:key . id].filetypes, a:ft)
|
||||
return
|
||||
endif
|
||||
endfor
|
||||
|
||||
let s:coc_language_servers_key_id_map[l:key] = get(s:coc_language_servers_key_id_map, l:key, 0)
|
||||
let s:coc_language_servers[l:key . s:coc_language_servers_key_id_map[l:key]] = {
|
||||
\'command': a:cmds[0],
|
||||
\'args': a:cmds[1:],
|
||||
\'filetypes': [a:ft]
|
||||
\}
|
||||
|
||||
let s:coc_language_servers_key_id_map[l:key] = s:coc_language_servers_key_id_map[l:key] + 1
|
||||
|
||||
autocmd! User CocNvimInit :call coc#config("languageserver", s:coc_language_servers)
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#lsp#show_doc() abort
|
||||
call CocActionAsync("doHover")
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#lsp#go_to_def() abort
|
||||
call CocActionAsync("jumpDefinition")
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#lsp#rename() abort
|
||||
call CocActionAsync("rename")
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#lsp#references() abort
|
||||
call CocActionAsync("jumpReferences")
|
||||
endfunction
|
||||
elseif has('nvim')
|
||||
" use LanguageClient-neovim
|
||||
function! SpaceVim#lsp#reg_server(ft, cmds) abort
|
||||
let g:LanguageClient_serverCommands[a:ft] = copy(a:cmds)
|
||||
|
@ -10,6 +10,7 @@ description: "Autocomplete code within SpaceVim, fuzzy find the candidates from
|
||||
- [Description](#description)
|
||||
- [Install](#install)
|
||||
- [Configuration](#configuration)
|
||||
- [Choose which completion engine to be used](#choose-which-completion-engine-to-be-used)
|
||||
- [Key bindings](#key-bindings)
|
||||
- [Snippets directories](#snippets-directories)
|
||||
- [Show snippets in auto-completion popup](#show-snippets-in-auto-completion-popup)
|
||||
@ -29,7 +30,10 @@ The following completion engines are supported:
|
||||
- [neocomplete](https://github.com/Shougo/neocomplete.vim) - vim with `+lua`
|
||||
- [neocomplcache](https://github.com/Shougo/neocomplcache.vim) - vim without `+lua`
|
||||
- [deoplete](https://github.com/Shougo/deoplete.nvim) - neovim with `+python3`
|
||||
- [coc](https://github.com/neoclide/coc.nvim) - vim >= 8.1 or neovim >= 0.3.1
|
||||
- [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) - disabled by default, to enable ycm, see `:h g:spacevim_enable_ycm`
|
||||
- [Completor](https://github.com/maralla/completor.vim) - vim8 with `+python` or `+python3`
|
||||
- [asyncomplete](https://github.com/prabirshrestha/asyncomplete.vim) - vim8 or neovim with `timers`
|
||||
|
||||
Snippets are supported via [neosnippet](https://github.com/Shougo/neosnippet.vim).
|
||||
|
||||
@ -44,6 +48,20 @@ To use this configuration layer, add following snippet to your custom configurat
|
||||
|
||||
## Configuration
|
||||
|
||||
### Choose which completion engine to be used
|
||||
|
||||
You can choose the completion engine (among the supported ones) to be used
|
||||
with the following variable:
|
||||
|
||||
- `g:spacevim_autocomplete_method`: the possible values are:
|
||||
- `ycm`: for YouCompleteMe
|
||||
- `neocomplcache`
|
||||
- `coc`: **Note** that coc.nvim is also a language server protocol client.
|
||||
See [lsp layer](language-server-protocol.md) for more information.
|
||||
- `deoplete`
|
||||
- `asyncomplete`
|
||||
- `completor`
|
||||
|
||||
### Key bindings
|
||||
|
||||
You can customize the user experience of auto-completion with the following layer variables:
|
||||
|
@ -22,9 +22,12 @@ This layers adds extensive support for [language-server-protocol](https://micros
|
||||
This layer is a heavy wallpaper of [LanguageClient-neovim](https://github.com/SpaceVim/LanguageClient-neovim) (an old fork),
|
||||
The upstream is rewritten by rust.
|
||||
|
||||
we also include [vim-lsp](https://github.com/prabirshrestha/vim-lsp), which is wrote in pure vim script.
|
||||
We also include [vim-lsp](https://github.com/prabirshrestha/vim-lsp), which is wrote in pure vim script.
|
||||
|
||||
the neovim team is going to implement the build-in LSP support, the
|
||||
Note that if `coc` is used as autocomplete method in the `autocomplete` layer,
|
||||
it will be used as lsp client.
|
||||
|
||||
The neovim team is going to implement the build-in LSP support, the
|
||||
PR is [neovim#6856](https://github.com/neovim/neovim/pull/6856). and the author of this PR
|
||||
create another plugin [tjdevries/nvim-langserver-shim](https://github.com/tjdevries/nvim-langserver-shim)
|
||||
|
||||
@ -33,6 +36,8 @@ SpaceVim should works well in different version of vim/neovim, so in the feature
|
||||
```vim
|
||||
if has('nvim')
|
||||
" use neovim build-in lsp
|
||||
if SpaceVim#layers#isLoaded("autocomplete") && get(g:, "spacevim_autocomplete_method") ==# 'coc'
|
||||
" use coc.nvim
|
||||
elseif has('python3')
|
||||
" use LanguageClient-neovim
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user