]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/go.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / go.vim
1 " Author: Horacio Sanson https://github.com/hsanson
2 " Description: Functions for integrating with Go tools
3
4 " Find the nearest dir listed in GOPATH and assume it the root of the go
5 " project.
6 function! ale#go#FindProjectRoot(buffer) abort
7     let l:sep = has('win32') ? ';' : ':'
8
9     let l:filename = ale#path#Simplify(expand('#' . a:buffer . ':p'))
10
11     for l:name in split($GOPATH, l:sep)
12         let l:path_dir = ale#path#Simplify(l:name)
13
14         " Use the directory from GOPATH if the current filename starts with it.
15         if l:filename[: len(l:path_dir) - 1] is? l:path_dir
16             return l:path_dir
17         endif
18     endfor
19
20     let l:default_go_path = ale#path#Simplify(expand('~/go'))
21
22     if isdirectory(l:default_go_path)
23         return l:default_go_path
24     endif
25
26     return ''
27 endfunction
28
29
30 call ale#Set('go_go111module', '')
31
32 " Return a string setting Go-specific environment variables
33 function! ale#go#EnvString(buffer) abort
34     let l:env = ''
35
36     " GO111MODULE - turn go modules behavior on/off
37     let l:go111module = ale#Var(a:buffer, 'go_go111module')
38
39     if !empty(l:go111module)
40         let l:env = ale#Env('GO111MODULE', l:go111module) . l:env
41     endif
42
43     return l:env
44 endfunction
45
46 function! ale#go#GetGoPathExecutable(suffix) abort
47     let l:prefix = $GOPATH
48
49     if !empty($GOPATH)
50         let l:prefix = $GOPATH
51     elseif has('win32')
52         let l:prefix = $USERPROFILE . '/go'
53     else
54         let l:prefix = $HOME . '/go'
55     endif
56
57     return ale#path#Simplify(l:prefix . '/' . a:suffix)
58 endfunction