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: "Request textDocument/definition failed" when working on a module whose upper directory contains no Go code #31492

Closed
kidlj opened this issue Apr 16, 2019 · 3 comments

Comments

@kidlj
Copy link

kidlj commented Apr 16, 2019

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

$ go version
go version go1.12 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mellon/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mellon/go"
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/01/v02g0nk97_98qt_4_dsq07hw0000gn/T/go-build847911855=/tmp/go-build -gno-record-gcc-switches -fno-common

What did you do?

Open demo code: https://github.com/kidlj/pki-example in vscode with the latest 0.9.3-beta.7 vscode-go extension and gopls language server on.

There's is a module inside the repository, which is github.com/kidlj/pki-example/demo.

When open the module directory with vscode, which is demo, it works fine.

$ code ~/Code/pki-example/demo

Instead if I open the upper directory, which is pki-example, gopls fails everything.

$ code ~/Code/pki-example

In the second case, gopls logs:

[Error - 2:08:41 AM] Request textDocument/codeAction failed.
  Message: no file information for file:///Users/mellon/Code/pki-example/demo/main.go
  Code: 0 

WX20190417-014312@2x

What did you expect to see?

gopls works with vscode.

What did you see instead?

vscode 'Go To Definition' fails.

@gopherbot gopherbot added this to the Unreleased milestone Apr 16, 2019
@ianthehat
Copy link

This is working as intended, you need to add any module directories you are using by hand as workspace directories in your vscode project. Until you do, the module is not visible to gopls, even if the files are, and thus it cannot analyze any of the code.
This is not something that gopls can fix, but it is possible in the future that the vscode go extension could either add the directories for you.

@divmgl
Copy link

divmgl commented Apr 30, 2019

@ianthehat do you mean adding directories using Go modules under the "folders" property in the workspace settings JSON file? Because I did this and it's still not working for me.

[Error - 3:16:57 PM] Request textDocument/hover failed.
  Message: no file information for file:///Users/dextermiguel/Documents/dev/ss/k2/cmd/lambda/survey-ingest-legacy/survey-ingest-legacy.go
  Code: 0 
{
  "folders": [
    {
      "path": "."
    },
    {
      "path": "/Users/dextermiguel/Documents/dev/ss/k2/cmd/lambda/survey-ingest-legacy"
    }
  ],

@ianthehat
Copy link

yes, but note that once you add them you currently need to reload the window as we do not track the update messages

@golang golang locked and limited conversation to collaborators Apr 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants