From e8d534843decdaebdd7f65a164e09978532751a1 Mon Sep 17 00:00:00 2001 From: Jali Date: Sat, 23 Oct 2021 15:22:14 +0200 Subject: [PATCH] Use vim-lsp instead of ale --- ale.vim | 17 ----------------- init.vim | 2 +- keymap.vim | 4 ++-- plug.vim | 4 +++- python.vim | 9 +++++++++ rust.vim | 9 ++++++++- vim-lsp.vim | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 59 insertions(+), 22 deletions(-) delete mode 100644 ale.vim create mode 100644 vim-lsp.vim diff --git a/ale.vim b/ale.vim deleted file mode 100644 index 0e29878..0000000 --- a/ale.vim +++ /dev/null @@ -1,17 +0,0 @@ -" Defines a specific list of linters, that you wish to use for a language -" Install the flake8, python-pylint packages -let g:ale_linters = { - \ 'python': ['flake8', 'pylint'], - \ 'rust': ['rls'], - \} - -let g:ale_fixers = { - \ 'python': ['yapf'], - \ 'rust': ['rustfmt'] - \} - -nmap :ALEFix - -let g:ale_fix_on_save = 1 -let g:airline#extensions#ale#enabled = 1 - diff --git a/init.vim b/init.vim index 482ff6a..c50f55c 100644 --- a/init.vim +++ b/init.vim @@ -70,7 +70,7 @@ source ~/.config/nvim/rainbow.vim source ~/.config/nvim/neomake.vim source ~/.config/nvim/keymap.vim source ~/.config/nvim/timestamp.vim -source ~/.config/nvim/ale.vim source ~/.config/nvim/html.vim +source ~/.config/nvim/vim-lsp.vim source ~/.config/nvim/python.vim source ~/.config/nvim/rust.vim diff --git a/keymap.vim b/keymap.vim index 847e5af..8287df9 100644 --- a/keymap.vim +++ b/keymap.vim @@ -23,8 +23,8 @@ noremap :belowright split +resize12 term://zsh noremap :bnext :bd# " Map ale wraps to control+k and control+j -nmap (ale_previous_wrap) -nmap (ale_next_wrap) +nmap (LspPreviousDiagnostic) +nmap (LspNextDiagnostic) " Map vim-grammarous to nmap :GrammarousCheck diff --git a/plug.vim b/plug.vim index d9057fc..c641014 100644 --- a/plug.vim +++ b/plug.vim @@ -15,6 +15,7 @@ Plug 'bling/vim-bufferline' Plug 'junegunn/fzf.vim' Plug 'tpope/vim-commentary' Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } +Plug 'lighttiger2505/deoplete-vim-lsp' Plug 'machakann/vim-highlightedyank' " Use rainbow parenthesis and automatic closing parens @@ -22,7 +23,8 @@ Plug 'luochen1990/rainbow' Plug 'jiangmiao/auto-pairs' " Linting plugin for multiple languages -Plug 'dense-analysis/ale' +Plug 'prabirshrestha/vim-lsp' +Plug 'mattn/vim-lsp-settings' " Language support for LaTeX Plug 'vim-latex/vim-latex' diff --git a/python.vim b/python.vim index 731d03d..2d5ec5d 100644 --- a/python.vim +++ b/python.vim @@ -3,3 +3,12 @@ au BufNewFile,BufRead *.py \ setlocal foldmethod=indent \ nospell +" register pyls as a language server. +if executable('pyls') + " pip install python-language-server + au User lsp_setup call lsp#register_server({ + \ 'name': 'pyls', + \ 'cmd': {server_info->['pyls']}, + \ 'allowlist': ['python'], + \ }) +endif diff --git a/rust.vim b/rust.vim index cce76ef..9b3ec71 100644 --- a/rust.vim +++ b/rust.vim @@ -1,4 +1,11 @@ " No spell checking in code file autocmd BufNewFile,BufRead *.rs setlocal nospell - +if executable('rls') + " pip install rust-language-server + au User lsp_setup call lsp#register_server({ + \ 'name': 'rls', + \ 'cmd': {server_info->['rls']}, + \ 'allowlist': ['rust'], + \ }) +endif diff --git a/vim-lsp.vim b/vim-lsp.vim new file mode 100644 index 0000000..a22f9ba --- /dev/null +++ b/vim-lsp.vim @@ -0,0 +1,36 @@ +" Configure the vim-lsp plugin in order to register any language server. +" + +function! s:on_lsp_buffer_enabled() abort + setlocal omnifunc=lsp#complete + setlocal signcolumn=yes + if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif + nmap gd (lsp-definition) + nmap gs (lsp-document-symbol-search) + nmap gS (lsp-workspace-symbol-search) + nmap gr (lsp-references) + nmap gi (lsp-implementation) + nmap gt (lsp-type-definition) + nmap rn (lsp-rename) + nmap [g (lsp-previous-diagnostic) + nmap ]g (lsp-next-diagnostic) + nmap K (lsp-hover) + inoremap lsp#scroll(+4) + inoremap lsp#scroll(-4) + + let g:lsp_format_sync_timeout = 1000 + autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync') + + " refer to doc to add more commands +endfunction + +augroup lsp_install + au! + " call s:on_lsp_buffer_enabled only for languages that has the server registered. + autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled() +augroup END + +" Set folding +set foldmethod=expr + \ foldexpr=lsp#ui#vim#folding#foldexpr() + \ foldtext=lsp#ui#vim#folding#foldtext()