Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: errors when using a build constraint #37624

Closed
mtibben opened this issue Mar 3, 2020 · 4 comments
Closed

x/tools/gopls: errors when using a build constraint #37624

mtibben opened this issue Mar 3, 2020 · 4 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@mtibben
Copy link

mtibben commented Mar 3, 2020

What did you do?

  1. Checked out this repo at this commit
  2. Opened VS Code
  3. Opened libsecret.go
  4. Hovered the mouse pointer over a method name

What did you expect to see?

Information about the method in a tooltip

What did you see instead?

Loading... flashed up then disappeared

Info

Build info
golang.org/x/tools/gopls v0.3.3
    golang.org/x/tools/gopls@(devel)
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
    golang.org/x/mod@v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20200227200655-6862ededa516 => ../
    golang.org/x/xerrors@v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=
Go info
go version go1.14 darwin/amd64

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/michael/Library/Caches/go-build"
GOENV="/Users/michael/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/michael/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/michael/src/github.com/99designs/keyring/go.mod"
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/7q/pgl16tb16mbf6gfdbzdr1l9w0000gn/T/go-build074438413=/tmp/go-build -gno-record-gcc-switches -fno-common"
gopls trace logs
[Trace - 21:26:02.874 PM] Sending response 'workspace/configuration - (2)' took 54ms.
Result: [{"usePlaceholders":true,"staticcheck":false},null]


[Trace - 21:26:02.965 PM] Sending request 'textDocument/foldingRange - (4)'.
Params: {"textDocument":{"uri":"file:///Users/michael/src/github.com/99designs/keyring/libsecret.go"}}


[Trace - 21:26:03.012 PM] Sending request 'textDocument/codeLens - (5)'.
Params: {"textDocument":{"uri":"file:///Users/michael/src/github.com/99designs/keyring/libsecret.go"}}


[Trace - 21:26:03.032 PM] Sending request 'textDocument/hover - (6)'.
Params: {"textDocument":{"uri":"file:///Users/michael/src/github.com/99designs/keyring/libsecret.go"},"position":{"line":12,"character":7}}


[Trace - 21:26:03.474 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/03/03 21:26:03 go/packages.Load\n\tsnapshot = 0\n\tquery = [./... builtin]\n\tpackages = 7"}


[Info  - 9:26:03 pm] 2020/03/03 21:26:03 go/packages.Load
	snapshot = 0
	query = [./... builtin]
	packages = 7
2020/03/03 21:26:04 DocumentSymbols failed: getting file for DocumentSymbols: no PackageHandles
	URI = file:///Users/michael/src/github.com/99designs/keyring/libsecret.go
[Trace - 21:26:04.146 PM] Received response 'textDocument/documentSymbol - (1)' in 1382ms.
Result: []


[Trace - 21:26:04.165 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/03/03 21:26:04 DocumentSymbols failed: getting file for DocumentSymbols: no PackageHandles\n\tURI = file:///Users/michael/src/github.com/99designs/keyring/libsecret.go"}


[Error - 9:26:04 pm] 2020/03/03 21:26:04 DocumentSymbols failed: getting file for DocumentSymbols: no PackageHandles
	URI = file:///Users/michael/src/github.com/99designs/keyring/libsecret.go
[Trace - 21:26:04.171 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/03/03 21:26:04 go/packages.Load\n\tsnapshot = 1\n\tquery = [file=/Users/michael/src/github.com/99designs/keyring/libsecret.go]\n\tpackages = 0"}


[Info  - 9:26:04 pm] 2020/03/03 21:26:04 go/packages.Load
	snapshot = 1
	query = [file=/Users/michael/src/github.com/99designs/keyring/libsecret.go]
	packages = 0
[Trace - 21:26:04.248 PM] Sending notification '$/cancelRequest'.
Params: {"id":6}


[Trace - 21:26:04.516 PM] Sending request 'textDocument/hover - (7)'.
Params: {"textDocument":{"uri":"file:///Users/michael/src/github.com/99designs/keyring/libsecret.go"},"position":{"line":13,"character":20}}


[Trace - 21:26:04.547 PM] Sending notification '$/cancelRequest'.
Params: {"id":7}


[Trace - 21:26:04.736 PM] Sending request 'textDocument/hover - (8)'.
Params: {"textDocument":{"uri":"file:///Users/michael/src/github.com/99designs/keyring/libsecret.go"},"position":{"line":13,"character":21}}


[Error - 21:26:04.741 PM] Received #2 getting file for AllImportsFixes: no PackageHandles


[Error - 9:26:04 pm] Request textDocument/codeAction failed.
  Message: getting file for AllImportsFixes: no PackageHandles
  Code: 0 
[Trace - 21:26:04.747 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/03/03 21:26:04 go/packages.Load\n\tsnapshot = 1\n\tquery = [file=/Users/michael/src/github.com/99designs/keyring/libsecret.go]\n\tpackages = 0"}


[Info  - 9:26:04 pm] 2020/03/03 21:26:04 go/packages.Load
	snapshot = 1
	query = [file=/Users/michael/src/github.com/99designs/keyring/libsecret.go]
	packages = 0
[Error - 21:26:05.271 PM] Received #3 no PackageHandles


[Error - 9:26:05 pm] Request textDocument/documentLink failed.
  Message: no PackageHandles
  Code: 0 
[Trace - 21:26:05.272 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/03/03 21:26:05 go/packages.Load\n\tsnapshot = 1\n\tquery = [file=/Users/michael/src/github.com/99designs/keyring/libsecret.go]\n\tpackages = 0"}
VS Code config
{
    "go.useLanguageServer": true,
    "[go]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        },
        "editor.snippetSuggestions": "none",
        "editor.codeActionsOnSaveTimeout": 3000,
    },
    "gopls": {
        "usePlaceholders": true,
        "staticcheck": false,
    },
    "go.languageServerFlags": [
        "-rpc.trace"
    ],
}
$ gopls -rpc.trace -v check keyring.go
2020/03/03 21:36:05 Info:2020/03/03 21:36:05 Build info
----------
golang.org/x/tools/gopls v0.3.3
    golang.org/x/tools/gopls@(devel)
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
    golang.org/x/mod@v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20200227200655-6862ededa516 => ../
    golang.org/x/xerrors@v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info
-------
go version go1.14 darwin/amd64

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/michael/Library/Caches/go-build"
GOENV="/Users/michael/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/michael/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/michael/src/github.com/99designs/keyring/go.mod"
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/7q/pgl16tb16mbf6gfdbzdr1l9w0000gn/T/go-build923110138=/tmp/go-build -gno-record-gcc-switches -fno-common"
2020/03/03 21:36:06 Info:2020/03/03 21:36:06 go/packages.Load
	snapshot = 0
	query = [./... builtin]
	packages = 7
@gopherbot gopherbot added this to the Unreleased milestone Mar 3, 2020
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Mar 3, 2020
@gopherbot
Copy link

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.4.0 Mar 3, 2020
@stamblerre stamblerre added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 3, 2020
@mtibben
Copy link
Author

mtibben commented Mar 4, 2020

The problem seems to be caused by the build constraint // +build linux . Removing the build constraint makes the problem go away.

However I would expect gopls to work on files with a build constraint

@mtibben mtibben changed the title x/tools/gopls: hover in VS Code broken x/tools/gopls: errors when using a build constraint Mar 4, 2020
@stamblerre
Copy link
Contributor

stamblerre commented Mar 4, 2020

gopls doesn't yet work automatically with build tags (#29202 is the tracking issue), but you can explicitly specify your build tags in your settings as a work-around. For example:

"gopls": {
    "buildFlags": ["-tags=linux"]
}

@mtibben
Copy link
Author

mtibben commented Mar 4, 2020

OK thanks

@golang golang locked and limited conversation to collaborators Mar 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants