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: cannot working lsp definition #39884

Closed
skanehira opened this issue Jun 26, 2020 · 9 comments
Closed

x/tools/gopls: cannot working lsp definition #39884

skanehira opened this issue Jun 26, 2020 · 9 comments

Comments

@skanehira
Copy link
Contributor

@skanehira skanehira commented Jun 26, 2020

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

$ go version
go version go1.14.4 darwin/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
GO111MODULE="auto"
GOARCH="amd64"
GOBIN="/Users/skanehira/dev/go/bin"
GOCACHE="/Users/skanehira/Library/Caches/go-build"
GOENV="/Users/skanehira/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/skanehira/dev/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
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/pb/r7kfzkbj3k18bkmd_ntd6c4w0000gn/T/go-build574856938=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. using vim-lsp and gopls to jump some imported package functions with :LspDefinition
  2. vim-lsp has error that No definition found

main.go is below. I can't found xorm package when I use gopls.

package main

import (
	"xorm.io/xorm"
)

func main() {
	xorm.NewEngine("", "")
}

My project layout is below.

$ tree $GOPATH/src/github.com/skanehira/sample
/Users/skanehira/dev/go/src/github.com/skanehira/sample
└── api
    ├── cmd
    │   └── main.go
    └── go.mod

2 directories, 2 files

xorm already has downloaded.

$ ll $GOPATH/pkg/mod/xorm.io/
total 0
drwxr-xr-x   5 skanehira  staff   160B Jun 23 19:47 ./
drwxr-xr-x  12 skanehira  staff   384B Jun 27 06:42 ../
dr-x------  47 skanehira  staff   1.5K Apr 21 16:55 builder@v0.3.7/
dr-x------  77 skanehira  staff   2.4K Apr 21 16:55 xorm@v1.0.1/
dr-x------  51 skanehira  staff   1.6K Jun 23 19:47 xorm@v1.0.2/

When I run editor and executing :LspDefinition, vim-lsp output below logs.

