Closed
Description
What version of Go are you using (go version
)?
$ go version go version devel go1.19-4d2da99 Sun Mar 20 03:01:15 2022 +0000 darwin/arm64 $ go list -m golang.org/x/tools golang.org/x/tools/gopls golang.org/x/tools v0.1.10-0.20220314210125-40370f8a2a08 golang.org/x/tools/gopls v0.0.0-20220314210125-40370f8a2a08
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 N/A
What did you do?
On macOS (where the temp directory is a symlink):
cd $(mktemp -d) && txtar-x <<<'
-- go.work --
go 1.19
use ./mymod
-- mymod/go.mod --
module mymod
go 1.19
-- mymod/main.go --
package main
import "runtime"
'
Open main.go
using -remote=auto
so that a new server is spawned.
What did you expect to see?
The diagnostic message referring to a resolved path (i.e. not symlinked directory).
What did you see instead?
Diagnostics (and code edits) reported by gopls are using the unresolved path, despite the LSP client sending resolved paths to gopls (see gopls.log below) e.g.:
PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{
URI: "file:///var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi/mymod/main.go",
Version: 0,
Diagnostics: {
{
Range: protocol.Range{
Start: protocol.Position{Line:0x2, Character:0x7},
End: protocol.Position{Line:0x2, Character:0x10},
},
Severity: 1,
Code: "UnusedImport",
CodeDescription: &protocol.CodeDescription{Href:"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source=gopls#UnusedImport"},
Source: "compiler",
Message: "\"runtime\" imported but not used",
Tags: nil,
RelatedInformation: nil,
Data: nil,
},
},
}
The root casue seems to be #51823. As the Forwarder intercepts the initialize
message and adds the local env (i.e. sets GOWORK
env in session options), all package loading afterwards will get unresolved paths.
gopls log
[Trace - 09:56:30.335 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/03/20 09:56:30 Handshake session update\n\tupdate_session=1\n\tdebug_address=\"127.0.0.1:52834\"\n\tlogfile=\"/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/buggopls.log\"\n\tserver=\"1\"\n\tgopls_path=\"/Users/leitzler/proj/govim/cmd_govim_gowork/cmd/govim/.bin/c9c08f4ed2e78446a9444e45a6727b07a7c1188cbaac9932ecbc1e9c77793b88/gopls\"\n"}
[Trace - 09:56:30.336 AM] Sending request 'initialize - (1)'.
Params: {"processId":0,"clientInfo":{"name":""},"rootUri":"","capabilities":{"workspace":{"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"executeCommand":{},"semanticTokens":{},"codeLens":{},"inlineValues":{},"configuration":true},"textDocument":{"synchronization":{},"completion":{"completionItem":{"tagSupport":{"valueSet":null},"resolveSupport":{"properties":null},"insertTextModeSupport":{"valueSet":null}},"completionItemKind":{},"completionList":{}},"hover":{"contentFormat":["plaintext"]},"signatureHelp":{"signatureInformation":{"parameterInformation":{}}},"declaration":{},"definition":{},"typeDefinition":{},"implementation":{},"references":{},"documentHighlight":{},"documentSymbol":{"symbolKind":{},"tagSupport":{"valueSet":null}},"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":null}},"resolveSupport":{"properties":null}},"codeLens":{},"documentLink":{},"colorProvider":{},"formatting":{},"rangeFormatting":{},"onTypeFormatting":{},"rename":{},"foldingRange":{},"selectionRange":{},"publishDiagnostics":{"tagSupport":{"valueSet":null}},"callHierarchy":{},"semanticTokens":{"requests":{},"tokenTypes":null,"tokenModifiers":null,"formats":null},"linkedEditingRange":{},"moniker":{},"typeHierarchy":{},"inlineValues":{}},"window":{"workDoneProgress":true,"showMessage":{"messageActionItem":{}},"showDocument":{"support":false}},"general":{"staleRequestSupport":{"cancel":false,"retryOnContentModified":null},"regularExpressions":{"engine":""},"markdown":{"parser":""}}},"initializationOptions":{"symbolMatcher":"fuzzy","symbolStyle":"full"},"workspaceFolders":[{"uri":"file:///private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi","name":""}]}
[Trace - 09:56:30.435 AM] Received response 'initialize - (1)' in 99ms.
Result: {"capabilities":{"textDocumentSync":{"change":2,"openClose":true,"save":{}},"completionProvider":{"triggerCharacters":["."],"completionItem":{}},"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":["gopls.add_dependency","gopls.add_import","gopls.apply_fix","gopls.check_upgrades","gopls.edit_go_directive","gopls.gc_details","gopls.generate","gopls.generate_gopls_mod","gopls.go_get_package","gopls.list_imports","gopls.list_known_packages","gopls.regenerate_cgo","gopls.remove_dependency","gopls.run_tests","gopls.start_debugging","gopls.test","gopls.tidy","gopls.toggle_gc_details","gopls.update_go_sum","gopls.upgrade_dependency","gopls.vendor"]},"callHierarchyProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":"gopls","version":"{\"GoVersion\":\"go1.18\",\"Path\":\"golang.org/x/tools/gopls\",\"Main\":{\"Path\":\"golang.org/x/tools/gopls\",\"Version\":\"v0.0.0-20220304203747-e155b03a0ecc\",\"Sum\":\"h1:S9R+t8Uq8+LEwc7fg3dRnuxIMh8bs+aKCZQpi3H11JY=\",\"Replace\":null},\"Deps\":[{\"Path\":\"github.com/BurntSushi/toml\",\"Version\":\"v1.0.0\",\"Sum\":\"h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=\",\"Replace\":null},{\"Path\":\"github.com/google/go-cmp\",\"Version\":\"v0.5.7\",\"Sum\":\"h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=\",\"Replace\":null},{\"Path\":\"github.com/sergi/go-diff\",\"Version\":\"v1.1.0\",\"Sum\":\"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\",\"Replace\":null},{\"Path\":\"golang.org/x/mod\",\"Version\":\"v0.6.0-dev.0.20220106191415-9b9b3d81d5e3\",\"Sum\":\"h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=\",\"Replace\":null},{\"Path\":\"golang.org/x/sync\",\"Version\":\"v0.0.0-20210220032951-036812b2e83c\",\"Sum\":\"h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=\",\"Replace\":null},{\"Path\":\"golang.org/x/sys\",\"Version\":\"v0.0.0-20220209214540-3681064d5158\",\"Sum\":\"h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=\",\"Replace\":null},{\"Path\":\"golang.org/x/text\",\"Version\":\"v0.3.7\",\"Sum\":\"h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=\",\"Replace\":null},{\"Path\":\"golang.org/x/tools\",\"Version\":\"v0.1.10-0.20220304203747-e155b03a0ecc\",\"Sum\":\"h1:+QG/aaACI5HAfdmCJgeK3d5/hVJM1+ao5Smtf0A/8fo=\",\"Replace\":null},{\"Path\":\"golang.org/x/xerrors\",\"Version\":\"v0.0.0-20200804184101-5ec99f83aff1\",\"Sum\":\"h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\",\"Replace\":null},{\"Path\":\"honnef.co/go/tools\",\"Version\":\"v0.3.0-0.dev.0.20220120121056-246e50be7597\",\"Sum\":\"h1:YYX8xj3UjOv5K17GjaNsJXycbFalZnPV1JhVTIXt/b4=\",\"Replace\":null},{\"Path\":\"mvdan.cc/gofumpt\",\"Version\":\"v0.3.0\",\"Sum\":\"h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=\",\"Replace\":null},{\"Path\":\"mvdan.cc/xurls/v2\",\"Version\":\"v2.4.0\",\"Sum\":\"h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=\",\"Replace\":null}],\"Settings\":[{\"Key\":\"-compiler\",\"Value\":\"gc\"},{\"Key\":\"CGO_ENABLED\",\"Value\":\"1\"},{\"Key\":\"CGO_CFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_CPPFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_CXXFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_LDFLAGS\",\"Value\":\"\"},{\"Key\":\"GOARCH\",\"Value\":\"arm64\"},{\"Key\":\"GOOS\",\"Value\":\"darwin\"}],\"Version\":\"master\"}"}}
[Trace - 09:56:30.436 AM] Sending notification 'initialized'.
Params: {}
[Trace - 09:56:30.437 AM] Received request 'window/workDoneProgress/create - (1)'.
Params: {"token":"5577006791947779410"}
[Trace - 09:56:30.437 AM] Sending response 'window/workDoneProgress/create - (1)' in 0ms.
Result:
[Trace - 09:56:30.437 AM] Received notification '$/progress'.
Params: {"token":"5577006791947779410","value":{"kind":"begin","message":"Loading packages...","title":"Setting up workspace"}}
[Trace - 09:56:30.437 AM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi/mymod/main.go","languageId":"go","version":1,"text":"package main\n\nimport \"runtime\"\n"}}
[Trace - 09:56:30.437 AM] Received request 'workspace/configuration - (2)'.
Params: {"items":[{"scopeUri":"file:///private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi","section":"gopls"}]}
[Trace - 09:56:30.438 AM] Sending response 'workspace/configuration - (2)' in 0ms.
Result: [{"analyses":{"fieldalignment":true,"unusedparam":true},"codelenses":{"gc_details":true},"experimentalWorkspaceModule":true,"gofumpt":true,"hoverKind":"FullDocumentation","staticcheck":true,"tempModfile":true}]
[Trace - 09:56:30.457 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/03/20 09:56:30 go env for /private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi\n(root /private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi)\n(go version go version go1.18 darwin/arm64)\n(valid build configuration = true)\n(build flags: [])\nGOINSECURE=\nGONOSUMDB=\nGOMODCACHE=/Users/leitzler/go/pkg/mod\nGOPATH=/Users/leitzler/go\nGOMOD=/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi/mymod/go.mod\nGOCACHE=/Users/leitzler/Library/Caches/go-build\nGOSUMDB=sum.golang.org\nGOFLAGS=\nGOPRIVATE=\nGOPROXY=https://proxy.golang.org,direct\nGO111MODULE=\nGOROOT=/usr/local/go\nGONOPROXY=\nGOWORK=/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi/go.work\n\n"}
[Trace - 09:56:30.509 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/03/20 09:56:30 go/packages.Load\n\tsnapshot=0\n\tdirectory=/private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi\n\tquery=[builtin mymod/...]\n\tpackages=2\n"}
[Trace - 09:56:30.516 AM] Received notification '$/progress'.
Params: {"token":"5577006791947779410","value":{"kind":"end","message":"Finished loading packages."}}
[Trace - 09:56:30.517 AM] Received request 'client/registerCapability - (3)'.
Params: {"registrations":[{"id":"workspace/didChangeWatchedFiles-0","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"{/private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi/mymod}","kind":7},{"globPattern":"**/*.{go,mod,sum,work}","kind":7}]}}]}
[Trace - 09:56:30.517 AM] Sending response 'client/registerCapability - (3)' in 0ms.
Result:
[Trace - 09:56:30.518 AM] Received request 'client/registerCapability - (4)'.
Params: {"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"}]}
[Trace - 09:56:30.518 AM] Sending response 'client/registerCapability - (4)' in 0ms.
Result:
[Trace - 09:56:30.523 AM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2022/03/20 09:56:30 tidy: diagnosing file:///private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi/mymod/go.mod: err: exit status 1: stderr: go: go.mod file indicates go 1.19, but maximum version supported by tidy is 1.18\n\n"}
[Trace - 09:56:30.575 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/03/20 09:56:30 go/packages.Load\n\tsnapshot=1\n\tdirectory=/private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi\n\tquery=[file=/private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi/mymod/main.go]\n\tpackages=1\n"}
[Trace - 09:56:30.575 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/03/20 09:56:30 go/packages.Load\n\tsnapshot=1\n\tpackage=\"command-line-arguments\"\n\tfiles=[/private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi/mymod/main.go]\n"}
[Trace - 09:56:30.622 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/03/20 09:56:30 discovered missing identifiers: map[memRecordCycle:true pageBits:true]\n\tpackage=\"runtime\"\n"}
[Trace - 09:56:30.662 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi/mymod/main.go","diagnostics":[{"range":{"start":{"line":2,"character":7},"end":{"line":2,"character":16}},"severity":1,"code":"UnusedImport","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source=gopls#UnusedImport"},"source":"compiler","message":"\"runtime\" imported but not used"}]}
[Trace - 09:56:30.933 AM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2022/03/20 09:56:30 tidy: diagnosing file:///private/var/folders/cz/31br911566l_bbx72cs_pgs40000gn/T/tmp.ShVfEZhi/mymod/go.mod: err: exit status 1: stderr: go: go.mod file indicates go 1.19, but maximum version supported by tidy is 1.18\n\n"}
[Trace - 09:56:38.099 AM] Sending request 'shutdown - (2)'.
Params:
[Trace - 09:56:38.100 AM] Received response 'shutdown - (2)' in 0ms.
Result: null
[Trace - 09:56:38.100 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/03/20 09:56:38 Shutdown session\n\tshutdown_session=1\n"}