nsf / gocode

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

no completion for standard libraries, e.g. "fmt" #329

Closed afiodorov closed 8 years ago

afiodorov commented 8 years ago

Code

package main

import "fmt"

func main() {
        fmt.Printf("hi\n")
}

Try auto completion at every single offset:

for i in {1..130}; do gocode -debug=true -f json autocomplete $i <~/go/src/afiodorov/example/hello.go; echo ""; done
[]
[]
[]
[]
...
[0, [{"class": "PANIC", "name": "PANIC", "type": "PANIC"}]]

not a single line contains Printf

My environment seems to be set-up correctly:

go env

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/tom/go"
GORACE=""
GOROOT="/usr"
GOTOOLDIR="/usr/lib/gcc/x86_64-unknown-linux-gnu/5.3.0"
CC="/usr/bin/gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="/usr/bin/g+

Contents of my ~/go:

tree -L 3

.
├── bin
│   ├── asmfmt
│   ├── gocode
│   ├── goimports
│   ├── golint
│   ├── gometalinter
│   ├── gorename
│   └── gotags
├── pkg
│   └── gccgo_linux_amd64
│       ├── github.com
│       ├── golang.org
│       └── gopkg.in
└── src
    ├── 9fans.net
    │   └── go
    ├── afiodorov
    │   └── example
    ├── github.com
    │   ├── alecthomas
    │   ├── golang
    │   ├── google
    │   ├── jstemmer
    │   ├── kisielk
    │   ├── klauspost
    │   ├── nsf
    │   └── rogpeppe
    ├── golang.org
    │   └── x
    └── gopkg.in
        └── alecthomas

24 directories, 7 files

On the other hand, gocode outputs correct predictions if I include an interface.

I browsed though issues - similar things have been raised - but were diagnosed with a problem I don't have. Still, sorry if it's duplicate. I might be missing something trivial as I just installed go - and I am very inexperienced in it.

nsf commented 8 years ago

-debug is not a client flag, but a server flag. Do what https://github.com/nsf/gocode#debugging says.

afiodorov commented 8 years ago

Thanks for a quick response.

2016/02/27 16:35:40 Go project path: .
2016/02/27 16:35:40 Got autocompletion request for ''
2016/02/27 16:35:40 Cursor at: 47
2016/02/27 16:35:40 -------------------------------------------------------
package main

import "fmt"

func main() {
        fmt.#Printf("hi\n")
}
2016/02/27 16:35:40 -------------------------------------------------------
2016/02/27 16:35:40 Import path "fmt" was not resolved
2016/02/27 16:35:40 Gocode's build context is:
2016/02/27 16:35:40  GOROOT: /usr
2016/02/27 16:35:40  GOPATH: /home/tom/go
2016/02/27 16:35:40  GOOS: linux
2016/02/27 16:35:40  GOARCH: amd64
2016/02/27 16:35:40  GBProjectRoot: ""
2016/02/27 16:35:40  lib-path: ""
2016/02/27 16:35:40 Error parsing input file (inner block):
2016/02/27 16:35:40  4:6: expected selector or type assertion, found ';'
2016/02/27 16:35:40  4:7: expected ';', found 'IDENT' Printf
2016/02/27 16:35:40  5:2: expected '}', found 'EOF'
2016/02/27 16:35:40  5:2: expected ';', found 'EOF'
2016/02/27 16:35:40 extracted expression tokens: fmt
2016/02/27 16:35:40 Offset: 0
2016/02/27 16:35:40 Number of candidates found: 0
2016/02/27 16:35:40 Candidates are:
2016/02/27 16:35:40 =======================================================
nsf commented 8 years ago

You showed your env before and I haven't noticed this line:

GOTOOLDIR="/usr/lib/gcc/x86_64-unknown-linux-gnu/5.3.0"

Which implies there is some sort of a conflict between gccgo and go. Gocode doesn't support gccgo libraries and it has to be compiled with go compiler so that it knows where its libraries are located.

Debug output also shows GOROOT dir which is most likely the one gccgo uses.

2016/02/27 16:35:40 GOROOT: /usr

I can suggest few solutions:

  1. Uninstall gccgo.
  2. Install go manually to some dir like ~/go and add ~/go/bin to PATH before everything else.

I would recommend doing (2). Most distros fuck things up when it comes to packaging Go (even my beloved archlinux).

afiodorov commented 8 years ago

Removed gccgo and installed go package. Now it all works.