ale/autoload/ale/fixers/goimports.vim
Martin Tournoij 92f20b0e51
goimports fixer doesn't work for vendored libraries
In Go you can "vendor" packages by putting them in the `vendor/`
directory for a project. Adding the `-srcdir` argument makes `goimports`
pick up these packages, in addition to what you have in GOPATH.

Without this, `goimports` is not very useful, since most projects vendor
their packages.
2017-12-08 12:49:02 +00:00

23 lines
657 B
VimL

" Author: Jeff Willette <jrwillette88@gmail.com>
" Description: Integration of goimports with ALE.
call ale#Set('go_goimports_executable', 'goimports')
call ale#Set('go_goimports_options', '')
function! ale#fixers#goimports#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'go_goimports_executable')
let l:options = ale#Var(a:buffer, 'go_goimports_options')
if !executable(l:executable)
return 0
endif
return {
\ 'command': ale#Escape(l:executable)
\ . ' -l -w -srcdir %s'
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction