go: x/tools/gopls: not working inside of $GOPATH

gopls did not recognize the correct path of import file. and gopls can not go to definenation in side the goroot.

  • I am working inside the GOPATH
  • GOMODULE111 is set as default (auto)
  • at go 1.12.7 on OSX
  • did not set GOROOT manually

I install go use the official install package from golang.org for osx.

Problems:

can not recognize fields

  • vim + ale + gopls
  • opened my project

image

can not go to define inside go root code

  • I opened my project in GOPATH
  • locate at `os.Open()
  • go to definitions
  • locate at an internal function
  • go to definitions, failed.

What version of Go are you using (go version)?

$ go version
go version go1.12.7 darwin/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
arthur@ArthursMacBookPro:~$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/arthur/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/arthur/golang"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nh/71f5qs9n3dz3v02z77nc86640000gn/T/go-build495324181=/tmp/go-build -gno-record-gcc-switches -fno-common"

env Output

env

Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.o82G0O0EfW/Render COLORFGBG=7;0 COLORTERM=truecolor CPPFLAGS=-I/usr/local/opt/llvm/include ETCDCTL_API=3 GOPATH=/Users/arthur/golang HOME=/Users/arthur ITERM_PROFILE=Default ITERM_SESSION_ID=w0t2p0:FD5B131C-E44F-45FE-9940-4E36328743AE LANG=en_US.UTF-8 LC_CTYPE=UTF-8 LDFLAGS=-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib LOGNAME=arthur PATH=/usr/local/opt/libressl/bin:/usr/local/opt/llvm/bin:/usr/local/opt/curl/bin:/usr/local/sbin:/usr/local/nginx/sbin:/Users/arthur/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/go/bin:/Applications/Wireshark.app/Contents/MacOS PWD=/Users/arthur SHELL=/usr/local/bin/fish SHLVL=1 SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.E9l9HnN7sF/Listeners TERM=xterm-256color TERM_PROGRAM=iTerm.app TERM_PROGRAM_VERSION=3.2.9 TERM_SESSION_ID=w0t2p0:FD5B131C-E44F-45FE-9940-4E36328743AE TMPDIR=/var/folders/nh/71f5qs9n3dz3v02z77nc86640000gn/T/ USER=arthur XPC_FLAGS=0x0 XPC_SERVICE_NAME=0 __CF_USER_TEXT_ENCODING=0x0:25:52 fish_user_paths=/usr/local/opt/libressl/bin /usr/local/opt/llvm/bin /usr/local/opt/curl/bin /usr/local/sbin

What did you do?

  • tried latest gopls
  • tried stable tag of gopls
  • set GOMODULE111=off when build gopls and use gopls

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 28 (11 by maintainers)

Most upvoted comments

Thank you - based on the logs, it seems like we are treating your package as if it were just a single file. For gopls you have to set a workspace root (https://github.com/golang/go/issues/32394), so that gopls knows where to find the go.mod file. I’m not sure how to configure that with your editor, but that may be the problem here.

Indeed we do need to fix the behavior. https://github.com/golang/go/issues/33462 will track this, and you can follow along for updates there. Thanks for bearing with me while we diagnosed this issue!

net/http depends on packages that have cgo code. It looks like these are runtime/cgo, net, and crypto/x509.

If the -compiled flag is passed to go list, listed packages and their dependencies are compiled, and the paths to the compiled .a files are included in the output. If cgo is enabled, a C compiler is required to build those packages. I’m guessing gopls uses the compiled .a files for type information, but even if it didn’t, cgo may be required for type checking.

@bwmarrin Have you tried disabling cgo by setting CGO_ENABLED=0 in your environment? I don’t believe cgo is disabled automatically depending on whether there is a C compiler in PATH.

@arthurkiller: I believe this quote from https://github.com/golang/go/issues/33018#issuecomment-518374510 should explain your problem. Can you try setting CGO_ENABLED=0 in your environment? Do you have a C compiler in your $PATH?