Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autocompletions unavailable for local packages #2018

Closed
danprince opened this issue Oct 12, 2018 · 15 comments
Closed

autocompletions unavailable for local packages #2018

danprince opened this issue Oct 12, 2018 · 15 comments

Comments

@danprince
Copy link

What did you do?

Trying to use autocomplete:

  • For a package from the standard library ✅
  • For a variable inside the current package ✅
  • For a remote package installed with go get
  • For a local package in $GOPATH/src

Looks like this is happening because the appropriate package objects under $GOPATH/pkg aren't being generated for some reason.

If I open the same files within vscode (using the vscode-go plugin, which also uses $GOPATH/bin/gocode) it works fine and the $GOPATH/pkg/**/*.a files are generated.

If I switch back into vim at this point, I can use those completions, however, if I update a file outside of the package I have open, then the completions aren't updated.

If I use the <C-x><C-o> binding, then the completion works but it's incredibly slow (> 2s each time). It doesn't generate the $GOPATH/pkg files either.

I've tried the following completion plugins with no luck:

  • deoplete and deoplete-go
  • ncm2 and ncm2-go

Tried with let g:go_gocode_propose_source = 1 but same problem.

Configuration (MUST fill this out):

  • vim-go version: 620e8ac

  • vimrc you used to reproduce:

call plug#begin('~/.vim/plugged')

Plug 'fatih/vim-go'

Plug 'Shougo/deoplete.nvim'
Plug 'zchee/deoplete-go', { 'do': 'make'}

let g:deoplete#enable_at_startup = 1

call plug#end()
  • Vim version (first three lines from :version):
NVIM v0.3.1
Build type: Release
LuaJIT 2.0.5
  • Go version (go version):
go version go1.11.1 darwin/amd64
  • Go environment (go env):
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/dan/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/dan/dev/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1d/fsc7nxn16b35vps3z8rl2h8m0000gn/T/go-build753843243=/tmp/go-build -gno-record-gcc-switches -fno-common"
@danprince danprince changed the title async completions unavailable async completions unavailable for local packages Oct 13, 2018
@danprince
Copy link
Author

danprince commented Oct 13, 2018

If I go install the packages manually after each change, completions works fine.

Looks like it could be related to #1853. Looks like nsf/gocode had an option for autobuilding that doesn't exist in mdempsly/gocode.

From the comments in that thread, it sounds like the propose source option is exactly what I want here, not sure why it's not working.

let g:go_gocode_propose_source = 1

Sounds like vscode-go got around this with a default buildOnSave option, that calls go build with the -i flag to also install dependencies.

So my short term workaround is:

autocmd BufWritePost *.go silent! GoBuild -i

Will also experiment with using an older version of Go with nsf/gocode.

@bhcleek
Copy link
Collaborator

bhcleek commented Oct 13, 2018

You found the right issue that explains the behavior you've noticed, and your work around is the right thing for you to do.

As for why the propose source option isn't working for you: it's possible that you're unintentionally using nsf instead of mdempsky; the last time I looked some other plugins still install and use nsf.

Even though you've found the right workaround, I'll leave this open for now as a reminder that an option to build on write is a feature to consider.

PRs welcome.

@danprince
Copy link
Author

Thanks @bhcleek! I'm pretty new to Go and learning a lot on the way.

If the propose source option is disabled by default and mdempsky (understandably) doesn't support autobuild, doesn't that mean that—by default—all vim-go users would need to go install local packages after every change they make locally to prevent completions from going stale?

Seems like build-on-write would be a less surprising default, especially as more people start to upgrade to the versions of vim-go that don't support nsf and stop getting up to date completions.

Let me know if it makes sense and I'll send a PR for a build-on-write option. Can disable it by default and see if this issue gets more attention from others running into the same thing.

@bhcleek
Copy link
Collaborator

bhcleek commented Oct 13, 2018

g:go_gocode_propose_source is on by default.

Installing on write comes with some unacceptable tradeoffs IMO:

  • main packages should likely not be installed on every write.
  • the pkg directory is likely to go away in a future version of Go, because it's not necessary for most tools now that there's package caching.
  • the user may have their GOPATH in a state where not all packages should be installed, so go build -i may be the wrong thing to use.

Ideally, one could just go build, which would cause packages to be cached, and then gocode would use the package cache. There's work being done on that front. You may want to familiarize yourself with mdempsky/gocode#46.

@danprince
Copy link
Author

Not sure why I thought it was off by default. 🤦‍♂️

@bhcleek bhcleek changed the title async completions unavailable for local packages autocompletions unavailable for local packages Oct 13, 2018
@danprince
Copy link
Author

danprince commented Oct 14, 2018

Also managed to get things working correctly by reverting to nsf/gocode and downgrading the minor version of go.

  • Downgrade to go1.9.7
  • gocode exit
  • rm $GOPATH/bin/gocode
  • go get github.com/nsf/gocode
  • gocode set autobuild true

@GeorgeMac
Copy link

Just going to share this here mdempsky/gocode#67

I raised an issue because I am having trouble with vim-go + gocode since moving to go1.11.

I have been sent back to vim-go now 😂 and this issue seems related and maybe the context will help.

@bhcleek
Copy link
Collaborator

bhcleek commented Oct 16, 2018

@GeorgeMac I can't duplicate that problem you're seeing at all.

I noticed that the video you posted, though, used a type local to the package, but the example you posted after running gocode -s debug was trying to autocomplete a testing.T.

@GeorgeMac
Copy link

I will try a local type and get back to you 👍

@flowchartsman
Copy link
Contributor

flowchartsman commented Oct 24, 2018

Also running into this issue, and happy to contribute debug cycles if anyone wants to coordinate. Not testing packages, so definitely as described, with the same autocmd workaround fixing it. Confirm local gopath completion only.

@bhcleek
Copy link
Collaborator

bhcleek commented Oct 24, 2018

@flowchartsman which gocode are you using? (mdempsky and nsf have different options, so gocode --help can be used to identify which one you're running.

Do you have any g:go_gocode_* options set? What's in your $HOME/.config/gocode/config.json?

Can you provide a way to duplicate the problem you're seeing?

@mnarrell
Copy link

mnarrell commented Nov 5, 2018

Is there any update here? Since the 1.19 release, the gocode based autocomplete simply does not work.

@bhcleek
Copy link
Collaborator

bhcleek commented Nov 6, 2018

@mnarrell vim-go changed to use github.com/mdempsky/gocode in v1.19, and it has slightly different options. To make sure you're using the correct version, please exit vim, and then in your shell run

gocode close
gocode exit

After that you should be able to run :GoUpdateBinaries in vim, and try again. If you still have problems with autocompletion afterwards, please open a separate issue so this issue can stay focused on the problems originally reported by @danprince.

@bhcleek
Copy link
Collaborator

bhcleek commented Nov 17, 2018

closed for lack of feedback

@bhcleek bhcleek closed this as completed Nov 17, 2018
@ldelossa
Copy link
Contributor

ldelossa commented Nov 21, 2018

@danprince I believe your example should be:

autocmd BufWritePost *.go silent! :GoBuild -i

This work around seems to work OK for me. Just worried about any caching gocode may do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants