summaryrefslogtreecommitdiff
path: root/ale_linters/go/gopls.vim
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2021-05-26 22:43:30 +0100
committerw0rp <devw0rp@gmail.com>2021-05-26 22:43:33 +0100
commitf53431331e2e2030a84de081baec93aad1e62363 (patch)
treec44ff92c5e4aaf6b39100e9ee40484a49ae39f78 /ale_linters/go/gopls.vim
parent3f386ae5e988d6e1b39332a760f9e990d2df7f31 (diff)
downloadale-f53431331e2e2030a84de081baec93aad1e62363.zip
Enable gopls by default with GOPATH detection
Diffstat (limited to 'ale_linters/go/gopls.vim')
-rw-r--r--ale_linters/go/gopls.vim19
1 files changed, 18 insertions, 1 deletions
diff --git a/ale_linters/go/gopls.vim b/ale_linters/go/gopls.vim
index f3f1bd6b..23082e9b 100644
--- a/ale_linters/go/gopls.vim
+++ b/ale_linters/go/gopls.vim
@@ -5,6 +5,21 @@
call ale#Set('go_gopls_executable', 'gopls')
call ale#Set('go_gopls_options', '--mode stdio')
call ale#Set('go_gopls_init_options', {})
+call ale#Set('go_gopls_use_global', get(g:, 'ale_use_global_executables', 0))
+
+function! s:GetGoPathExecutable(suffix) abort
+ let l:prefix = $GOPATH
+
+ if !empty($GOPATH)
+ let l:prefix = $GOPATH
+ elseif has('win32')
+ let l:prefix = $USERPROFILE . '/go'
+ else
+ let l:prefix = $HOME . '/go'
+ endif
+
+ return ale#path#Simplify(l:prefix . '/' . a:suffix)
+endfunction
function! ale_linters#go#gopls#GetCommand(buffer) abort
return ale#go#EnvString(a:buffer)
@@ -29,7 +44,9 @@ endfunction
call ale#linter#Define('go', {
\ 'name': 'gopls',
\ 'lsp': 'stdio',
-\ 'executable': {b -> ale#Var(b, 'go_gopls_executable')},
+\ 'executable': {b -> ale#path#FindExecutable(b, 'go_gopls', [
+\ s:GetGoPathExecutable('bin/gopls'),
+\ ])},
\ 'command': function('ale_linters#go#gopls#GetCommand'),
\ 'project_root': function('ale_linters#go#gopls#FindProjectRoot'),
\ 'initialization_options': {b -> ale#Var(b, 'go_gopls_init_options')},