log vim-lsp
```
Sat Jun 27 07:36:16 2020:["<---",1,{"method":"workspace/configuration","jsonrpc":"2.0","id":1,"params":{"items":[{"section":"gopls","scopeUri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample"},{"section":"gopls-sample","scopeUri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample"}]}}]
Sat Jun 27 07:36:16 2020:["--->",1,"gopls",{"id":1,"result":[null,null]}]
Sat Jun 27 07:36:16 2020:["<---",1,"gopls",{"response":{"method":"window/logMessage","jsonrpc":"2.0","params":{"message":"2020/06/27 07:36:16 Build info\n----------\ngolang.org/x/tools/gopls 0.4.1\n    golang.org/x/tools/gopls@v0.4.1 h1:0e3BPxGV4B3cd0zdMuccwW72SgmHp92lAjOyxX/ScAw=\n    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\n    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=\n    golang.org/x/sync@v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=\n    golang.org/x/tools@v0.0.0-20200513154647-78b527d18275 h1:e7nYe9s94RHunFJ7b+mmPxiQMOKMVSqYASToWb1EcHs=\n    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=\n    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=\n    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=\n\nGo info\n-------\ngo version go1.14.4 darwin/amd64\n\n\n","type":3}}}]
Sat Jun 27 07:36:16 2020:["<---",1,"gopls",{"response":{"method":"window/logMessage","jsonrpc":"2.0","params":{"message":"2020/06/27 07:36:16 go/packages.Load\n\tsnapshot=0\n\tdirectory=/Users/skanehira/dev/go/src/github.com/skanehira/sample\n\tquery=[./... builtin]\n\tpackages=2\n","type":3}}}]
Sat Jun 27 07:36:16 2020:["<---",1,"gopls",{"response":{"method":"window/logMessage","jsonrpc":"2.0","params":{"message":"2020/06/27 07:36:16 no dep handle: no metadata for xorm.io/xorm\n\tpackage=\"xorm.io/xorm\"\n","type":1}}}]
Sat Jun 27 07:36:16 2020:["<---",1,"gopls",{"response":{"method":"window/logMessage","jsonrpc":"2.0","params":{"message":"2020/06/27 07:36:16 go env for /Users/skanehira/dev/go/src/github.com/skanehira/sample\n(valid build configuration = true)\n(build flags: [])\nGO111MODULE=\"auto\"\nGOARCH=\"amd64\"\nGOBIN=\"/Users/skanehira/dev/go/bin\"\nGOCACHE=\"/Users/skanehira/Library/Caches/go-build\"\nGOENV=\"/Users/skanehira/Library/Application Support/go/env\"\nGOEXE=\"\"\nGOFLAGS=\"\"\nGOHOSTARCH=\"amd64\"\nGOHOSTOS=\"darwin\"\nGOINSECURE=\"\"\nGONOPROXY=\"\"\nGONOSUMDB=\"\"\nGOOS=\"darwin\"\nGOPATH=\"/Users/skanehira/dev/go\"\nGOPRIVATE=\"\"\nGOPROXY=\"https://proxy.golang.org,direct\"\nGOROOT=\"/usr/local/Cellar/go/1.14.4/libexec\"\nGOSUMDB=\"sum.golang.org\"\nGOTMPDIR=\"\"\nGOTOOLDIR=\"/usr/local/Cellar/go/1.14.4/libexec/pkg/tool/darwin_amd64\"\nGCCGO=\"gccgo\"\nAR=\"ar\"\nCC=\"clang\"\nCXX=\"clang++\"\nCGO_ENABLED=\"1\"\nGOMOD=\"\"\nCGO_CFLAGS=\"-g -O2\"\nCGO_CPPFLAGS=\"\"\nCGO_CXXFLAGS=\"-g -O2\"\nCGO_FFLAGS=\"-g -O2\"\nCGO_LDFLAGS=\"-g -O2\"\nPKG_CONFIG=\"pkg-config\"\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/pb/r7kfzkbj3k18bkmd_ntd6c4w0000gn/T/go-build233912473=/tmp/go-build -gno-record-gcc-switches -fno-common\"\n\n","type":3}}}]
Sat Jun 27 07:36:16 2020:["<---",1,{"method":"workspace/configuration","jsonrpc":"2.0","id":2,"params":{"items":[{"section":"gopls","scopeUri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample"},{"section":"gopls-sample","scopeUri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample"}]}}]
Sat Jun 27 07:36:16 2020:["--->",1,"gopls",{"id":2,"result":[null,null]}]
Sat Jun 27 07:36:16 2020:["<---",1,"gopls",{"response":{"method":"textDocument/publishDiagnostics","jsonrpc":"2.0","params":{"uri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample/api/cmd/main.go","diagnostics":[{"source":"compiler","range":{"end":{"character":15,"line":3},"start":{"character":1,"line":3}},"message":"could not import xorm.io/xorm (no package for import xorm.io/xorm)","severity":1}]}}}]
Sat Jun 27 07:36:16 2020:["add signs",1]
Sat Jun 27 07:36:16 2020:["<---",1,{"method":"workspace/configuration","jsonrpc":"2.0","id":3,"params":{"items":[{"section":"gopls","scopeUri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample"},{"section":"gopls-sample","scopeUri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample"}]}}]
Sat Jun 27 07:36:16 2020:["--->",1,"gopls",{"id":3,"result":[null,null]}]
Sat Jun 27 07:36:16 2020:["<---",1,"gopls",{"response":{"method":"window/logMessage","jsonrpc":"2.0","params":{"message":"2020/06/27 07:36:16 no dep handle: no metadata for xorm.io/xorm\n\tpackage=\"xorm.io/xorm\"\n","type":1}}}]
Sat Jun 27 07:36:16 2020:["<---",1,"gopls",{"response":{"id":2,"jsonrpc":"2.0","result":[{"startLine":2,"endCharacter":15,"kind":"imports","startCharacter":8,"endLine":3},{"startLine":6,"endCharacter":23,"startCharacter":13,"endLine":7}]},"request":{"id":2,"jsonrpc":"2.0","method":"textDocument/foldingRange","params":{"textDocument":{"uri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample/api/cmd/main.go"}}}}]
Sat Jun 27 07:36:19 2020:[{"response":{"data":{"__data__":"vim-lsp","server_name":"gopls"},"message":"server already started"}}]
Sat Jun 27 07:36:19 2020:[{"response":{"data":{"__data__":"vim-lsp","init_result":{"id":1,"jsonrpc":"2.0","result":{"capabilities":{"executeCommandProvider":{"commands":["tidy","upgrade.dependency","generate"]},"documentHighlightProvider":true,"hoverProvider":true,"typeDefinitionProvider":true,"definitionProvider":true,"referencesProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"foldingRangeProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","source.fixAll","source.organizeImports"]},"textDocumentSync":{"save":{},"change":2,"openClose":true},"codeLensProvider":{},"workspace":{"workspaceFolders":{"changeNotifications":"workspace/didChangeWorkspaceFolders","supported":true}},"documentLinkProvider":{},"implementationProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"documentSymbolProvider":true,"renameProvider":true,"completionProvider":{"triggerCharacters":["."]}},"serverInfo":{"version":"Build info\n----------\ngolang.org/x/tools/gopls 0.4.1\n    golang.org/x/tools/gopls@v0.4.1 h1:0e3BPxGV4B3cd0zdMuccwW72SgmHp92lAjOyxX/ScAw=\n    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\n    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=\n    golang.org/x/sync@v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=\n    golang.org/x/tools@v0.0.0-20200513154647-78b527d18275 h1:e7nYe9s94RHunFJ7b+mmPxiQMOKMVSqYASToWb1EcHs=\n    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=\n    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=\n    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=\n\nGo info\n-------\ngo version go1.14.4 darwin/amd64\n\n","name":"gopls"}}},"server_name":"gopls"},"message":"lsp server already initialized"}}]
Sat Jun 27 07:36:19 2020:["--->",1,"gopls",{"method":"workspace/didChangeConfiguration","params":{"settings":{}}}]
Sat Jun 27 07:36:19 2020:[{"response":{"data":{"__data__":"vim-lsp","server_name":"gopls"},"message":"configuration sent"}}]
Sat Jun 27 07:36:19 2020:[{"response":{"data":{"path":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample/api/cmd/main.go","__data__":"vim-lsp","server_name":"gopls"},"message":"already opened"}}]
Sat Jun 27 07:36:19 2020:[{"response":{"data":{"path":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample/api/cmd/main.go","__data__":"vim-lsp","server_name":"gopls"},"message":"not dirty"}}]
Sat Jun 27 07:36:19 2020:["--->",1,"gopls",{"method":"textDocument/definition","on_notification":"---funcref---","params":{"textDocument":{"uri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample/api/cmd/main.go"},"position":{"character":6,"line":7}}}]
Sat Jun 27 07:36:19 2020:["<---",1,{"method":"workspace/configuration","jsonrpc":"2.0","id":4,"params":{"items":[{"section":"gopls","scopeUri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample"},{"section":"gopls-sample","scopeUri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample"}]}}]
Sat Jun 27 07:36:19 2020:["--->",1,"gopls",{"id":4,"result":[null,null]}]
Sat Jun 27 07:36:19 2020:["<---",1,"gopls",{"response":{"id":3,"jsonrpc":"2.0","result":null,"error":{"data":null,"code":0,"message":"no object for ident NewEngine"}},"request":{"id":3,"jsonrpc":"2.0","method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/skanehira/dev/go/src/github.com/skanehira/sample/api/cmd/main.go"},"position":{"character":6,"line":7}}}}]
```

