summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2020-11-21 20:45:51 +0000
committerGitHub <noreply@github.com>2020-11-21 20:45:51 +0000
commitb4550f361bc0d8d0cce81ecc02c82167b6df0738 (patch)
tree376d866381a40fbea3eb51ea45709feb599ccaad /autoload
parentb09ccc12c3001b4d551d35cb0c4195793d9b6d10 (diff)
parent513e6ee972ea4ee57b28b8b8c10e0b89bb674f25 (diff)
downloadale-b4550f361bc0d8d0cce81ecc02c82167b6df0738.zip
Merge pull request #3409 from lyz-code/feat/add-autoimport-support
feat: add autoimport fixer
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/autoimport.vim25
2 files changed, 30 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 64e65214..3a88ede1 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -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'],
diff --git a/autoload/ale/fixers/autoimport.vim b/autoload/ale/fixers/autoimport.vim
new file mode 100644
index 00000000..37a52db8
--- /dev/null
+++ b/autoload/ale/fixers/autoimport.vim
@@ -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