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 call ale#Set('python_pyright_use_global', get(g:, 'ale_use_global_executables', 0))
2 call ale#Set('python_pyright_executable', 'pyright-langserver')
3 call ale#Set('python_pyright_config', {})
4 call ale#Set('python_pyright_auto_pipenv', 0)
5 call ale#Set('python_pyright_auto_poetry', 0)
6 call ale#Set('python_pyright_auto_uv', 0)
8 " Force the cwd of the server to be the same as the project root to
9 " fix issues with treating local files matching first or third party library
10 " names being imported incorrectly.
11 function! ale_linters#python#pyright#GetCwd(buffer) abort
14 \ 'project_root': function('ale#python#FindProjectRoot'),
16 let l:root = ale#lsp_linter#FindProjectRoot(a:buffer, l:fake_linter)
18 return !empty(l:root) ? l:root : v:null
21 function! ale_linters#python#pyright#GetConfig(buffer) abort
22 let l:config = deepcopy(ale#Var(a:buffer, 'python_pyright_config'))
24 if !has_key(l:config, 'python')
25 let l:config.python = {}
28 if type(l:config.python) is v:t_dict
29 " Automatically detect the virtualenv path and use it.
30 if !has_key(l:config.python, 'venvPath')
31 let l:venv = ale#python#FindVirtualenv(a:buffer)
34 let l:config.python.venvPath = l:venv
38 " Automatically use the version of Python in virtualenv.
39 if type(get(l:config.python, 'venvPath')) is v:t_string
40 \&& !empty(l:config.python.venvPath)
41 \&& !has_key(l:config.python, 'pythonPath')
42 let l:config.python.pythonPath = ale#path#Simplify(
43 \ l:config.python.venvPath
44 \ . (has('win32') ? '/Scripts/python' : '/bin/python')
52 function! ale_linters#python#pyright#GetExecutable(buffer) abort
53 if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pyright_auto_pipenv'))
54 \ && ale#python#PipenvPresent(a:buffer)
58 if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pyright_auto_poetry'))
59 \ && ale#python#PoetryPresent(a:buffer)
63 if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pyright_auto_uv'))
64 \ && ale#python#UvPresent(a:buffer)
68 return ale#python#FindExecutable(a:buffer, 'python_pyright', ['pyright-langserver'])
71 function! ale_linters#python#pyright#GetCommand(buffer) abort
72 let l:executable = ale_linters#python#pyright#GetExecutable(a:buffer)
73 let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
74 \ ? ' run pyright-langserver'
78 if ale#Var(a:buffer, 'python_auto_virtualenv')
79 let l:env_string = ale#python#AutoVirtualenvEnvString(a:buffer)
82 return l:env_string . ale#Escape(l:executable) . l:exec_args . ' --stdio'
85 call ale#linter#Define('python', {
88 \ 'cwd': function('ale_linters#python#pyright#GetCwd'),
89 \ 'executable': function('ale_linters#python#pyright#GetExecutable'),
90 \ 'command': function('ale_linters#python#pyright#GetCommand'),
91 \ 'project_root': function('ale#python#FindProjectRoot'),
92 \ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
93 \ 'lsp_config': function('ale_linters#python#pyright#GetConfig'),