nsf / gocode

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

Multiple files in a package #181

Closed ulrichSchreiner closed 10 years ago

ulrichSchreiner commented 10 years ago

hi

if i have multiple files in a package and send one of them via stdin to gocode, gocode seems to ignore all content of the other files of the same package.

For example: I have a package "mymodule" and there i have "mymodule.go" and "mymodule_test.go", both contain "package mymodule". if i send the "mymodule_test.go" via stdin to gocode, nothing from "mymodule.go" is recognized; all structs, functions ... no autocompletion for this elements is contained in the result.

how can i work around this problem?

thx

nsf commented 10 years ago

I guess new integration docs are a bit confusing. The full command spec you usually run from a text editor looks like this: gocode autocomplete <path> <cursor offset>, and of course you pass the current buffer via stdin. The important part here is <path>. While gocode doesn't support passing in multiple unsaved files, it will look for other files of the package on the file system using that path as a pointer to the directory.

For example, let's say you have a directory with your Go project: ~/mygo/src/proj. And it has files a.go and b.go. In order for gocode to work properly you should invoke it like this: gocode autocomplete ~/mygo/src/proj/a.go 123 and pass a.go contents via stdin. That way gocode will deduce the directory of your project to ~/mygo/src/proj and will look for other .go files there with matching package clause.

Hopefully it makes sense.

ulrichSchreiner commented 10 years ago

Works like a charm.

Thanks.