Panic when autocompleting files under GOPATH
HankelBao opened this issue · comments
What version of Go are you using (go version
)?
go version go1.11.4 linux/amd64
What operating system and processor architecture are you using (go env
)?
GOARCH="amd64"
GOBIN="/home/hankelbao/go/bin"
GOCACHE="/home/hankelbao/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/hankelbao/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build283547848=/tmp/go-build -gno-record-gcc-switches"
What is the debug output of gocode
?
Here is my test code(in go):
package main
import "os/exec"
import "os"
func main() {
c := exec.Command("gocode", "autocomplete", "/home/hankelbao/go/src/github.com/hankelbao/tide/cmd/tide/tide.go", "c51",)
// c := exec.Command("gocode", "autocomplete", "/home/hankelbao/Projects/go_test/testgo.go", "c51",)
c.Stdout = os.Stdout
c.Run()
}
I got this debug output from gocode -s -debug:
2019/01/13 17:04:48 Got autocompletion request for '/home/hankelbao/go/src/github.com/hankelbao/tide/cmd/tide/tide.go'
2019/01/13 17:04:48 Cursor at: 0
2019/01/13 17:04:48 -------------------------------------------------------
#
2019/01/13 17:04:48 -------------------------------------------------------
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x7e7e31]
goroutine 1141 [running]:
go/token.(*File).Pos(...)
/usr/lib/go/src/go/token/position.go:251
github.com/stamblerre/gocode/internal/suggest.(*Config).analyzePackage.func1(0xc00013eb00, 0xc00032be50, 0x41, 0xc003d76900, 0x689, 0x889, 0x0, 0xc0003a1020, 0x5)
/home/hankelbao/go/src/github.com/stamblerre/gocode/internal/suggest/suggest.go:152 +0x4c1
golang.org/x/tools/go/packages.(*loader).parseFiles.func1(0xc0001ac0a0, 0xc003a30520, 0xc003a30560, 0xc000eed7f0, 0x11, 0xc00032be50, 0x41)
/home/hankelbao/go/src/golang.org/x/tools/go/packages/packages.go:788 +0x291
created by golang.org/x/tools/go/packages.(*loader).parseFiles
/home/hankelbao/go/src/golang.org/x/tools/go/packages/packages.go:772 +0x1d8
However, when I tried file that is not in GOPATH, it works:
package main
import "os/exec"
import "os"
func main() {
// c := exec.Command("gocode", "autocomplete", "/home/hankelbao/go/src/github.com/hankelbao/tide/cmd/tide/tide.go", "c51",)
c := exec.Command("gocode", "autocomplete", "/home/hankelbao/Projects/go_test/testgo.go", "c51",)
c.Stdout = os.Stdout
c.Run()
}
What (client-side) flags are you passing into gocode
?
Just 'autocomplete', the file name, and the offset.
Based on your debug output, it seems like gocode is not finding your file. Notice that there is a "#" sign in the debug output, but there is no file content around it. The # sign is supposed to mark where the completion is in the file. That seems to be the problem to me.
Also, when I run gocode from the command line, I usually pass in arguments like this: gocode -in /path/to/file.go autocomplete /path/to/file.go <offset>
. Maybe try that?
Yes. What you are saying is correct.
If I want gocode to autocomplete a file, I need the '-in' argument.
If I want gocode to autocomplete from buffer, I need to send the content of the file through Stdin.
Obviously, in this situation, I should add the '-in' argument.
Thank you very much for your help.