Skip to content

Commit

Permalink
Merge pull request #1988 from fatih/gocode
Browse files Browse the repository at this point in the history
gocode: add support for experimental gocode
  • Loading branch information
bhcleek authored Oct 21, 2018
2 parents e0499fa + ec76e30 commit 5fffae9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
17 changes: 16 additions & 1 deletion autoload/go/complete.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
function! s:gocodeCommand(cmd, args) abort
let bin_path = go#path#CheckBinPath("gocode")
let l:gocode_bin = "gocode"
let l:gomod = go#util#gomod()
if filereadable(l:gomod)
" Save the file when in module mode so that go list can read the
" imports. If the user doesn't have autowrite or autorwriteall enabled,
" they'll need to write the file manually to get reliable results.
" See https://github.com/fatih/vim-go/pull/1988#issuecomment-428576989.
"
" TODO(bc): don't save the file when in module mode once
" golang.org/x/tools/go/packages has support for an overlay and it's used
" by gocode.
call go#cmd#autowrite()
let l:gocode_bin = "gocode-gomod"
endif

let bin_path = go#path#CheckBinPath(l:gocode_bin)
if empty(bin_path)
return []
endif
Expand Down
7 changes: 7 additions & 0 deletions autoload/go/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ function! go#util#gopath() abort
return substitute(s:exec(['go', 'env', 'GOPATH'])[0], '\n', '', 'g')
endfunction

" gomod returns 'go env GOMOD'. gomod changes depending on the folder. Don't
" use go#util#env as it caches the value.
function! go#util#gomod() abort
return substitute(s:exec(['go', 'env', 'GOMOD'])[0], '\n', '', 'g')
endfunction


function! go#util#osarch() abort
return go#util#env("goos") . '_' . go#util#env("goarch")
endfunction
Expand Down
1 change: 1 addition & 0 deletions plugin/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let s:packages = {
\ 'errcheck': ['github.com/kisielk/errcheck'],
\ 'fillstruct': ['github.com/davidrjenni/reftools/cmd/fillstruct'],
\ 'gocode': ['github.com/mdempsky/gocode', {'windows': ['-ldflags', '-H=windowsgui']}],
\ 'gocode-gomod': ['github.com/stamblerre/gocode'],
\ 'godef': ['github.com/rogpeppe/godef'],
\ 'gogetdoc': ['github.com/zmb3/gogetdoc'],
\ 'goimports': ['golang.org/x/tools/cmd/goimports'],
Expand Down

0 comments on commit 5fffae9

Please sign in to comment.