]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/python/pylsp.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / ale / ale_linters / python / pylsp.vim
1 " Author: aurieh <me@aurieh.me>
2 " Description: A language server for Python
3
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', {})
11
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)
15         return 'pipenv'
16     endif
17
18     if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pylsp_auto_poetry'))
19     \ && ale#python#PoetryPresent(a:buffer)
20         return 'poetry'
21     endif
22
23     if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pylsp_auto_uv'))
24     \ && ale#python#UvPresent(a:buffer)
25         return 'uv'
26     endif
27
28     return ale#python#FindExecutable(a:buffer, 'python_pylsp', ['pylsp'])
29 endfunction
30
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
35     let l:fake_linter = {
36     \   'name': 'pylsp',
37     \   'project_root': function('ale#python#FindProjectRoot'),
38     \}
39     let l:root = ale#lsp_linter#FindProjectRoot(a:buffer, l:fake_linter)
40
41     return !empty(l:root) ? l:root : v:null
42 endfunction
43
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\)$'
47     \   ? ' run pylsp'
48     \   : ''
49     let l:env_string = ''
50
51     if ale#Var(a:buffer, 'python_auto_virtualenv')
52         let l:env_string = ale#python#AutoVirtualenvEnvString(a:buffer)
53     endif
54
55     return l:env_string . ale#Escape(l:executable) . l:exec_args . ale#Pad(ale#Var(a:buffer, 'python_pylsp_options'))
56 endfunction
57
58 call ale#linter#Define('python', {
59 \   'name': 'pylsp',
60 \   'lsp': 'stdio',
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')},
67 \})