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/cmd/gopls: failed to GoToDefinition for cipher package in vscode using ctrl + left click #32516

Closed
hujianxin opened this issue Jun 10, 2019 · 8 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@hujianxin
Copy link

hujianxin commented Jun 10, 2019

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

$ go version
go version go1.12.5 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/hujianxin/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/hujianxin/go"
GOPROXY=""
GORACE=""
GOROOT="/home/hujianxin/g/go"
GOTMPDIR=""
GOTOOLDIR="/home/hujianxin/g/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/hujianxin/t/godemo/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build100322405=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. mkdir godemo1
  2. cd godemo1
  3. go mod init test
  4. touch main.go
  5. paste the following code into main.go
  6. move the cursor on cipher.Stream , F12(GoToDefinition) works well
  7. close the open file: $GOROOT/src/crypto/cipher/cipher.go, that is nesseary
  8. ctrl+right click on cipher.Stream(), fails to work
  9. F12 also fails to work

What did you expect to see?

jump to definition of Stream method

What did you see instead?

image

@gopherbot gopherbot added this to the Unreleased milestone Jun 10, 2019
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Jun 10, 2019
@stamblerre
Copy link
Contributor

Looking at the documentation for cipher/stream (https://golang.org/pkg/crypto/cipher), it seems like there is no Stream() function defined in that package. Can you check if the same thing happens when you define:

var _ cipher.Stream

@stamblerre stamblerre added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 10, 2019
@cee-dub
Copy link

cee-dub commented Jun 11, 2019

I've been having code completion issues in my project today and found this issue while searching. I can reproduce the issue above, and also a gopls crash. I apologize if this is pile-on; let me know if it would be better to file a separate issue.

I started a new directory outside GOPATH, ran go mod init github.com/cee-dub/gopls-bugs/vscode and typed in

package main

import "crypto/cipher"

func main() {
	var _ cipher.Stream
}

which produces the same series of errors:

[Error - 4:54:50 PM] Request textDocument/hover failed.
  Message: no object for ident Stream
  Code: 0 

Adding parentheses after Stream to make Stream() causes a panic and VSCode restarts the server unsuccessfully 5 times, then gives up.

[Info  - 4:55:24 PM] no signature help for file:///Users/cameron/src/gopls-bugs/vscode/main.go:5:22 : cannot find an enclosing function
[Error - 4:55:24 PM] Request textDocument/codeAction failed.
  Message: /Users/cameron/src/gopls-bugs/vscode/main.go:6:21: expected ';', found '(' (and 1 more errors)
  Code: 0 
panic: parse : empty url

goroutine 22 [running]:
golang.org/x/tools/internal/span.URI.Filename(...)
	/Users/cameron/src/go/src/golang.org/x/tools/internal/span/uri.go:27
golang.org/x/tools/internal/span.CompareURI(0xc0000ee680, 0x33, 0x0, 0x0, 0x0)
	/Users/cameron/src/go/src/golang.org/x/tools/internal/span/uri.go:64 +0x2f6
golang.org/x/tools/internal/lsp/protocol.(*ColumnMapper).Range(0xc0007ab2c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/cameron/src/go/src/golang.org/x/tools/internal/lsp/protocol/span.go:49 +0xaa
golang.org/x/tools/internal/lsp.toProtocolDocumentSymbols(0xc0007ab2c0, 0xc001965a40, 0x1, 0x1, 0xc001965a40, 0x1, 0x1)
	/Users/cameron/src/go/src/golang.org/x/tools/internal/lsp/symbols.go:35 +0x260
golang.org/x/tools/internal/lsp.(*Server).documentSymbol(0xc000100f00, 0x175af60, 0xc0007ab230, 0xc000cb33c0, 0xc000cb33c0, 0x0, 0x0, 0x0, 0xc001492a00)
	/Users/cameron/src/go/src/golang.org/x/tools/internal/lsp/symbols.go:23 +0x164
golang.org/x/tools/internal/lsp.(*Server).DocumentSymbol(0xc000100f00, 0x175af60, 0xc0007ab230, 0xc000cb33c0, 0xc000cb33c0, 0x0, 0x0, 0xc0005ecf80, 0x0)
	/Users/cameron/src/go/src/golang.org/x/tools/internal/lsp/server.go:199 +0x4d
golang.org/x/tools/internal/lsp/protocol.serverHandler.func1(0x175af60, 0xc0007ab230, 0xc00017a3f0, 0xc0005ed440)
	/Users/cameron/src/go/src/golang.org/x/tools/internal/lsp/protocol/tsserver.go:335 +0x53bc
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc0000b3d40, 0xc00017a3f0)
	/Users/cameron/src/go/src/golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:288 +0x189
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
	/Users/cameron/src/go/src/golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:278 +0xba
[Info  - 4:55:24 PM] Connection to server got closed. Server will restart.
[Error - 4:55:24 PM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
	at Object.dispose (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-languageclient/lib/client.js:57:35)
	at LanguageClient.handleConnectionClosed (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-languageclient/lib/client.js:2036:42)
	at LanguageClient.handleConnectionClosed (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-languageclient/lib/main.js:127:15)
	at closeHandler (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-languageclient/lib/client.js:2023:18)
	at CallbackList.invoke (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageReader.fireClose (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-jsonrpc/lib/messageReader.js:111:27)
	at Socket.listen.readable.on (/Users/cameron/.vscode/extensions/ms-vscode.go-0.10.2/node_modules/vscode-jsonrpc/lib/messageReader.js:151:46)
	at Socket.emit (events.js:187:15)
	at Pipe.Socket._destroy._handle.close [as _onclose] (net.js:596:12)
[Info  - 4:55:24 PM] Build info
----------
no module information, gopls not built in module mode

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/cameron/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/cameron/src/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.5/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/cameron/src/gopls-bugs/vscode/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/r3/kh_tqb1j47ldzdbqfrtts6q40000gn/T/go-build674408149=/tmp/go-build -gno-record-gcc-switches -fno-common"

The only non-default setting for the above is "go.useLanguageServer": true from the .vscode/settings.json file.

Screen Shot 2019-06-10 at 16 59 27

@hujianxin
Copy link
Author

I have tried var _ cipher.Stream, same issue, thanks

@hujianxin
Copy link
Author

@stamblerre

@gopherbot
Copy link

Change https://golang.org/cl/181578 mentions this issue: internal/lsp: fix check for changed imports

gopherbot pushed a commit to golang/tools that referenced this issue Jun 11, 2019
We weren't comparing the right values when checking to see if a file's
import statements had changed. This was causing us to not refetch a
package's metadata when needed in certain cases. In particular, if you
typed out an import path by hand you would get stuck with "no metadata
for package" until you added or deleted another import line to trigger
metadata refresh.

Updates golang/go#32516, golang/go#32232

Change-Id: I1c99e9ee56d18f02c44c749d33679aa4e561c620
GitHub-Last-Rev: 20d46b3
GitHub-Pull-Request: #112
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181578
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
@muirdm
Copy link

muirdm commented Jun 11, 2019

@hujianxin @cee-dub can you rebuild gopls off master and see if the error is fixed?

@cee-dub
Copy link

cee-dub commented Jun 11, 2019

The change in https://golang.org/cl/181578 has drastically increased stability of gopls for me. Thank you!

@hujianxin
Copy link
Author

@muirrn I upgraded gopls to the latest version, and checked, this issue has gone away, thanks

@golang golang locked and limited conversation to collaborators Jun 11, 2020
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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants