rogpeppe / godef

Print where symbols are defined in Go source code
BSD 3-Clause "New" or "Revised" License
666 stars 142 forks source link

godef needs GOPATH set but this is not needed by Go 1.9 onwards #73

Open duncanharris opened 6 years ago

duncanharris commented 6 years ago

I have Go installed to a non-standard path. With Go 1.9 all you need is the go executable on the path and then Go figures everything out from there. However godef is not so clever and wants GOROOT to be set.

The following shows my Go environment with godef not working and then me setting GOROOT to get it working.

$ ls -l `which go`
lrwxrwxrwx 1 root root 29 Sep 12 11:01 /usr/bin/go -> /home/duncan/.go/go1.9/bin/go
$ set | fgrep GO
GOPATH=/home/duncan/.local
$ go version
go version go1.9 linux/amd64
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/duncan/.local"
GORACE=""
GOROOT="/home/duncan/.go/go1.9"
GOTOOLDIR="/home/duncan/.go/go1.9/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build177033922=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
$ godef -f pkg/data/codebook/codebook.go csv.Reader
parseLocalPackage error: no more package files found
godef: no declaration found for csv.Reader
$ export GOROOT=/home/duncan/.go/go1.9
$ godef -f pkg/data/codebook/codebook.go csv.Reader
/home/duncan/.go/go1.9/src/encoding/csv/reader.go:90:6
$ set | fgrep GO
GOPATH=/home/duncan/.local
GOROOT=/home/duncan/.go/go1.9
$ 
yaojingguo commented 6 years ago

I have the same problem. I am using Go 1.9.1.

csuzuliangpan commented 6 years ago

the same prooblem,did you fand the way?come share

yaojingguo commented 6 years ago

You can try to set GOPATH.