mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-09 04:52:29 +08:00
Merge pull request #3409 from lyz-code/feat/add-autoimport-support
feat: add autoimport fixer
This commit is contained in:
@@ -12,6 +12,11 @@ let s:default_registry = {
|
||||
\ 'suggested_filetypes': ['help'],
|
||||
\ 'description': 'Align help tags to the right margin',
|
||||
\ },
|
||||
\ 'autoimport': {
|
||||
\ 'function': 'ale#fixers#autoimport#Fix',
|
||||
\ 'suggested_filetypes': ['python'],
|
||||
\ 'description': 'Fix import issues with autoimport.',
|
||||
\ },
|
||||
\ 'autopep8': {
|
||||
\ 'function': 'ale#fixers#autopep8#Fix',
|
||||
\ 'suggested_filetypes': ['python'],
|
||||
|
||||
25
autoload/ale/fixers/autoimport.vim
Normal file
25
autoload/ale/fixers/autoimport.vim
Normal file
@@ -0,0 +1,25 @@
|
||||
" Author: lyz-code
|
||||
" Description: Fixing Python imports with autoimport.
|
||||
|
||||
call ale#Set('python_autoimport_executable', 'autoimport')
|
||||
call ale#Set('python_autoimport_options', '')
|
||||
call ale#Set('python_autoimport_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
|
||||
function! ale#fixers#autoimport#Fix(buffer) abort
|
||||
let l:options = ale#Var(a:buffer, 'python_autoimport_options')
|
||||
|
||||
let l:executable = ale#python#FindExecutable(
|
||||
\ a:buffer,
|
||||
\ 'python_autoimport',
|
||||
\ ['autoimport'],
|
||||
\)
|
||||
|
||||
if !executable(l:executable)
|
||||
return 0
|
||||
endif
|
||||
|
||||
return {
|
||||
\ 'command': ale#path#BufferCdString(a:buffer)
|
||||
\ . ale#Escape(l:executable) . (!empty(l:options) ? ' ' . l:options : '') . ' -',
|
||||
\}
|
||||
endfunction
|
||||
Reference in New Issue
Block a user