nvim: Switch to vim-lsp and asyncomplete

vim-lsp seems to provide more options, seems to work better and faster
even perhaps. With the switch to vim-lsp and asyncomplete we should be
able to remove dependency on external python provider.

Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
This commit is contained in:
Sanchayan Maity 2020-02-14 12:27:26 +05:30
parent 519262d41f
commit 18de6cf24d

View file

@ -60,8 +60,10 @@ Plug 'godlygeek/tabular'
" For Nix
Plug 'LnL7/vim-nix', { 'for': 'nix' }
" For autocompletion
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'deoplete-plugins/deoplete-tag'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-buffer.vim'
Plug 'prabirshrestha/asyncomplete-file.vim'
Plug 'prabirshrestha/asyncomplete-tags.vim'
" For Python
Plug 'numirias/semshi', { 'do': ':UpdateRemotePlugins' }
" Autocomplete for Rust
@ -97,7 +99,9 @@ Plug 'dag/vim-fish'
Plug 'lifepillar/pgsql.vim'
" LC related
Plug 'liuchengxu/vista.vim'
Plug 'autozimu/LanguageClient-neovim', { 'branch': 'next', 'do': 'bash install.sh' }
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
" Miscellaneous
Plug 'editorconfig/editorconfig-vim'
Plug 'igankevich/mesonic'
@ -499,12 +503,67 @@ augroup END
augroup LSP
au!
nnoremap <LocalLeader>cs :LanguageClientStart<CR>
nnoremap <LocalLeader>ch :LanguageClientStop<CR>
" Somehow the LanguageClientStarted event does not seem to fire or work
" in case of purescript so call to setup the bindings
au FileType purescript :call SetLspKeybindings()
autocmd User LanguageClientStarted :call SetLspKeybindings()
nnoremap <LocalLeader>le :call lsp#enable()<CR>
nnoremap <LocalLeader>ld :call lsp#disable()<CR>
nnoremap <LocalLeader>lh :LspStopServer()<CR>
nnoremap <LocalLeader>ls :LspStatus<CR>
au User lsp_server_init call s:on_lsp_server_init()
augroup END
augroup VimLspSettings
au!
if executable('pyls')
au User lsp_setup call lsp#register_server({
\ 'name': 'pyls',
\ 'cmd': {server_info->['pyls']},
\ 'whitelist': ['python'],
\ })
endif
if executable('ra_lsp_server')
au User lsp_setup call lsp#register_server({
\ 'name': 'ra_lsp_server',
\ 'cmd': {server_info->['ra_lsp_server']},
\ 'whitelist': ['rust'],
\ })
endif
if executable('purescript-language-server')
au User lsp_setup call lsp#register_server({
\ 'name': 'purescript-language-server',
\ 'cmd': {server_info->['purescript-language-server', '--stdio']},
\ 'whitelist': ['purescript'],
\ })
endif
if executable('ghcide')
au User lsp_setup call lsp#register_server({
\ 'name': 'ghcide',
\ 'cmd': {server_info->['ghcide', '--lsp']},
\ 'whitelist': ['haskell'],
\ })
endif
augroup END
augroup AsyncCompleteSetup
au!
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#tags#get_source_options({
\ 'name': 'tags',
\ 'whitelist': ['c', 'haskell'],
\ 'completor': function('asyncomplete#sources#tags#completor'),
\ }))
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#buffer#get_source_options({
\ 'name': 'buffer',
\ 'whitelist': ['*'],
\ 'blacklist': ['go'],
\ 'completor': function('asyncomplete#sources#buffer#completor'),
\ 'config': {
\ 'max_buffer_size': 5000000,
\ },
\ }))
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({
\ 'name': 'file',
\ 'whitelist': ['*'],
\ 'priority': 10,
\ 'completor': function('asyncomplete#sources#file#completor')
\ }))
augroup END
" --------------------------- Plugin settings --------------------------------
@ -541,25 +600,6 @@ else
endif
let g:hoogle_search_count = 30
" Use deoplete
let g:deoplete#enable_at_startup = 1
let g:deoplete#sources = {}
call deoplete#custom#source('_',
\ 'disabled_syntaxes', ['Comment', 'String'])
call deoplete#custom#option('sources', {
\ '_' : ['buffer', 'tag', 'around', 'file', 'member'],
\ 'haskell': ['LanguageClient', 'buffer', 'tag'],
\ 'rust': ['LanguageClient', 'buffer'],
\ 'python': ['LanguageClient', 'buffer'],
\ 'purescript': ['LanguageClient', 'buffer'],
\})
call deoplete#custom#option({
\ 'auto_complete_delay': 200,
\ 'auto_complete': v:true,
\ 'smart_case': v:true,
\ })
let g:deoplete#sources#rust#disable_keymap = 1
" Use airline
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#fnamemod = ':t'
@ -603,11 +643,9 @@ let g:neomake_c_gcc_maker = {
" Automatically detect style file and apply style to formatting
let g:clang_format#detect_style_file = 1
" Additional trigger not required with deoplete
let g:tmuxcomplete#trigger = ''
" Required for vimtex
let g:vimtex_compiler_progname = 'nvr'
" Fix deoplete's tab behaviour
" Fix tab behaviour while switching through completion options
let g:SuperTabDefaultCompletionType = "<c-n>"
" For workspace
let g:workspace_session_directory = $HOME . '/.vim/session/'
@ -650,25 +688,22 @@ let g:fzf_layout = { 'window': 'call CreateCentredFloatingWindow()' }
let g:quickr_cscope_keymaps = 0
" LSP
let g:LanguageClient_autoStart = 0
let g:LanguageClient_loggingFile = expand('$HOME/.cache/LC.log')
let g:LanguageClient_selectionUI = "quickfix"
let g:LanguageClient_serverCommands = {
\ 'haskell': ['ghcide', '--lsp'],
\ 'rust': ['ra_lsp_server'],
\ 'python': ['pyls'],
\ 'purescript': ['purescript-language-server', '--stdio', '--config', '{}'],
\ }
let g:lsp_diagnostics_enabled = 1
let g:lsp_signs_enabled = 1
let g:lsp_diagnostics_echo_cursor = 1
let g:lsp_highlight_references_enabled = 1
let g:lsp_auto_enable = 0
" Vista
let g:vista_executive_for = {
\ 'c': 'ctags',
\ 'haskell': 'lcn',
\ 'rust': 'lcn',
\ 'python': 'lcn',
\ 'haskell': 'vim_lsp',
\ 'rust': 'vim_lsp',
\ 'purescript': 'vim_lsp',
\ 'python': 'vim_lsp',
\ }
let g:vista_ctags_cmd = {
\ 'haskell': 'stack exec -- hasktags -x -o - -c',
\ 'haskell': 'stack exec -- hasktags -x -o - -c .',
\ }
" Allow nightfly theme to set indentline colors
@ -741,21 +776,33 @@ function! MakeArrow(type)
endif
endfunction
function! SetLspKeybindings()
nnoremap gd :call LanguageClient#textDocument_definition()<CR>
nnoremap gr :call LanguageClient#textDocument_rename()<CR>
nnoremap gx :call LanguageClient#textDocument_references()<CR>
nnoremap K :call LanguageClient#textDocument_hover()<CR>
nnoremap ge :call LanguageClient#explainErrorAtPoint()<CR>
function! s:on_lsp_server_init() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
nnoremap <LocalLeader>cm :call LanguageClient_contextMenu()<CR>
nnoremap <LocalLeader>td :call LanguageClient#textDocument_typeDefinition()<CR>
nnoremap <LocalLeader>di :call LanguageClient#textDocument_implementation()<CR>
nnoremap <LocalLeader>cl :call LanguageClient#textDocument_codeLens()<CR>
nnoremap <LocalLeader>ca :call LanguageClient#textDocument_codeAction()<CR>
nnoremap <LocalLeader>rf :call LanguageClient#textDocument_rangeFormatting()<CR>
nnoremap <LocalLeader>f :call LanguageClient#textDocument_formatting()<CR>
nnoremap <LocalLeader>a :call LanguageClient_workspace_applyEdit()<CR>
nnoremap <LocalLeader>dc :call LanguageClient#textDocument_completion()<CR>
nnoremap <LocalLeader>ds :call LanguageClient_textDocument_documentSymbol()<CR>
" Always expected to work
nmap <buffer> gd :LspDefinition<CR>
nmap <buffer> gpd :LspPeekDefinition<CR>
nmap <buffer> gk :LspHover<CR>
" May or may not be available depending on language server
nmap <buffer> gx :LspReferences<CR>
nmap <buffer> gr :LspRename<CR>
nmap <buffer> <LocalLeader>ca :LspCodeAction<CR>
nmap <buffer> <LocalLeader>dd :LspDocumentDiagnostics<CR>
nmap <buffer> <LocalLeader>df :LspDocumentFormat<CR>
nmap <buffer> <LocalLeader>rf :LspDocumentRangeFormat<CR>
nmap <buffer> <LocalLeader>ds :LspDocumentSymbol<CR>
nmap <buffer> <LocalLeader>di :LspImplementation<CR>
nmap <buffer> <LocalLeader>nd :LspNextDiagnostic<CR>
nmap <buffer> <LocalLeader>pd :LspPreviousDiagnostic<CR>
nmap <buffer> <LocalLeader>ne :LspNextError<CR>
nmap <buffer> <LocalLeader>pe :LspPreviousError<CR>
nmap <buffer> <LocalLeader>nr :LspNextReference<CR>
nmap <buffer> <LocalLeader>pr :LspPreviousReference<CR>
nmap <buffer> <LocalLeader>nw :LspNextWarning<CR>
nmap <buffer> <LocalLeader>pw :LspPreviousWarning<CR>
nmap <buffer> <LocalLeader>dt :LspTypeDefinition<CR>
nmap <buffer> <LocalLeader>td :LspPeekTypeDefinition<CR>
nmap <buffer> <LocalLeader>pi :LspPeekImplementation<CR>
endfunction