From 18de6cf24d4ae44e197274f12c28ce6a6b591e1f Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Fri, 14 Feb 2020 12:27:26 +0530 Subject: [PATCH] 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 --- nvim/.config/nvim/init.vim | 167 ++++++++++++++++++++++++------------- 1 file changed, 107 insertions(+), 60 deletions(-) diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim index 854996f..f21b641 100644 --- a/nvim/.config/nvim/init.vim +++ b/nvim/.config/nvim/init.vim @@ -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 cs :LanguageClientStart - nnoremap ch :LanguageClientStop - " 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 le :call lsp#enable() + nnoremap ld :call lsp#disable() + nnoremap lh :LspStopServer() + nnoremap ls :LspStatus + 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 = "" " 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() - nnoremap gr :call LanguageClient#textDocument_rename() - nnoremap gx :call LanguageClient#textDocument_references() - nnoremap K :call LanguageClient#textDocument_hover() - nnoremap ge :call LanguageClient#explainErrorAtPoint() +function! s:on_lsp_server_init() abort + setlocal omnifunc=lsp#complete + setlocal signcolumn=yes - nnoremap cm :call LanguageClient_contextMenu() - nnoremap td :call LanguageClient#textDocument_typeDefinition() - nnoremap di :call LanguageClient#textDocument_implementation() - nnoremap cl :call LanguageClient#textDocument_codeLens() - nnoremap ca :call LanguageClient#textDocument_codeAction() - nnoremap rf :call LanguageClient#textDocument_rangeFormatting() - nnoremap f :call LanguageClient#textDocument_formatting() - nnoremap a :call LanguageClient_workspace_applyEdit() - nnoremap dc :call LanguageClient#textDocument_completion() - nnoremap ds :call LanguageClient_textDocument_documentSymbol() + " Always expected to work + nmap gd :LspDefinition + nmap gpd :LspPeekDefinition + nmap gk :LspHover + + " May or may not be available depending on language server + nmap gx :LspReferences + nmap gr :LspRename + nmap ca :LspCodeAction + nmap dd :LspDocumentDiagnostics + nmap df :LspDocumentFormat + nmap rf :LspDocumentRangeFormat + nmap ds :LspDocumentSymbol + nmap di :LspImplementation + nmap nd :LspNextDiagnostic + nmap pd :LspPreviousDiagnostic + nmap ne :LspNextError + nmap pe :LspPreviousError + nmap nr :LspNextReference + nmap pr :LspPreviousReference + nmap nw :LspNextWarning + nmap pw :LspPreviousWarning + nmap dt :LspTypeDefinition + nmap td :LspPeekTypeDefinition + nmap pi :LspPeekImplementation endfunction