vim: Migrate from ALE and vim-go -> vim-lsp

This commit is contained in:
Rob Watson 2021-03-21 16:10:17 +01:00
parent d404ac9362
commit f192da86a7
2 changed files with 116 additions and 117 deletions

View File

@ -1,28 +1,14 @@
nmap <silent> gvd <Plug>(go-def-vertical)
nmap <silent> gsd <Plug>(go-def-split)
nmap <silent> gvD <Plug>(go-def-type-vertical)
nmap <silent> gsD <Plug>(go-def-type-split)
nmap <silent> <leader>gb :up<bar>:GoBuild<cr> nmap <silent> <leader>gb :up<bar>:GoBuild<cr>
nmap <silent> <leader>gr :up<bar>:GoRun<cr> nmap <silent> <leader>gr :up<bar>:GoRun<cr>
nmap <silent> <leader>gc :GoCallers<cr> nmap <silent> <leader>gt :up<bar>:GoTest<cr>
" TODO: if GoInfo returns nothing an [INFO] SUCCESS message is shown. nmap <silent> <leader>gf :up<bar>:GoTestFunc<cr>
" But disabling g:go_echo_command_info impacts build and test workflow.
nmap <silent> <leader>gi :GoInfo<cr>
nmap <silent> <leader>gp :GoImplements<cr>
nmap <silent> <leader>ga :GoAlternate<cr>
nmap <silent> <leader>gk :GoDocBrowser<cr> nmap <silent> <leader>gk :GoDocBrowser<cr>
nmap <silent> <leader>gd :GoDecls<cr>
nmap <silent> <leader>gD :GoDeclsDir<cr>
" mnemonic: match
nmap <silent> <leader>gm :GoSameIds<cr>
nmap <silent> <leader>gv :vsplit<bar>:GoAlternate!<cr> nmap <silent> <leader>gv :vsplit<bar>:GoAlternate!<cr>
nmap <silent> <leader>gV <c-w><c-o>:vsplit<bar>:GoAlternate!<cr> nmap <silent> <leader>gV <c-w><c-o>:vsplit<bar>:GoAlternate!<cr>
nmap <silent> <leader>gs :split<bar>:GoAlternate!<cr> nmap <silent> <leader>gs :split<bar>:GoAlternate!<cr>
nmap <silent> <leader>gS <c-w><c-o>:split<bar>:GoAlternate!<cr> nmap <silent> <leader>gS <c-w><c-o>:split<bar>:GoAlternate!<cr>
nmap <silent> <leader>gt <esc>:up<bar>:GoTest<cr>
nmap <silent> <leader>gf <esc>:up<bar>:GoTestFunc<cr>
nmap <silent> <leader>gat <esc>:GoAddTags<cr> nmap <silent> <leader>gat <esc>:GoAddTags<cr>
nmap <silent> <leader>grt <esc>:GoRemoveTags<cr> nmap <silent> <leader>grt <esc>:GoRemoveTags<cr>
nmap <silent> <leader>gec <esc>:up<bar>:GoErrCheck<cr> nmap <silent> <leader>gec <esc>:up<bar>:GoErrCheck<cr>
@ -34,41 +20,23 @@ nnoremap <silent> dq :GoDebugStop<cr>
nnoremap <silent> dn :GoDebugNext<cr> nnoremap <silent> dn :GoDebugNext<cr>
nnoremap <silent> ds :GoDebugStep<cr> nnoremap <silent> ds :GoDebugStep<cr>
" Avoid window positions jumping around when building and testing: " Vim-Go configuration
set cmdheight=2 let g:go_gopls_enabled = 0
" fzf configuration:
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit' }
" Vim-Go configuration:
let g:go_decls_mode = 'fzf'
let g:go_fmt_autosave = 0 let g:go_fmt_autosave = 0
" Vim-Go seems to handle fix-on-save better than ALE: " TODO: move to vim-lsp
let g:go_imports_autosave = 1 let g:go_imports_autosave = 1
let g:go_auto_sameids = 0 let g:go_auto_sameids = 0
let g:go_auto_type_info = 0 let g:go_auto_type_info = 0
let g:go_info_mode = 'gopls' let g:go_code_completion_enabled = 0
" ALE handles auto type info:
let g:go_auto_type_info = 0
let g:go_code_completion_enabled = 1
let g:go_echo_command_info = 0 let g:go_echo_command_info = 0
let g:go_echo_go_info = 0 let g:go_echo_go_info = 0
let g:go_highlight_diagnostic_errors = 0 let g:go_highlight_diagnostic_errors = 0
let g:go_highlight_diagnostic_warnings = 0 let g:go_highlight_diagnostic_warnings = 0
" g:go_statusline_duration doesn't seem to work accurately, but does help:
" g:go_statusline_duration doesn't seem to work accurately, but does help
" reduce the time the build/test success messages are shown in the status
" line.
let g:go_statusline_duration = 1000 let g:go_statusline_duration = 1000
let g:go_gopls_analyses = {
\ 'composites': v:false,
\ 'unusedparams': v:true,
\ 'unusedresult': v:true,
\ 'shadow': v:true,
\ }
let g:go_fmt_options = {
\ 'goimports': '-local github.com/sensiblecodeio/cantabular',
\ }
autocmd BufNewFile,BufRead *.go nmap <silent> <leader>g6 :GoAlternate!<cr> autocmd BufNewFile,BufRead *.go nmap <silent> <leader>g6 :GoAlternate!<cr>

