mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-24 21:11:28 +08:00
Allows the user to override $GO111MODULE environment variable through ale options. This gives control over the default behavior of Go module resolution. Golang documentation: https://github.com/golang/go/wiki/Modules#how-to-use-modules Add `ale#Go#EnvString()` function to make it easy to add similar Go environment variables in the future. Use the new `EnvString` function in all available Go tools callbacks & update tests Also add test of linter command callback for `gofmt`
45 lines
1.2 KiB
VimL
45 lines
1.2 KiB
VimL
" Author: Horacio Sanson https://github.com/hsanson
|
|
" Description: Functions for integrating with Go tools
|
|
|
|
" Find the nearest dir listed in GOPATH and assume it the root of the go
|
|
" project.
|
|
function! ale#go#FindProjectRoot(buffer) abort
|
|
let l:sep = has('win32') ? ';' : ':'
|
|
|
|
let l:filename = ale#path#Simplify(expand('#' . a:buffer . ':p'))
|
|
|
|
for l:name in split($GOPATH, l:sep)
|
|
let l:path_dir = ale#path#Simplify(l:name)
|
|
|
|
" Use the directory from GOPATH if the current filename starts with it.
|
|
if l:filename[: len(l:path_dir) - 1] is? l:path_dir
|
|
return l:path_dir
|
|
endif
|
|
endfor
|
|
|
|
let l:default_go_path = ale#path#Simplify(expand('~/go'))
|
|
|
|
if isdirectory(l:default_go_path)
|
|
return l:default_go_path
|
|
endif
|
|
|
|
return ''
|
|
endfunction
|
|
|
|
|
|
call ale#Set('go_go111module', '')
|
|
|
|
" Return a string setting Go-specific environment variables
|
|
function! ale#go#EnvString(buffer) abort
|
|
let l:env = ''
|
|
|
|
" GO111MODULE - turn go modules behavior on/off
|
|
let l:go111module = ale#Var(a:buffer, 'go_go111module')
|
|
|
|
if !empty(l:go111module)
|
|
let l:env = ale#Env('GO111MODULE', l:go111module) . l:env
|
|
endif
|
|
|
|
return l:env
|
|
endfunction
|