All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: aurieh <me@aurieh.me>
2 " Description: A language server for Python
4 call ale#Set('python_pylsp_executable', 'pylsp')
5 call ale#Set('python_pylsp_options', '')
6 call ale#Set('python_pylsp_use_global', get(g:, 'ale_use_global_executables', 0))
7 call ale#Set('python_pylsp_auto_pipenv', 0)
8 call ale#Set('python_pylsp_auto_poetry', 0)
9 call ale#Set('python_pylsp_auto_uv', 0)
10 call ale#Set('python_pylsp_config', {})
12 function! ale_linters#python#pylsp#GetExecutable(buffer) abort
13 if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pylsp_auto_pipenv'))
14 \ && ale#python#PipenvPresent(a:buffer)
18 if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pylsp_auto_poetry'))
19 \ && ale#python#PoetryPresent(a:buffer)
23 if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pylsp_auto_uv'))
24 \ && ale#python#UvPresent(a:buffer)
28 return ale#python#FindExecutable(a:buffer, 'python_pylsp', ['pylsp'])
31 " Force the cwd of the server to be the same as the project root to
32 " fix issues with treating local files matching first or third party library
33 " names being imported incorrectly.
34 function! ale_linters#python#pylsp#GetCwd(buffer) abort
37 \ 'project_root': function('ale#python#FindProjectRoot'),
39 let l:root = ale#lsp_linter#FindProjectRoot(a:buffer, l:fake_linter)
41 return !empty(l:root) ? l:root : v:null
44 function! ale_linters#python#pylsp#GetCommand(buffer) abort
45 let l:executable = ale_linters#python#pylsp#GetExecutable(a:buffer)
46 let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
51 if ale#Var(a:buffer, 'python_auto_virtualenv')
52 let l:env_string = ale#python#AutoVirtualenvEnvString(a:buffer)
55 return l:env_string . ale#Escape(l:executable) . l:exec_args . ale#Pad(ale#Var(a:buffer, 'python_pylsp_options'))
58 call ale#linter#Define('python', {
61 \ 'executable': function('ale_linters#python#pylsp#GetExecutable'),
62 \ 'cwd': function('ale_linters#python#pylsp#GetCwd'),
63 \ 'command': function('ale_linters#python#pylsp#GetCommand'),
64 \ 'project_root': function('ale#python#FindProjectRoot'),
65 \ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
66 \ 'lsp_config': {b -> ale#Var(b, 'python_pylsp_config')},