179
vimrc
View File

@ -160,6 +160,10 @@ inoremap <expr><C-]> pumvisible() ? "\<C-]>" : "\<Enter>"
let g:vim_markdown_conceal = 1 let g:vim_markdown_conceal = 1
" fzf configuration: " fzf configuration:
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit' }
nmap <leader>t :Files<cr> nmap <leader>t :Files<cr>
nmap <leader>T :GFiles<cr> nmap <leader>T :GFiles<cr>
nmap <leader>b :Buffers<cr> nmap <leader>b :Buffers<cr>
@ -168,7 +172,29 @@ nmap <leader>gg :Rg<cr>
" Lightline configuration: " Lightline configuration:
packadd! lightline.vim packadd! lightline.vim
function! GitHead() function! GitHead()
return '[' . FugitiveHead() . ']' let l:head = FugitiveHead()
if l:head == ''
return ''
endif
return '[' . l:head . ']'
endfunction
function! LightlineLSPErrorText()
let l:info = lsp#get_buffer_diagnostics_counts()
if info.error == 0
return ''
endif
let sign = get(g:lsp_diagnostics_signs_error, 'text', 'E')
return info.error . sign
endfunction
function! LightlineLSPWarningText()
let l:info = lsp#get_buffer_diagnostics_counts()
if info.warning == 0
return ''
endif
let sign = get(g:lsp_diagnostics_signs_warning, 'text', 'W')
return info.warning . sign
endfunction endfunction
set laststatus=2 set laststatus=2
@ -177,13 +203,21 @@ let g:lightline = {
\ 'active': { \ 'active': {
\ 'left': [ [ 'mode', 'paste' ], \ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ], \ [ 'readonly', 'filename', 'modified' ],
\ [ 'gitbranch' ] ], \ [ 'gitbranch' ], ['lsperror', 'lspwarn'] ],
\ 'right': [ ['lineinfo'], ['percent'], ['filetype'], ['gobuild'] ], \ 'right': [ ['lineinfo'], ['percent'], ['filetype'], ['gobuild'] ],
\ }, \ },
\ 'component_function': { \ 'component_function': {
\ 'gobuild': 'go#statusline#Show', \ 'gobuild': 'go#statusline#Show',
\ 'gitbranch': 'GitHead', \ 'gitbranch': 'GitHead',
\ }, \ },
\ 'component_expand': {
\ 'lsperror': 'LightlineLSPErrorText',
\ 'lspwarn': 'LightlineLSPWarningText',
\ },
\ 'component_type': {
\ 'lsperror': 'error',
\ 'lspwarn': 'warning',
\ },
\ 'mode_map': { \ 'mode_map': {
\ 'n' : 'N', \ 'n' : 'N',
\ 'i' : 'I', \ 'i' : 'I',
@ -220,82 +254,81 @@ let g:echodoc#type='echo'
let g:echodoc#enable_at_startup = 1 let g:echodoc#enable_at_startup = 1
packadd! echodoc.vim packadd! echodoc.vim
" ALE configuration: " vim-fugitive
nmap [L <Plug>(ale_first) " load before LSP to ensure it doesn't clobber signcolumn
nmap ]L <Plug>(ale_last) packadd! vim-fugitive
nmap [e <Plug>(ale_previous_wrap_error)
nmap ]e <Plug>(ale_next_wrap_error)
nmap [w <Plug>(ale_previous_wrap)
nmap ]w <Plug>(ale_next_wrap)
nmap <leader>ad :ALEDetail<cr> " vim-go
map <Leader>g :ALEGoToDefinition<CR> " load before LSP to ensure it doesn't clobber mappings
map <Leader>f :ALEFindReferences<CR> packadd! vim-go
map <Leader>fv :ALEFindReferences -vsplit<CR>
map <Leader>fh :ALEFindReferences -split<CR>
map <Leader>ft :ALEFindReferences -tab<CR>
nnoremap gD :ALEGoToTypeDefinition<cr>
nnoremap gd :ALEGoToDefinition<cr>
command GoToDefinition ALEGoToDefinition
command GoToTypeDefinition ALEGoToTypeDefinition
command FindReferences ALEFindReferences
command Rename ALERename
let g:ale_sign_column_always = 1 " LSP configuration:
let g:ale_fix_on_save = 1 packadd! vim-lsp
let g:ale_lint_on_text_changed = 1 packadd! vim-lsp-settings
let g:ale_lint_on_enter = 1 packadd! deoplete-vim-lsp
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1 let g:lsp_settings = {
let g:ale_echo_cursor = 1 \ 'gopls': {
let g:ale_lint_delay = 100 \ 'initialization_options': {
let g:ale_lsp_suggestions = 1 \ 'ui.diagnostic.analyses': {
let g:ale_set_balloons = 1 \ 'composites': v:false,
" NOTE: Needs https://github.com/dense-analysis/ale/issues/3350 \ 'unusedparams': v:true,
let g:ale_rust_analyzer_config = { \ 'unusedresult': v:true,
\ 'diagnostics': { 'disabled': ['unresolved-import'] }, \ 'shadow': v:true,
\ 'cargo': { 'loadOutDirsFromCheck': v:true }, \ },
\ 'procMacro': { 'enable': v:true }, \ 'staticcheck': v:true,
\ 'checkOnSave': { 'command': 'clippy', 'enable': v:true }, \ }}}
\ } let g:lsp_diagnostics_float_cursor = 1
let g:ale_go_goimports_options = '-local github.com/sensiblecodeio/cantabular'
let g:ale_go_gopls_init_options = { function! s:on_lsp_buffer_enabled() abort
\ 'ui.diagnostic.analyses': { setlocal omnifunc=lsp#complete
\ 'composites': v:false, setlocal signcolumn=yes
\ 'unusedparams': v:true,
\ 'unusedresult': v:true, " Jump to definitions
\ 'shadow': v:true, nmap <buffer> gd <plug>(lsp-definition)
\ }, nmap <buffer> gvd :vertical :LspDefinition<cr>
\ 'staticcheck': v:true} nmap <buffer> gsd :belowright :LspDefinition<cr>
" let g:ale_command_wrapper = 'nice -n5' nmap <buffer> gD <plug>(lsp-type-definition)
let g:ale_completion_enabled = 0 nmap <buffer> gvD :vertical :LspTypeDefinition<cr>
let g:ale_close_preview_on_insert = 1 nmap <buffer> gsD :belowright :LspTypeDefinition<cr>
let g:ale_hover_to_preview = 1 " Map to leader keys too, easy typo:
let g:ale_history_log_output = 0 nmap <buffer> <leader>gd <plug>(lsp-definition)
let g:ale_linters = { nmap <buffer> <leader>gD <plug>(lsp-type-definition)
\ 'javascript': ['eslint'],
\ 'go': ['gopls'], " Peek definitions, only on leader keys
\ 'rust': ['analyzer'], nmap <buffer> <leader>pd <plug>(lsp-peek-definition)
\ 'css': ['stylelint'], nmap <buffer> <leader>pD <plug>(lsp-peek-type-definition)
\ 'python': ['pyls'],
\ 'ruby': ['rubocop'], " Navigation
\ } nmap <buffer> <silent> ]e <plug>(lsp-next-error)
let g:ale_fixers = { nmap <buffer> <silent> [e <plug>(lsp-previous-error)
\ '*': ['remove_trailing_lines', 'trim_whitespace'], nmap <buffer> <silent> ]d <plug>(lsp-next-diagnostic)
\ 'javascript': ['prettier'], nmap <buffer> <silent> [d <plug>(lsp-previous-diagnostic)
\ 'rust': [], nmap <buffer> <silent> ]r <plug>(lsp-next-reference)
\ 'go': [], nmap <buffer> <silent> [r <plug>(lsp-previous-reference)
\ 'css': ['stylelint'],
\ 'python': ['autopep8'], " Misc actions
\ 'ruby': ['rubocop'], nmap <buffer> <leader>ci <plug>(lsp-call-hierarchy-incoming)
\ } nmap <buffer> <leader>co <plug>(lsp-call-hierarchy-outgoing)
nmap <buffer> <leader>a <plug>(lsp-code-action)
nmap <buffer> <leader>i <plug>(lsp-implementation)
nmap <buffer> <leader>r <plug>(lsp-references)
nmap <buffer> <leader>d <plug>(lsp-hover)
nmap <buffer> <leader>e <plug>(lsp-rename)
endfunction
augroup lsp_install
au!
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
autocmd User lsp_diagnostics_updated call lightline#update()
" autocmd BufWritePre <buffer> silent LspDocumentFormatSync
" autocmd CursorHold <buffer> silent LspHover
augroup END
" load internal plugins: " load internal plugins:
runtime macros/matchit.vim runtime macros/matchit.vim
" load ALE only after configured:
packadd! ale
" load other plugins: " load other plugins:
packadd! tmux-complete.vim packadd! tmux-complete.vim
packadd! vim-commentary packadd! vim-commentary
@ -303,7 +336,5 @@ packadd! vim-commentary
" https://github.com/junegunn/fzf/blob/master/plugin/fzf.vim " https://github.com/junegunn/fzf/blob/master/plugin/fzf.vim
" and also this separate plugin, which is loaded here: " and also this separate plugin, which is loaded here:
packadd! fzf.vim packadd! fzf.vim
packadd! vim-go
packadd! vim-surround packadd! vim-surround
packadd! vim-yaml-folds packadd! vim-yaml-folds
packadd! vim-fugitive