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: package import error but indeed program runs normally #42873

Closed
fourdim opened this issue Nov 29, 2020 · 6 comments
Closed

x/tools/gopls: package import error but indeed program runs normally #42873

fourdim opened this issue Nov 29, 2020 · 6 comments

Comments

@fourdim
Copy link

@fourdim fourdim commented Nov 29, 2020

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

$ go version
go version go1.15.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
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/username/.cache/go-build"
GOENV="/home/username/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/username/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/username/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io,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="/home/username/workspace/projects/http2socks5/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-build039276181=/tmp/go-build -gno-record-gcc-switches"


Besides, I use the vscode remote-ssh extension.

What did you do?

I just import a package golang.org/x/net/proxy.

What did you expect to see?

The program runs properly without any notifcation.

What did you see instead?

The program is running properly.
However, the extension go nightly tells me that the complier noticed that I have a package loading error.
It does not influence the program's performence, but the notifcation is kind of annoying.
Snipaste_2020-11-29_22-12-56

@bcmills
Copy link
Member

@bcmills bcmills commented Nov 30, 2020

@hyangah hyangah changed the title Package import error but indeed program runs normally x/tools/gopls: package import error but indeed program runs normally Nov 30, 2020
@gopherbot gopherbot added this to the Unreleased milestone Nov 30, 2020
@hyangah
Copy link
Contributor

@hyangah hyangah commented Nov 30, 2020

@fourdim thanks for the report - can you please capture the gopls log following the instruction here? https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#capturing-logs
We need the trace from the beginning.

@stamblerre this error message is strange - it reports that there is no main module, but according to the go env output, there IS a go.mod file in the same directory as main.go.

@fourdim
Copy link
Author

@fourdim fourdim commented Dec 1, 2020

gopls server Output
[Trace - 14:27:17.255 PM] Sending request 'initialize - (0)'.
Params: {"processId":31580,"clientInfo":{"name":"vscode","version":"1.51.1"},"rootPath":"/home/username","rootUri":"file:///home/username","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport":{"valueSet":[1]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true,"semanticTokens":{"refreshSupport":true}},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]},"codeDescriptionSupport":true,"dataSupport":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[1]},"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]}},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true},"activeParameterSupport":true},"contextSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true,"tagSupport":{"valueSet":[1]},"labelSupport":true},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"disabledSupport":true,"dataSupport":true,"resolveSupport":{"properties":["edit"]},"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true,"prepareSupportDefaultBehavior":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true},"selectionRange":{"dynamicRegistration":true},"callHierarchy":{"dynamicRegistration":true},"semanticTokens":{"dynamicRegistration":true,"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","member","macro","keyword","modifier","comment","string","number","regexp","operator"],"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"],"formats":["relative"],"requests":{"range":true,"full":{"delta":true}}}},"window":{"workDoneProgress":true}},"initializationOptions":{"allExperiments":true},"trace":"off","workspaceFolders":[{"uri":"file:///home/username","name":"username"}]}

[Trace - 14:27:17.256 PM] Received response 'initialize - (0)' in 1ms.
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":{"codeActionKinds":["quickfix","refactor.extract","refactor.rewrite","source.fixAll","source.organizeImports"]},"codeLensProvider":{},"documentLinkProvider":{},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"renameProvider":{"prepareProvider":true},"foldingRangeProvider":true,"executeCommandProvider":{"commands":["gopls.generate","gopls.fill_struct","gopls.regenerate_cgo","gopls.test","gopls.tidy","gopls.undeclared_name","gopls.add_dependency","gopls.upgrade_dependency","gopls.remove_dependency","gopls.vendor","gopls.extract_variable","gopls.extract_function","gopls.gc_details","gopls.generate_gopls_mod"]},"callHierarchyProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":"gopls","version":"{"path":"golang.org/x/tools/gopls","version":"v0.5.4-pre.1","sum":"h1:ac/2M/1ezJQ9o/F52BHM8yHYOU/W5wKFWeb3rXt5/JA=","deps":[{"path":"github.com/BurntSushi/toml","version":"v0.3.1","sum":"h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ="},{"path":"github.com/google/go-cmp","version":"v0.5.1","sum":"h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k="},{"path":"github.com/sergi/go-diff","version":"v1.1.0","sum":"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0="},{"path":"golang.org/x/mod","version":"v0.3.0","sum":"h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4="},{"path":"golang.org/x/sync","version":"v0.0.0-20201020160332-67f06af15bc9","sum":"h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck="},{"path":"golang.org/x/tools","version":"v0.0.0-20201123203206-735e963e909b","sum":"h1:U8XGResmZKfdo8rCjWPsuiB4cu7N0PJSpQwc9lZr9Rg="},{"path":"golang.org/x/xerrors","version":"v0.0.0-20200804184101-5ec99f83aff1","sum":"h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE="},{"path":"honnef.co/go/tools","version":"v0.0.1-2020.1.6","sum":"h1:W18jzjh8mfPez+AwGLxmOImucz/IFjpNlrKVnaj2YVc="},{"path":"mvdan.cc/gofumpt","version":"v0.0.0-20200927160801-5bfeb2e70dd6","sum":"h1:z+/YqapuV7VZPvBb3GYmuEJbA88M3PFUxaHilHYVCpQ="},{"path":"mvdan.cc/xurls/v2","version":"v2.2.0","sum":"h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A="}]}"}}

[Trace - 14:27:17.268 PM] Sending notification 'initialized'.
Params: {}

[Trace - 14:27:17.268 PM] Received request 'window/workDoneProgress/create - (1)'.
Params: {"token":"*******************"}

[Trace - 14:27:17.269 PM] Sending response 'window/workDoneProgress/create - (1)' in 1ms.
Result:

[Trace - 14:27:17.269 PM] Received notification '$/progress'.
Params: {"token":"*******************","value":{"kind":"begin","title":"Setting up workspace","message":"Loading packages..."}}

[Trace - 14:27:17.270 PM] Received request 'workspace/configuration - (2)'.
Params: {"items":[{"scopeUri":"file:///home/username","section":"gopls"}]}

[Trace - 14:27:17.274 PM] Sending response 'workspace/configuration - (2)' in 4ms.
Result: [null]

[Trace - 14:27:17.317 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/12/01 14:27:17 go env for /home/username\n(root /home/username)\n(go version go version go1.15.5 linux/amd64)\n(valid build configuration = false)\n(build flags: [])\nGOPATH=/home/username/go\nGO111MODULE=on\nGONOSUMDB=\nGOMODCACHE=/home/username/go/pkg/mod\nGONOPROXY=\nGOPROXY=https://goproxy.io,direct\nGOROOT=/usr/local/go\nGOFLAGS=\nGOINSECURE=\nGOMOD=/dev/null\nGOCACHE=/home/username/.cache/go-build\nGOSUMDB=sum.golang.org\nGOPRIVATE=\n\n"}

[Info - 2:27:17 PM] 2020/12/01 14:27:17 go env for /home/username
(root /home/username)
(go version go version go1.15.5 linux/amd64)
(valid build configuration = false)
(build flags: [])
GOPATH=/home/username/go
GO111MODULE=on
GONOSUMDB=
GOMODCACHE=/home/username/go/pkg/mod
GONOPROXY=
GOPROXY=https://goproxy.io,direct
GOROOT=/usr/local/go
GOFLAGS=
GOINSECURE=
GOMOD=/dev/null
GOCACHE=/home/username/.cache/go-build
GOSUMDB=sum.golang.org
GOPRIVATE=

[Trace - 14:27:17.317 PM] Received request 'client/registerCapability - (3)'.
Params: {"registrations":[{"id":"workspace/didChangeWatchedFiles-0","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/*.{go,mod,sum}","kind":7}]}}]}

[Trace - 14:27:17.321 PM] Sending response 'client/registerCapability - (3)' in 3ms.
Result:

[Trace - 14:27:17.321 PM] Received request 'client/registerCapability - (4)'.
Params: {"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"}]}

[Trace - 14:27:17.322 PM] Sending response 'client/registerCapability - (4)' in 0ms.
Result:

[Trace - 14:27:17.326 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/12/01 14:27:17 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./ builtin]: exit status 1: go: cannot find main module; see 'go help modules'\n\n\tsnapshot=0\n\tdirectory=/home/username\n\tquery=[./ builtin]\n\tpackages=0\n"}

[Error - 2:27:17 PM] 2020/12/01 14:27:17 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./ builtin]: exit status 1: go: cannot find main module; see 'go help modules'

snapshot=0
directory=/home/username
query=[./ builtin]
packages=0

[Trace - 14:27:17.328 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/12/01 14:27:17 initial workspace load failed: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./ builtin]: exit status 1: go: cannot find main module; see 'go help modules'\n: packages.Load error\n"}

[Trace - 14:27:17.328 PM] Received notification '$/progress'.
Params: {"token":"*******************","value":{"kind":"end","message":"Finished loading packages."}}

