]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/fixers/autoimport.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / fixers / autoimport.vim
1 " Author: lyz-code
2 " Description: Fixing Python imports with autoimport.
3
4 call ale#Set('python_autoimport_executable', 'autoimport')
5 call ale#Set('python_autoimport_options', '')
6 call ale#Set('python_autoimport_use_global', get(g:, 'ale_use_global_executables', 0))
7 call ale#Set('python_autoimport_auto_pipenv', 0)
8 call ale#Set('python_autoimport_auto_poetry', 0)
9 call ale#Set('python_autoimport_auto_uv', 0)
10
11 function! ale#fixers#autoimport#GetExecutable(buffer) abort
12     if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_autoimport_auto_pipenv'))
13     \ && ale#python#PipenvPresent(a:buffer)
14         return 'pipenv'
15     endif
16
17     if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_autoimport_auto_poetry'))
18     \ && ale#python#PoetryPresent(a:buffer)
19         return 'poetry'
20     endif
21
22     if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_autoimport_auto_uv'))
23     \ && ale#python#UvPresent(a:buffer)
24         return 'uv'
25     endif
26
27     return ale#python#FindExecutable(a:buffer, 'python_autoimport', ['autoimport'])
28 endfunction
29
30 function! ale#fixers#autoimport#Fix(buffer) abort
31     let l:executable = ale#fixers#autoimport#GetExecutable(a:buffer)
32
33     let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
34     \   ? ' run autoimport'
35     \   : ''
36
37     let l:options = ale#Var(a:buffer, 'python_autoimport_options')
38
39     return {
40     \   'cwd': '%s:h',
41     \   'command': ale#Escape(l:executable) . l:exec_args
42     \       . (!empty(l:options) ? ' ' . l:options : '')
43     \       . ' -',
44     \}
45 endfunction