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: missing diagnostics when rootUri isn't module root #38354

Closed
leitzler opened this issue Apr 10, 2020 · 1 comment
Closed

x/tools/gopls: missing diagnostics when rootUri isn't module root #38354

leitzler opened this issue Apr 10, 2020 · 1 comment
Labels
Milestone

Comments

@leitzler
Copy link
Contributor

@leitzler leitzler commented Apr 10, 2020

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

$ go version
go version go1.14 linux/amd64
$ go list -m golang.org/x/tools golang.org/x/tools/gopls
golang.org/x/tools v0.0.0-20200408132156-9ee5ef7a2c0d
golang.org/x/tools/gopls v0.0.0-20200408132156-9ee5ef7a2c0d

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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/leitzler/.cache/go-build"
GOENV="/home/leitzler/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/leitzler/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build976246565=/tmp/go-build -gno-record-gcc-switches"

What did you do?

With the following structure (note that a.go's last line won't compile):

$ cd $(mktemp -d)
$ txtar -x <<EOF
-- go.mod --
module example.com

go 1.14
-- a/a.go --
package a

const A = 1

asdfgh
-- b/b.go --
package b

import "example.com/a"

const B = a.A
EOF

If I open b/b.go from the module root, so that my workspace rootUri is file:///tmp/tmp.DA6ETbEMa6 gopls sends diagnostics for a.go.
Logfile:

[Trace - 12:56:01.902 PM] Sending request 'initialize - (1)'.
Params: {"processId":0,"clientInfo":{"name":""},"rootUri":"file:///tmp/tmp.DA6ETbEMa6","capabilities":{"Workspace":{"workspaceEdit":{},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"symbolKind":{},"tagSupport":{"valueSet":null}},"executeCommand":{},"configuration":true},"textDocument":{"synchronization":{},"completion":{"completionItem":{"tagSupport":{"valueSet":null}},"completionItemKind":{}},"hover":{"contentFormat":["plaintext"]},"signatureHelp":{"signatureInformation":{"parameterInformation":{}}},"declaration":{},"definition":{},"typeDefinition":{},"implementation":{},"references":{},"documentHighlight":{},"documentSymbol":{"symbolKind":{},"tagSupport":{"valueSet":null}},"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":null}}},"codeLens":{},"documentLink":{},"colorProvider":{},"formatting":{},"rangeFormatting":{},"onTypeFormatting":{},"rename":{},"foldingRange":{},"selectionRange":{},"publishDiagnostics":{"tagSupport":{"valueSet":null}}},"Window":{}},"workspaceFolders":null}


[Trace - 12:56:01.918 PM] Received response 'initialize - (1)' in 16ms.
Result: {"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{"triggerCharacters":["."]},"hoverProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":true,"codeLensProvider":{},"documentLinkProvider":{},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"renameProvider":true,"foldingRangeProvider":true,"executeCommandProvider":{"commands":["tidy","upgrade.dependency","generate"]},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":""}}


[Trace - 12:56:01.919 PM] Sending notification 'initialized'.
Params: {}


[Trace - 12:56:01.919 PM] Received request 'client/registerCapability - (1)'.
Params: {"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"},{"id":"workspace/didChangeWatchedFiles","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/*.go","kind":7}]}}]}


[Trace - 12:56:01.922 PM] Sending response 'client/registerCapability - (1)' took 2ms.
Result: {}


[Trace - 12:56:01.937 PM] Received request 'workspace/configuration - (2)'.
Params: {"items":[{"scopeUri":"file:///tmp/tmp.DA6ETbEMa6","section":"gopls"},{"scopeUri":"file:///tmp/tmp.DA6ETbEMa6","section":"gopls-tmp.DA6ETbEMa6"}]}


[Trace - 12:56:01.937 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/04/10 12:56:01 Build info\n----------\ngolang.org/x/tools/gopls master\n    golang.org/x/tools/gopls@v0.0.0-20200408132156-9ee5ef7a2c0d h1:0FkzqDZzIcnr3qf0Zud/IQJ+X1Yj8mw1ulNaFZh36g8=\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-20200408132156-9ee5ef7a2c0d h1:2DXIdtvIYvvWOcAOsX81FwOUBoQoMZhosWn7KjXEl94=\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 linux/amd64\n\n"}


[Trace - 12:56:01.938 PM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.DA6ETbEMa6/b/b.go","languageId":"go","version":1,"text":"package b\n\nimport \"example.com/a\"\n\nconst B = a.A\n"}}


[Trace - 12:56:01.938 PM] Sending response 'workspace/configuration - (2)' took 0ms.
Result: [{"hoverKind":"FullDocumentation","staticcheck":true,"tempModfile":false},null]


[Trace - 12:56:02.043 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/04/10 12:56:02 go/packages.Load\n\tsnapshot=0\n\tdirectory=/tmp/tmp.DA6ETbEMa6\n\tquery=[./... builtin]\n\tpackages=3"}


[Trace - 12:56:02.076 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/04/10 12:56:02 go env for /tmp/tmp.DA6ETbEMa6\n(valid build configuration = true)\n(build flags: [])\nGO111MODULE=\"\"\nGOARCH=\"amd64\"\nGOBIN=\"\"\nGOCACHE=\"/home/leitzler/.cache/go-build\"\nGOENV=\"/home/leitzler/.config/go/env\"\nGOEXE=\"\"\nGOFLAGS=\"\"\nGOHOSTARCH=\"amd64\"\nGOHOSTOS=\"linux\"\nGOINSECURE=\"\"\nGONOPROXY=\"\"\nGONOSUMDB=\"\"\nGOOS=\"linux\"\nGOPATH=\"/home/leitzler/go\"\nGOPRIVATE=\"\"\nGOPROXY=\"https://proxy.golang.org,direct\"\nGOROOT=\"/usr/local/go\"\nGOSUMDB=\"sum.golang.org\"\nGOTMPDIR=\"\"\nGOTOOLDIR=\"/usr/local/go/pkg/tool/linux_amd64\"\nGCCGO=\"gccgo\"\nAR=\"ar\"\nCC=\"gcc\"\nCXX=\"g++\"\nCGO_ENABLED=\"1\"\nGOMOD=\"/tmp/tmp.DA6ETbEMa6/go.mod\"\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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build808511203=/tmp/go-build -gno-record-gcc-switches\"\n"}


[Trace - 12:56:02.079 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///tmp/tmp.DA6ETbEMa6/a/a.go","diagnostics":[{"range":{"start":{"line":4,"character":0},"end":{"line":4,"character":0}},"severity":1,"source":"syntax","message":"expected declaration, found asdfgh"}]}


[Trace - 12:56:02.084 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///tmp/tmp.DA6ETbEMa6/b/b.go","version":1,"diagnostics":[{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":9}},"severity":2,"source":"ST1000","message":"at least one file in a package should have a package comment"}]}


[Trace - 12:56:16.896 PM] Sending request 'textDocument/definition - (2)'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.DA6ETbEMa6/b/b.go"},"position":{"line":4,"character":12}}


[Trace - 12:56:16.897 PM] Received response 'textDocument/definition - (2)' in 0ms.
Result: [{"uri":"file:///tmp/tmp.DA6ETbEMa6/a/a.go","range":{"start":{"line":2,"character":6},"end":{"line":2,"character":7}}}]


[Trace - 12:56:16.917 PM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.DA6ETbEMa6/a/a.go","languageId":"go","version":1,"text":"package a\n\nconst A = 1\n\nasdfgh\n"}}

But if I open b.go from within package b, so that my workspace rootUri is file:///tmp/tmp.DA6ETbEMa6/b, gopls won't send any diagnostics for a.go.
Logfile:

[Trace - 12:56:58.258 PM] Sending request 'initialize - (1)'.
Params: {"processId":0,"clientInfo":{"name":""},"rootUri":"file:///tmp/tmp.DA6ETbEMa6/b","capabilities":{"Workspace":{"workspaceEdit":{},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"symbolKind":{},"tagSupport":{"valueSet":null}},"executeCommand":{},"configuration":true},"textDocument":{"synchronization":{},"completion":{"completionItem":{"tagSupport":{"valueSet":null}},"completionItemKind":{}},"hover":{"contentFormat":["plaintext"]},"signatureHelp":{"signatureInformation":{"parameterInformation":{}}},"declaration":{},"definition":{},"typeDefinition":{},"implementation":{},"references":{},"documentHighlight":{},"documentSymbol":{"symbolKind":{},"tagSupport":{"valueSet":null}},"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":null}}},"codeLens":{},"documentLink":{},"colorProvider":{},"formatting":{},"rangeFormatting":{},"onTypeFormatting":{},"rename":{},"foldingRange":{},"selectionRange":{},"publishDiagnostics":{"tagSupport":{"valueSet":null}}},"Window":{}},"workspaceFolders":null}

[Trace - 12:56:58.265 PM] Received response 'initialize - (1)' in 7ms.
Result: {"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{"triggerCharacters":["."]},"hoverProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":true,"codeLensProvider":{},"documentLinkProvider":{},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"renameProvider":true,"foldingRangeProvider":true,"executeCommandProvider":{"commands":["tidy","upgrade.dependency","generate"]},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":""}}

[Trace - 12:56:58.267 PM] Sending notification 'initialized'.
Params: {}

[Trace - 12:56:58.267 PM] Received request 'client/registerCapability - (1)'.
Params: {"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"},{"id":"workspace/didChangeWatchedFiles","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/*.go","kind":7}]}}]}

[Trace - 12:56:58.270 PM] Sending response 'client/registerCapability - (1)' took 3ms.
Result: {}

[Trace - 12:56:58.286 PM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.DA6ETbEMa6/b/b.go","languageId":"go","version":1,"text":"package b\n\nimport "example.com/a"\n\nconst B = a.A\n"}}

[Trace - 12:56:58.289 PM] Received request 'workspace/configuration - (2)'.
Params: {"items":[{"scopeUri":"file:///tmp/tmp.DA6ETbEMa6/b","section":"gopls"},{"scopeUri":"file:///tmp/tmp.DA6ETbEMa6/b","section":"gopls-b"}]}

[Trace - 12:56:58.289 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/04/10 12:56:58 Build info\n----------\ngolang.org/x/tools/gopls master\n golang.org/x/tools/gopls@v0.0.0-20200408132156-9ee5ef7a2c0d h1:0FkzqDZzIcnr3qf0Zud/IQJ+X1Yj8mw1ulNaFZh36g8=\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-20200408132156-9ee5ef7a2c0d h1:2DXIdtvIYvvWOcAOsX81FwOUBoQoMZhosWn7KjXEl94=\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 linux/amd64\n\n"}

[Trace - 12:56:58.290 PM] Sending response 'workspace/configuration - (2)' took 0ms.
Result: [{"hoverKind":"FullDocumentation","staticcheck":true,"tempModfile":false},null]

[Trace - 12:56:58.401 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/04/10 12:56:58 go/packages.Load\n\tsnapshot=0\n\tdirectory=/tmp/tmp.DA6ETbEMa6/b\n\tquery=[./... builtin]\n\tpackages=2"}

[Trace - 12:56:58.435 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/04/10 12:56:58 go env for /tmp/tmp.DA6ETbEMa6/b\n(valid build configuration = true)\n(build flags: [])\nGO111MODULE=""\nGOARCH="amd64"\nGOBIN=""\nGOCACHE="/home/leitzler/.cache/go-build"\nGOENV="/home/leitzler/.config/go/env"\nGOEXE=""\nGOFLAGS=""\nGOHOSTARCH="amd64"\nGOHOSTOS="linux"\nGOINSECURE=""\nGONOPROXY=""\nGONOSUMDB=""\nGOOS="linux"\nGOPATH="/home/leitzler/go"\nGOPRIVATE=""\nGOPROXY="https://proxy.golang.org,direct\"\nGOROOT=\"/usr/local/go\"\nGOSUMDB=\"sum.golang.org\"\nGOTMPDIR=\"\"\nGOTOOLDIR=\"/usr/local/go/pkg/tool/linux_amd64\"\nGCCGO=\"gccgo\"\nAR=\"ar\"\nCC=\"gcc\"\nCXX=\"g++\"\nCGO_ENABLED=\"1\"\nGOMOD=\"/tmp/tmp.DA6ETbEMa6/go.mod\"\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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build736301229=/tmp/go-build -gno-record-gcc-switches"\n"}

[Trace - 12:56:58.439 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///tmp/tmp.DA6ETbEMa6/b/b.go","version":1,"diagnostics":[{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":9}},"severity":2,"source":"ST1000","message":"at least one file in a package should have a package comment"}]}

[Trace - 12:57:12.988 PM] Sending request 'textDocument/definition - (2)'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.DA6ETbEMa6/b/b.go"},"position":{"line":4,"character":12}}

[Trace - 12:57:12.989 PM] Received response 'textDocument/definition - (2)' in 0ms.
Result: [{"uri":"file:///tmp/tmp.DA6ETbEMa6/a/a.go","range":{"start":{"line":2,"character":6},"end":{"line":2,"character":7}}}]

[Trace - 12:57:13.010 PM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///tmp/tmp.DA6ETbEMa6/a/a.go","languageId":"go","version":1,"text":"package a\n\nconst A = 1\n\nasdfgh\n"}}

What did you expect to see?

Diagnostics for a/a.go in both cases

What did you see instead?

No diagnostics for a/a.go

@gopherbot gopherbot added this to the Unreleased milestone Apr 10, 2020
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Apr 10, 2020

Right now, gopls sets the workspace scope to the root URI passed in the initialize request. We are aiming to change this in future versions (either gopls/v0.5 or v0.6), so for now, this is behaving as intended. We have a few issues opened for this work already, so I'll close this one. Thanks for reporting, though!

@stamblerre stamblerre closed this Apr 10, 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.