vimrc(lsp,ale): lint with pylsp+autoformat python

...if relevant formatters are available. also, default to hard tabs.
This commit is contained in:
t14 2024-07-06 11:55:02 +02:00
parent e2c012ed96
commit 6a396b996f
Signed by: wanderer
SSH Key Fingerprint: SHA256:szgNfbjbimyesAS1xfRZ0DY3hcNv9xC9ocRCJjD4Wgg
2 changed files with 6 additions and 6 deletions

@ -1,7 +1,7 @@
" vim-python " vim-python
augroup vimrc-python augroup vimrc-python
autocmd! autocmd!
autocmd FileType python setlocal expandtab shiftwidth=4 tabstop=8 colorcolumn=79 autocmd FileType python setlocal noexpandtab shiftwidth=4 tabstop=4 colorcolumn=79
\ formatoptions+=croq softtabstop=4 \ formatoptions+=croq softtabstop=4
\ cinwords=if,elif,else,for,while,try,except,finally,def,class,with \ cinwords=if,elif,else,for,while,try,except,finally,def,class,with
augroup END augroup END
@ -19,7 +19,7 @@ let g:jedi#smart_auto_mappings = 0
" ale " ale
:call extend(g:ale_linters, { :call extend(g:ale_linters, {
\'python': ['ruff', 'flake8'], }) \'python': ['ruff', 'flake8', 'pylsp'], })
":call extend(g:ale_fixers, { ":call extend(g:ale_fixers, {
" \'python': ['ruff_format'], }) " \'python': ['ruff_format'], })

@ -343,7 +343,7 @@ let g:ale_linters = {
\ 'hare': ['hare', 'vim-lsp'], \ 'hare': ['hare', 'vim-lsp'],
\ 'lua': ['vim-lsp'], \ 'lua': ['vim-lsp'],
\ 'nix': ['nil', 'rnix_lsp', 'alejandra', 'deadnix', 'statix', 'nixpkgs-fmt', 'vim-lsp'], \ 'nix': ['nil', 'rnix_lsp', 'alejandra', 'deadnix', 'statix', 'nixpkgs-fmt', 'vim-lsp'],
\ 'python': ['ruff', 'vim-lsp', 'pylint', 'yapf', 'isort'], \ 'python': ['ruff', 'vim-lsp', 'pylint', 'pylsp', 'yapf', 'isort'],
\ 'rust': ['analyzer', 'cargo', 'rls', 'vim-lsp'], \ 'rust': ['analyzer', 'cargo', 'rls', 'vim-lsp'],
\ 'sh': ['shellcheck', 'shfmt', 'shell', 'vim-lsp'], \ 'sh': ['shellcheck', 'shfmt', 'shell', 'vim-lsp'],
\ 'bash': ['shellcheck', 'shfmt', 'shell', 'vim-lsp'], \ 'bash': ['shellcheck', 'shfmt', 'shell', 'vim-lsp'],
@ -1180,14 +1180,14 @@ if executable('dhall-lsp-server')
\ }) \ })
augroup END augroup END
endif endif
if executable('pyls') if executable('pylsp')
" pip install python-language-server " pip install python-language-server
" or python-lsp-black from the AUR " or python-lsp-black from the AUR
augroup lsp_py augroup lsp_py
autocmd! autocmd!
autocmd User lsp_setup call lsp#register_server({ autocmd User lsp_setup call lsp#register_server({
\ 'name': 'pyls', \ 'name': 'pyls',
\ 'cmd': {server_info->[&shell, &shellcmdflag, 'pyls']}, \ 'cmd': {server_info->[&shell, &shellcmdflag, 'pylsp']},
\ 'allowlist': ['python'], \ 'allowlist': ['python'],
\ }) \ })
" \ 'cmd': {server_info->['pyls']}, " \ 'cmd': {server_info->['pyls']},
@ -1229,7 +1229,7 @@ function! s:on_lsp_buffer_enabled() abort
let g:lsp_format_sync_timeout = 700 let g:lsp_format_sync_timeout = 700
augroup lsp_format_sync augroup lsp_format_sync
autocmd! autocmd!
autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync') autocmd! BufWritePre *.rs,*.go,*.python call execute('LspDocumentFormatSync')
augroup END augroup END
" refer to doc to add more commands " refer to doc to add more commands