]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/python/pyright.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 '56df844d3c39ec494dacc69eae34272b27db185a' as '.vim/bundle/asyncomplete'
[etc/vim.git] / .vim / bundle / ale / ale_linters / python / pyright.vim
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)
7
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
12     let l:fake_linter = {
13     \   'name': 'pyright',
14     \   'project_root': function('ale#python#FindProjectRoot'),
15     \}
16     let l:root = ale#lsp_linter#FindProjectRoot(a:buffer, l:fake_linter)
17
18     return !empty(l:root) ? l:root : v:null
19 endfunction
20
21 function! ale_linters#python#pyright#GetConfig(buffer) abort
22     let l:config = deepcopy(ale#Var(a:buffer, 'python_pyright_config'))
23
24     if !has_key(l:config, 'python')
25         let l:config.python = {}
26     endif
27
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)
32
33             if !empty(l:venv)
34                 let l:config.python.venvPath = l:venv
35             endif
36         endif
37
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')
45             \)
46         endif
47     endif
48
49     return l:config
50 endfunction
51
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)
55         return 'pipenv'
56     endif
57
58     if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pyright_auto_poetry'))
59     \ && ale#python#PoetryPresent(a:buffer)
60         return 'poetry'
61     endif
62
63     if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pyright_auto_uv'))
64     \ && ale#python#UvPresent(a:buffer)
65         return 'uv'
66     endif
67
68     return ale#python#FindExecutable(a:buffer, 'python_pyright', ['pyright-langserver'])
69 endfunction
70
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'
75     \   : ''
76     let l:env_string = ''
77
78     if ale#Var(a:buffer, 'python_auto_virtualenv')
79         let l:env_string = ale#python#AutoVirtualenvEnvString(a:buffer)
80     endif
81
82     return l:env_string . ale#Escape(l:executable) . l:exec_args . ' --stdio'
83 endfunction
84
85 call ale#linter#Define('python', {
86 \   'name': 'pyright',
87 \   'lsp': 'stdio',
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'),
94 \})