From 14779f654194f86b3cec6d89e3fef9e792d29026 Mon Sep 17 00:00:00 2001 From: Oxbian Date: Tue, 4 Feb 2025 19:34:35 -0500 Subject: feat: working + clean linter/fixer/completion/LSP --- conf/keymaps.vim | 43 ------------------------------------------ conf/plugins.vim | 57 +++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 54 deletions(-) (limited to 'conf') diff --git a/conf/keymaps.vim b/conf/keymaps.vim index 066dd21..351520d 100644 --- a/conf/keymaps.vim +++ b/conf/keymaps.vim @@ -145,46 +145,3 @@ noremap sa zg " show the list of alternatives for the word noremap s? z= - -""""""""""""""""""" -" LSP -""""""""""""""""""" -inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" - -" Make to accept selected completion item or notify coc.nvim to format -" u breaks current undo, please make your own choice -inoremap pumvisible() ? coc#_select_confirm() : - \"\u\\=coc#on_enter()\" -let g:coc_snippet_next = '' - -nmap gp (coc-diagnostic-prev) -nmap gn (coc-diagnostic-next) - -" GoTo code navigation -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gi (coc-implementation) -nmap gr (coc-references) - -" Use K to show documentation in preview window -nnoremap gh :call ShowDocumentation() - -function! ShowDocumentation() - if CocAction('hasProvider', 'hover') - call CocActionAsync('doHover') - else - call feedkeys('K', 'in') - endif -endfunction - -" Highlight the symbol and its references when holding the cursor -autocmd CursorHold * silent call CocActionAsync('highlight') - -" Symbol renaming -nmap gR (coc-rename) - -" Formatting selected code -xmap gf (coc-format-selected) -nmap gf (coc-format-selected) - -nmap qf (coc-fix-current) diff --git a/conf/plugins.vim b/conf/plugins.vim index 89ca4c3..bdfa5ea 100644 --- a/conf/plugins.vim +++ b/conf/plugins.vim @@ -22,7 +22,7 @@ Plug 'liuchengxu/vim-which-key' " Show leader mapping cheatsheet Plug 'airblade/vim-gitgutter' " Git diff " Autocompletion, linter, syntax -Plug 'neoclide/coc.nvim', {'branch': 'release'} +Plug 'dense-analysis/ale' " Tools Plug 'ap/vim-css-color' " rgb, hex color preview @@ -35,7 +35,25 @@ filetype plugin indent on " Allow filetype detection, plugins, indentation " Configuration """"""""""""""""""""""""" " LSP -let g:coc_global_extensions = ['coc-json', 'coc-markdownlint'] " You can add other coc extensions here +let g:ale_python_auto_virtualenv = 1 +let g:ale_completion_enabled = 1 +let g:ale_floating_preview = 1 " Show hover doc & detail in a popup +let g:ale_fix_on_save = 1 + +" Stop linting when writing +let g:ale_lint_on_text_changed = 'never' +let g:ale_lint_on_insert_leave = 0 +let g:ale_hover_cursor = 1 +let g:ale_set_balloons = 1 " Show error when mouse over it + +" Linters and fixers (don't forget to setup LSP as linters) +let g:ale_linters = { +\ 'python': ['pylsp', 'flake8', 'pylint', 'mypy'] +\} + +let g:ale_fixers = { +\ 'python': ['black', 'isort', 'autopep8'] +\} " Netrw (filetree built-in vim) let g:netrw_keepdir = 0 " Reload buffer usefull when moving or removing file @@ -54,6 +72,21 @@ let g:currentmode={ \ 'Rv' : 'V·Replace ', \ 'c' : 'Command ', \} + +" Getting numbers of errors in ALE +function! LinterStatus() abort + let l:counts = ale#statusline#Count(bufnr('')) + + let l:all_errors = l:counts.error + l:counts.style_error + let l:all_non_errors = l:counts.total - l:all_errors + + return l:counts.total == 0 ? 'OK' : printf( + \ '%dW %dE', + \ all_non_errors, + \ all_errors + \) + +endfunction set laststatus=2 set statusline= " VIM Mode @@ -66,6 +99,7 @@ set statusline+=%{&readonly?'\ ':''} set statusline+=%=%y set statusline+=\ \|\ %{&fileencoding?&fileencoding:&encoding} set statusline+=\ \|\ [%{&fileformat}\] +set statusline+=\ \|\ %{LinterStatus()} " Line count and percentage set statusline+=\ \|\ %l:%c set statusline+=\ [%p%%]\ @@ -119,15 +153,16 @@ let g:which_key_map.h = { \ } " LSP key help +" Activer WhichKey pour ALE let g:which_key_map.g = { \ 'name' : '+LSP', - \ 'd' : 'go to definition', - \ 'n' : 'next diagnostic', - \ 'p' : 'previous diagnostic', - \ 'r' : 'go to reference', - \ 'R' : 'rename object', - \ 'y' : 'type definition', - \ 'i' : 'go to implementation', - \ 'h' : 'documentation', - \ 'f' : 'format document', + \ 'd' : [':ALEGoToDefinition', 'go to definition'], + \ 'n' : [':ALENext', 'next diagnostic'], + \ 'p' : [':ALEPrevious', 'previous diagnostic'], + \ 'r' : [':ALEFindReferences', 'go to reference'], + \ 'R' : [':ALERename', 'rename object'], + \ 'y' : [':ALEType', 'type definition'], + \ 'i' : [':ALEGoToImplementation', 'go to implementation'], + \ 'h' : [':ALEHover', 'documentation'], + \ 'f' : [':ALEFix', 'format document'], \ } -- cgit v1.2.3