[Error - 2:27:17 PM] 2020/12/01 14:27:17 initial workspace load failed: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./ builtin]: exit status 1: go: cannot find main module; see 'go help modules'
: packages.Load error

[Trace - 14:27:17.340 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/12/01 14:27:17 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules'\n\n\tsnapshot=0\n\tdirectory=/home/username\n\tquery=[./]\n\tpackages=0\n"}

[Error - 2:27:17 PM] 2020/12/01 14:27:17 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules'

snapshot=0
directory=/home/username
query=[./]
packages=0

[Trace - 14:27:17.510 PM] Received request 'window/workDoneProgress/create - (5)'.
Params: {"token":"8674665223082153551"}

[Trace - 14:27:17.511 PM] Sending response 'window/workDoneProgress/create - (5)' in 0ms.
Result:

[Trace - 14:27:17.511 PM] Received notification '$/progress'.
Params: {"token":"8674665223082153551","value":{"kind":"begin","title":"Error loading workspace","message":"go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules' : packages.Load error"}}

[Trace - 14:27:17.511 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/12/01 14:27:17 errors diagnosing workspace: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules'\n: packages.Load error\n\tsnapshot=0\n\tdirectory=file:///home/username\n"}

[Error - 2:27:17 PM] 2020/12/01 14:27:17 errors diagnosing workspace: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules'
: packages.Load error
snapshot=0
directory=file:///home/username

[Trace - 14:27:22.859 PM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///home/username/workspace/projects/http2socks5/main.go","languageId":"go","version":1,"text":"package main\n\nimport (\n\t"bytes"\n\t"fmt"\n\t"io"\n\t"log"\n\t"net"\n\t"net/url"\n\t"strings"\n\n\t"golang.org/x/net/proxy"\n)\n\nfunc main() {\n\tlog.SetFlags(log.LstdFlags | log.Lshortfile)\n\tl, err := net.Listen("tcp", "127.0.0.1:8080")\n\tif err != nil {\n\t\tlog.Panic(err)\n\t}\n\n\tfor {\n\t\tclient, err := l.Accept()\n\t\tif err != nil {\n\t\t\tlog.Panic(err)\n\t\t}\n\n\t\tgo handleClientRequest(client)\n\t}\n}\n\nfunc handleClientRequest(client net.Conn) {\n\tif client == nil {\n\t\treturn\n\t}\n\tdefer client.Close()\n\n\tvar b [1024]byte\n\tn, err := client.Read(b[:])\n\tif err != nil {\n\t\tlog.Println(err)\n\t\treturn\n\t}\n\tvar method, host, address string\n\tfmt.Sscanf(string(b[:bytes.IndexByte(b[:], '\n')]), "%s%s", &method, &host)\n\tfmt.Println(host)\n\thostPortURL, err := url.Parse(host)\n\tif err != nil {\n\t\tlog.Println(err)\n\t\treturn\n\t}\n\n\tif hostPortURL.Opaque == "443" { //https\n\t\taddress = hostPortURL.Scheme + ":443"\n\t} else { //http\n\t\tif strings.Index(hostPortURL.Host, ":") == -1 { //http port 80 by default\n\t\t\taddress = hostPortURL.Host + ":80"\n\t\t} else {\n\t\t\taddress = hostPortURL.Host\n\t\t}\n\n\t}\n\n\tscoks5Dialer, err := proxy.SOCKS5("tcp", "127.0.0.1:51837", nil, proxy.Direct)\n\tif err != nil {\n\t\tlog.Println(err)\n\t\treturn\n\t}\n\tserver, err := scoks5Dialer.Dial("tcp", address)\n\tif err != nil {\n\t\tlog.Println(err)\n\t\treturn\n\t}\n\tif method == "CONNECT" {\n\t\tfmt.Fprint(client, "HTTP/1.1 200 Connection established\n\n")\n\t} else {\n\t\tserver.Write(b[:n])\n\t}\n\n\tgo io.Copy(server, client)\n\tio.Copy(client, server)\n}\n"}}

[Trace - 14:27:22.859 PM] Sending request 'textDocument/documentLink - (1)'.
Params: {"textDocument":{"uri":"file:///home/username/workspace/projects/http2socks5/main.go"}}

[Trace - 14:27:22.859 PM] Sending request 'textDocument/codeAction - (2)'.
Params: {"textDocument":{"uri":"file:///home/username/workspace/projects/http2socks5/main.go"},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}},"context":{"diagnostics":[]}}

[Trace - 14:27:22.859 PM] Sending request 'textDocument/documentSymbol - (3)'.
Params: {"textDocument":{"uri":"file:///home/username/workspace/projects/http2socks5/main.go"}}

[Trace - 14:27:22.859 PM] Sending notification '$/cancelRequest'.
Params: {"id":3}

[Trace - 14:27:22.859 PM] Sending request 'textDocument/documentSymbol - (4)'.
Params: {"textDocument":{"uri":"file:///home/username/workspace/projects/http2socks5/main.go"}}

[Trace - 14:27:22.870 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/12/01 14:27:22 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules'\n\n\tsnapshot=0\n\tdirectory=/home/username\n\tquery=[./]\n\tpackages=0\n"}

[Error - 2:27:22 PM] 2020/12/01 14:27:22 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules'

snapshot=0
directory=/home/username
query=[./]
packages=0

[Trace - 14:27:22.981 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/12/01 14:27:22 go/packages.Load\n\tsnapshot=1\n\tdirectory=/home/username\n\tquery=[file=/home/username/workspace/projects/http2socks5/main.go]\n\tpackages=1\n"}

[Trace - 14:27:22.982 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/12/01 14:27:22 go/packages.Load\n\tsnapshot=1\n\tpackage_path="command-line-arguments"\n\tfiles=[/home/username/workspace/projects/http2socks5/main.go]\n"}

[Info - 2:27:22 PM] 2020/12/01 14:27:22 go/packages.Load
snapshot=1
directory=/home/username
query=[file=/home/username/workspace/projects/http2socks5/main.go]
packages=1

[Info - 2:27:22 PM] 2020/12/01 14:27:22 go/packages.Load
snapshot=1
package_path="command-line-arguments"
files=[/home/username/workspace/projects/http2socks5/main.go]

[Trace - 14:27:22.988 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/12/01 14:27:22 go/packages.Load\n\tsnapshot=1\n\tpackage_path="command-line-arguments"\n\tfiles=[/home/username/workspace/projects/http2socks5/main.go]\n"}

[Trace - 14:27:22.988 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/12/01 14:27:22 go/packages.Load\n\tsnapshot=1\n\tdirectory=/home/username\n\tquery=[file=/home/username/workspace/projects/http2socks5/main.go]\n\tpackages=1\n"}

[Info - 2:27:22 PM] 2020/12/01 14:27:22 go/packages.Load
snapshot=1
package_path="command-line-arguments"
files=[/home/username/workspace/projects/http2socks5/main.go]

[Info - 2:27:22 PM] 2020/12/01 14:27:22 go/packages.Load
snapshot=1
directory=/home/username
query=[file=/home/username/workspace/projects/http2socks5/main.go]
packages=1

[Trace - 14:27:23.032 PM] Sending request 'textDocument/codeLens - (5)'.
Params: {"textDocument":{"uri":"file:///home/username/workspace/projects/http2socks5/main.go"}}

[Trace - 14:27:23.035 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/12/01 14:27:23 command-line-arguments: no dep handle for golang.org/x/net/proxy: no metadata for golang.org/x/net/proxy\n\tsnapshot=1\n"}

[Error - 2:27:23 PM] 2020/12/01 14:27:23 command-line-arguments: no dep handle for golang.org/x/net/proxy: no metadata for golang.org/x/net/proxy
snapshot=1

[Trace - 14:27:23.037 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/12/01 14:27:23 command-line-arguments: no dep handle for golang.org/x/net/proxy: no metadata for golang.org/x/net/proxy\n\tsnapshot=1\n"}

[Error - 2:27:23 PM] 2020/12/01 14:27:23 command-line-arguments: no dep handle for golang.org/x/net/proxy: no metadata for golang.org/x/net/proxy
snapshot=1

[Trace - 14:27:23.078 PM] Sending request 'textDocument/foldingRange - (6)'.
Params: {"textDocument":{"uri":"file:///home/username/workspace/projects/http2socks5/main.go"}}

[Trace - 14:27:23.230 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///home/username/workspace/projects/http2socks5/main.go","version":1,"diagnostics":[{"range":{"start":{"line":11,"character":1},"end":{"line":11,"character":25}},"severity":1,"source":"compiler","message":"could not import golang.org/x/net/proxy (no package for import golang.org/x/net/proxy)"}]}

[Trace - 14:27:23.230 PM] Received response 'textDocument/documentLink - (1)' in 371ms.
Result: [{"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":7}},"target":"https://pkg.go.dev/bytes?utm_source=gopls"},{"range":{"start":{"line":4,"character":2},"end":{"line":4,"character":5}},"target":"https://pkg.go.dev/fmt?utm_source=gopls"},{"range":{"start":{"line":5,"character":2},"end":{"line":5,"character":4}},"target":"https://pkg.go.dev/io?utm_source=gopls"},{"range":{"start":{"line":6,"character":2},"end":{"line":6,"character":5}},"target":"https://pkg.go.dev/log?utm_source=gopls"},{"range":{"start":{"line":7,"character":2},"end":{"line":7,"character":5}},"target":"https://pkg.go.dev/net?utm_source=gopls"},{"range":{"start":{"line":8,"character":2},"end":{"line":8,"character":9}},"target":"https://pkg.go.dev/net/url?utm_source=gopls"},{"range":{"start":{"line":9,"character":2},"end":{"line":9,"character":9}},"target":"https://pkg.go.dev/strings?utm_source=gopls"},{"range":{"start":{"line":11,"character":2},"end":{"line":11,"character":24}},"target":"https://pkg.go.dev/golang.org/x/net/proxy?utm_source=gopls"},{"range":{"start":{"line":16,"character":30},"end":{"line":16,"character":44}},"target":"https://127.0.0.1:8080"},{"range":{"start":{"line":63,"character":43},"end":{"line":63,"character":58}},"target":"https://127.0.0.1:51837"}]

[Error - Received] 14:27:23.231 PM #3 JSON RPC cancelled

[Trace - 14:27:23.231 PM] Received response 'textDocument/codeAction - (2)' in 372ms.
Result: null

[Trace - 14:27:23.231 PM] Received response 'textDocument/documentSymbol - (4)' in 372ms.
Result: [{"name":"main","detail":"()","kind":12,"range":{"start":{"line":14,"character":0},"end":{"line":29,"character":1}},"selectionRange":{"start":{"line":14,"character":5},"end":{"line":14,"character":9}}},{"name":"handleClientRequest","detail":"(client net.Conn)","kind":12,"range":{"start":{"line":31,"character":0},"end":{"line":81,"character":1}},"selectionRange":{"start":{"line":31,"character":5},"end":{"line":31,"character":24}}}]

[Trace - 14:27:23.232 PM] Received response 'textDocument/codeLens - (5)' in 199ms.
Result: null

[Trace - 14:27:23.232 PM] Received response 'textDocument/foldingRange - (6)' in 153ms.
Result: [{"startLine":2,"startCharacter":8,"endLine":11,"endCharacter":25,"kind":"imports"},{"startLine":14,"startCharacter":13,"endLine":28,"endCharacter":2},{"startLine":17,"startCharacter":16,"endLine":18,"endCharacter":16},{"startLine":21,"startCharacter":6,"endLine":27,"endCharacter":32},{"startLine":23,"startCharacter":17,"endLine":24,"endCharacter":17},{"startLine":31,"startCharacter":43,"endLine":80,"endCharacter":24},{"startLine":32,"startCharacter":19,"endLine":33,"endCharacter":8},{"startLine":39,"startCharacter":16,"endLine":41,"endCharacter":8},{"startLine":47,"startCharacter":16,"endLine":49,"endCharacter":8},{"startLine":52,"startCharacter":33,"endLine":53,"endCharacter":39},{"startLine":54,"startCharacter":9,"endLine":59,"endCharacter":3},{"startLine":55,"startCharacter":49,"endLine":56,"endCharacter":37},{"startLine":57,"startCharacter":10,"endLine":58,"endCharacter":29},{"startLine":64,"startCharacter":16,"endLine":66,"endCharacter":8},{"startLine":69,"startCharacter":16,"endLine":71,"endCharacter":8},{"startLine":73,"startCharacter":25,"endLine":74,"endCharacter":63},{"startLine":75,"startCharacter":9,"endLine":76,"endCharacter":21}]

[Trace - 14:27:23.440 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/12/01 14:27:23 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules'\n\n\tsnapshot=1\n\tdirectory=/home/username\n\tquery=[./]\n\tpackages=0\n"}

[Error - 2:27:23 PM] 2020/12/01 14:27:23 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules'

snapshot=1
directory=/home/username
query=[./]
packages=0

[Trace - 14:27:23.614 PM] Received notification '$/progress'.
Params: {"token":"8674665223082153551","value":{"kind":"report","message":"go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules' : packages.Load error"}}

[Trace - 14:27:23.615 PM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/12/01 14:27:23 errors diagnosing workspace: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules'\n: packages.Load error\n\tsnapshot=1\n\tdirectory=file:///home/username\n"}

[Error - 2:27:23 PM] 2020/12/01 14:27:23 errors diagnosing workspace: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module; see 'go help modules'
: packages.Load error
snapshot=1
directory=file:///home/username

[Trace - 14:27:23.769 PM] Sending request 'textDocument/codeAction - (7)'.
Params: {"textDocument":{"uri":"file:///home/username/workspace/projects/http2socks5/main.go"},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}},"context":{"diagnostics":[]}}

[Trace - 14:27:23.770 PM] Received response 'textDocument/codeAction - (7)' in 0ms.
Result: null

[Trace - 14:27:31.975 PM] Sending request 'textDocument/codeAction - (8)'.
Params: {"textDocument":{"uri":"file:///home/username/workspace/projects/http2socks5/main.go"},"range":{"start":{"line":16,"character":46},"end":{"line":17,"character":16}},"context":{"diagnostics":[]}}

[Trace - 14:27:31.976 PM] Received response 'textDocument/codeAction - (8)' in 0ms.
Result: null

[Trace - 14:27:33.485 PM] Sending request 'textDocument/codeAction - (9)'.
Params: {"textDocument":{"uri":"file:///home/username/workspace/projects/http2socks5/main.go"},"range":{"start":{"line":17,"character":16},"end":{"line":17,"character":16}},"context":{"diagnostics":[]}}

[Trace - 14:27:33.485 PM] Received response 'textDocument/codeAction - (9)' in 0ms.
Result: null

[Trace - 14:27:53.236 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/12/01 14:27:53 background imports cache refresh starting\n"}

[Info - 2:27:53 PM] 2020/12/01 14:27:53 background imports cache refresh starting

[Trace - 14:27:53.274 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/12/01 14:27:53 background refresh finished after 42.990432ms\n"}

[Info - 2:27:53 PM] 2020/12/01 14:27:53 background refresh finished after 42.990432ms

Besides, I found something that the error only occurred when I open the whole home directory as the workspace in vscode.
Whenever I only open the project folder as the workspace, it won't occur.
It seems that the gopls treats my home directory as the project folder.
However, the gopls should not tell me that it cannot import golang.org/x/net as the gopath was already defined in the PATH.

It is hard for me to accept that I should only open my project folder as a workspace as an answer to this issue.
I'm using remote-ssh extension.
For me, I would like to have my whole home directory to be the workspace as the vscode will become a file explorer.
I can not always open a project folder as the workspace. Whenever I'm opening something else, the gopls will run automatically to generate a notification.

Thanks for your help. I do hope that you would fix this issue.

@hyangah
Copy link
Contributor

@hyangah hyangah commented Dec 1, 2020

@fourdim Thanks for sharing the trace.

VS Code and language server assume the open folder as the project root. For people who want to work on multiple related projects, VS Code supports multi-root workspace mode.

Since there is no main module, the error message is not completely wrong IMHO, but I agree that better error message that explains why users are getting those errors would be helpful.

gopls/v0.5.4 adds support for opening a directory above the main module but this is activated only when there is only one module in a subdirectory. It's common to have multiple project directories under home directory; I don't think this feature is applicable to users who open the entire home directory.
I don't think the experimentalWorkspaceModule feature is applicable to this use case either - the feature assumes all the modules in the folders are somewhat related, but in this particular case, that's not necessarily true.

BTW VSCode remote-ssh extension allows to open a target folder or vscode workspace, so it doesn't limit you to open only from the home directory. I myself use remote-ssh often and usually use VSCode's "Open Folder" function that allows me to navigate the remote directory and open a separate window per each project. VSCode caches the directory configuration so I can easily resume my work by choosing it when reconnecting. By keeping the workspace project-scoped, vscode and language server becomes more performant - the language server and the vscode index all the symbols and references, set up file watchers, and do many things for everything under the folder.

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Dec 1, 2020

https://golang.org/cl/272346 will improve these error messages, but yes, in this case, the best course of action would be to add each module as its own workspace folder.

@fourdim
Copy link
Author

@fourdim fourdim commented Dec 2, 2020

@hyangah @stamblerre Thanks for your reply. You can close this issue according to your need.

@stamblerre stamblerre closed this Dec 2, 2020
vscode-go: gopls by default automation moved this from Needs Triage to Done Dec 2, 2020
@stamblerre stamblerre removed this from the gopls/vscode-go milestone Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants