nsf / gocode

An autocompletion daemon for the Go programming language
MIT License
5.01k stars 657 forks source link

Is it possible to autocomplete when using `dep`? #491

Closed jsfr closed 3 years ago

jsfr commented 6 years ago

When using https://github.com/golang/dep in a project all dependencies are placed in the project root under vendor/[url]/... is it possible to get gocode to see these and autocomplete them?

I realize dep is still an experiment, but I thought there might be a way since it's the official one. Still, I haven't been able to make it work either using the lib-path or package-lookup-mode

nsf commented 6 years ago

I'm not tracking what's going on with dep, but I'll have a look at it and tell you more about the gocode <-> dep situation. Will try to do so later today, hopefully won't forget about it.

nsf commented 6 years ago

Well I took a brief look. Seems like dep doesn't do any custom building. It relies on go tool and gocode should support everything go tool supports. Maybe. The main question to answer is where are the compiled libraries reside. Gocode pulls info only from compiled libraries or the currently edited package. Local autocompletion should work always, but when it comes to imported party packages it's important to make sure gocode finds the right binaries. What exactly doesn't work in your case?

jsfr commented 6 years ago

So yeah as you're saying what doesn't work is exactly trying to autocomplete imported 3rd party packages which have been added to the project using dep instead of go get.

I think it may be some misconfiguration on my side though.

I've tried using gocode's autocompletion with Neovim and VS Code. For code all I have to do is download the Go extension and autocompletion works just fine in the project.

However for Vim I'm trying to use https://github.com/zchee/deoplete-go to get gocode working with Deoplete and here it doesn't seem to work :(. So probably this is just me no being able to figure out the right setup.

I'll continue to play around with it and write here if I make it work :)

DisposaBoy commented 6 years ago

@jsfr dep just inserts things in the vendor directory so it should work if the vendored package is installed - gocode relies on the compiled .a files for imported packages. Maybe Neovim and VS Code are using the autobuild option from https://github.com/nsf/gocode#options

JianleiZhang commented 6 years ago

I also encountered this problem. My temporary solution is: go build -i in the project path.

ghost commented 6 years ago

I just encountered this in my own project and even though I have .a files generated under the /pkg path gocode still seems to fail with the autocomplete.

BrillianceSummer commented 6 years ago

emacs gocode dep not work

Koshroy commented 6 years ago

This issue isn't emacs specific, but are the arguments being passed incorrectly to gocode in the emacs gocode autocomplete? go build -i does fix it temporarily (or running go install on the 3rd party deps that I added using dep ensure) but that's not a solution I'd like to support long term. The arguments are being passed in https://github.com/nsf/gocode/blob/master/emacs/go-autocomplete.el#L101 . I'm not super familiar with the arguments that gocode takes.

palsivertsen commented 6 years ago

I managed to get this working by setting this flag: gocode set autobuild true The docs says this is an experimental feature.

My setup was as follows:

  1. Clean go directories
  2. Create a project and install a dependency: echo -e "package main\nfunc main(){}" > main.go && dep init && dep ensure -add github.com/gorilla/mux
  3. Add main.go and try auto completion for router (does not work):
    
    package main

import ( "net/http"

"github.com/gorilla/mux"

)

func main() { router := mux.NewRouter() router.hand // Autocomplete here http.Handle("/", router) }

4. Enable autobuild:
`gocode set autobuild true`
5. Try autocompletion (works):
```go
package main

import (
    "net/http"

    "github.com/gorilla/mux"
)

func main() {
    router := mux.NewRouter()
    router.Handle(path, handler) // Autocomplete here
    http.Handle("/", router)
}
kovetskiy commented 6 years ago

@palsivertsen try to run go install ./vendor/... between 2 and 3 steps

palsivertsen commented 6 years ago

@kovetskiy That seems to work as well, even with gocode set autobuild false