What did you expect to see?

Can jump some definitoins.

What did you see instead?

Cannot jump some definitions.

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 26, 2020

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.

@gopherbot gopherbot added this to the Unreleased milestone Jun 26, 2020
@skanehira skanehira changed the title x/tools/gopls: cannot working lspdefinitioncccccckvldfbjgkcevuhhjgvcklcuuhbhrihiengejfj x/tools/gopls: cannot working lsp definition Jun 26, 2020
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jun 26, 2020

Can you please share the information requested in the issue template, as well as in the Troubleshooting guide linked above?

@skanehira
Copy link
Contributor Author

@skanehira skanehira commented Jun 26, 2020

@stamblerre Sorry, I posted before I wrote the information

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jun 26, 2020

No worries. I think you need to open your workspace at the /Users/skanehira/dev/go/src/github.com/skanehira/sample/api directory, as it is your module root. This is a current limitation of gopls that we are working on addressing.

@skanehira
Copy link
Contributor Author

@skanehira skanehira commented Jun 26, 2020

@stamblerre Thank you :)
Can you tell me how I change workspace ?

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jun 26, 2020

I'm sorry, but I'm not familiar with vim-lsp - I would suggest asking that question in the vim-lsp repository or in the #vim channel of the Gophers Slack.

@skanehira
Copy link
Contributor Author

@skanehira skanehira commented Jun 26, 2020

@stamblerre I misunderstood that change workspace is gopls's features
Thank you :)

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jun 26, 2020

Ah I see. Yeah my guess is that changing your workspace should be as simple as opening Vim with a different directory, but I know some editors have commands to change workspaces.

@skanehira
Copy link
Contributor Author

@skanehira skanehira commented Jun 27, 2020

@stamblerre
This is looks like vim-lsp's bug.
I'll close this issue.

Thank you for helping me :)

@skanehira skanehira closed this Jun 27, 2020
@stamblerre stamblerre modified the milestones: gopls/v0.5.0, gopls/v0.4.4 Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.