golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.8k stars 17.64k forks source link

x/tools/gopls: error message pop-up: "The code in the workspace failed to compile..." #40578

Closed shenghui0779 closed 4 years ago

shenghui0779 commented 4 years ago

image

hyangah commented 4 years ago

@shenghui0779 thanks for the report. This looks similar to https://github.com/golang/vscode-go/issues/463 and it looks like the error message is from the gopls

Can you please follow the gopls troubleshooting guide and share the gopls log? https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#vs-code

phongvcao commented 4 years ago

@hyangah I'm having the same problem but on Vim with coc.nvim. How can I enable gopls debug with args in coc.nvim? I've tried multiple setup without success.

The golang/go documentation for Vim/coc.nvim (https://github.com/golang/tools/blob/master/gopls/doc/vim.md#cocnvim) doesn't mention anything about -rpc.trace and -debug=localhost:6060

stamblerre commented 4 years ago

I'm also not sure about how to pass flags to the language server in coc.nvim, but you can try running gopls -rpc.trace -v check path/to/file.go. Otherwise, I'd suggest filing a coc.nvim issue to ask about passing flags to gopls.

leguminosa commented 4 years ago

I have the same issue, it keeps popping out for almost every action I did

chrismalek commented 4 years ago

+1

stamblerre commented 4 years ago

@leguminosa, @chrismalek: Please open new issues and provide the information requested in the gopls troubleshooting guide.

hyangah commented 4 years ago

@phongvcao I am not familiar with coc.nvim. I am guessing you can pass extra args with the args field and set revealOutputChannelOn. Probably trace.server option is also another way.

chrismalek commented 4 years ago

More Information:

I enabled the trace flag in vscode settings.

 "go.languageServerFlags": ["-rpc.trace", "-debug=localhost:6060"]

Here is what my directory look like.

▶ pwd
/Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit

com~apple~CloudDocs/code/chg-ps-audit  master ✗                                                                                                                                                                                                                               2d ⚑ ◒  
▶ tree
.
├── Dockerfile
├── code
│   └── backend
│       ├── chg-ps-audit
│       ├── config.yml
│       ├── go.mod
│       ├── go.sum
│       └── main.go
├── docs
│   ├── assets
│   ├── audits.md
│   ├── backend.md
│   ├── collector.md
│   ├── front-end.md
│   ├── gcp-setup.md
│   └── readme.md
└── readme.md

Output of trace

[Trace - 09:33:00.295 AM] Sending request 'initialize - (0)'.
Params: {"processId":70490,"clientInfo":{"name":"vscode","version":"1.47.3"},"rootPath":"/Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit","rootUri":"file:///Users/chrismalek/Library/Mobile%20Documents/com~apple~CloudDocs/code/chg-ps-audit","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]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]}},"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]}},"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}},"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},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"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},"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}},"window":{"workDoneProgress":true}},"initializationOptions":{},"trace":"off","workspaceFolders":[{"uri":"file:///Users/chrismalek/Library/Mobile%20Documents/com~apple~CloudDocs/code/chg-ps-audit","name":"chg-ps-audit"}]}

[Trace - 09:33:00.312 AM] Received response 'initialize - (0)' 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":{"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":["generate","fill_struct","regenerate_cgo","test","tidy","undeclared_name","upgrade_dependency","vendor","extract_variable","extract_function"]},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":"gopls","version":"Build info\n----------\ngolang.org/x/tools/gopls 0.4.4\n    golang.org/x/tools/gopls@v0.4.4 h1:8djGYsaZ0ByP0vaXg4T+mnyfDcHpWKSZ+tpQSGv9ahk=\n    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n    github.com/google/go-cmp@v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=\n    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\n    golang.org/x/mod@v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=\n    golang.org/x/sync@v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=\n    golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c h1:jLQLIAedRoS9I2Py7l/ZAGGzUxLFsdg42JXEpS/a+ow=\n    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=\n    honnef.co/go/tools@v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=\n    mvdan.cc/gofumpt@v0.0.0-20200709182408-4fd085cb6d5f h1:gi7cb8HTDZ6q8VqsUpkdoFi3vxwHMneQ6+Q5Ap5hjPE=\n    mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=\n\nGo info\n-------\ngo version go1.14.6 darwin/amd64\n\n"}}

[Trace - 09:33:00.328 AM] Sending notification 'initialized'.
Params: {}

[Trace - 09:33:00.342 AM] Received request 'workspace/configuration - (1)'.
Params: {"items":[{"scopeUri":"file:///Users/chrismalek/Library/Mobile%20Documents/com~apple~CloudDocs/code/chg-ps-audit","section":"gopls"},{"scopeUri":"file:///Users/chrismalek/Library/Mobile%20Documents/com~apple~CloudDocs/code/chg-ps-audit","section":"gopls-chg-ps-audit"}]}

[Trace - 09:33:00.342 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/08/08 09:33:00 Build info\n----------\ngolang.org/x/tools/gopls 0.4.4\n    golang.org/x/tools/gopls@v0.4.4 h1:8djGYsaZ0ByP0vaXg4T+mnyfDcHpWKSZ+tpQSGv9ahk=\n    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n    github.com/google/go-cmp@v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=\n    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\n    golang.org/x/mod@v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=\n    golang.org/x/sync@v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=\n    golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c h1:jLQLIAedRoS9I2Py7l/ZAGGzUxLFsdg42JXEpS/a+ow=\n    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=\n    honnef.co/go/tools@v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=\n    mvdan.cc/gofumpt@v0.0.0-20200709182408-4fd085cb6d5f h1:gi7cb8HTDZ6q8VqsUpkdoFi3vxwHMneQ6+Q5Ap5hjPE=\n    mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=\n\nGo info\n-------\ngo version go1.14.6 darwin/amd64\n\n\n"}

[Trace - 09:33:00.353 AM] Sending response 'workspace/configuration - (1)' in 10ms.
Result: [null,null]

[Info  - 9:33:00 AM] 2020/08/08 09:33:00 Build info
----------
golang.org/x/tools/gopls 0.4.4
    golang.org/x/tools/gopls@v0.4.4 h1:8djGYsaZ0ByP0vaXg4T+mnyfDcHpWKSZ+tpQSGv9ahk=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/google/go-cmp@v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
    golang.org/x/sync@v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
    golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c h1:jLQLIAedRoS9I2Py7l/ZAGGzUxLFsdg42JXEpS/a+ow=
    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
    honnef.co/go/tools@v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=
    mvdan.cc/gofumpt@v0.0.0-20200709182408-4fd085cb6d5f h1:gi7cb8HTDZ6q8VqsUpkdoFi3vxwHMneQ6+Q5Ap5hjPE=
    mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=

Go info
-------
go version go1.14.6 darwin/amd64

[Trace - 09:33:00.389 AM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2020/08/08 09:33:00 go env for /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit\n(root )\n(valid build configuration = false)\n(build flags: [])\nGOPRIVATE=\nGOPROXY=https://proxy.golang.org,direct\nGOCACHE=/Users/chrismalek/Library/Caches/go-build\nGOFLAGS=\nGONOPROXY=\nGOPATH=/Users/chrismalek/code/go\nGOROOT=/usr/local/opt/go/libexec\nGOMOD=/dev/null\nGO111MODULE=on\nGOSUMDB=sum.golang.org\nGOINSECURE=\nGOMODCACHE=\nGONOSUMDB=\n\n"}

[Trace - 09:33:00.389 AM] Received request 'client/registerCapability - (2)'.
Params: {"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"},{"id":"workspace/didChangeWatchedFiles","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"/**/*.{go,mod,sum}","kind":7}]}}]}

[Info  - 9:33:00 AM] 2020/08/08 09:33:00 go env for /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit
(root )
(valid build configuration = false)
(build flags: [])
GOPRIVATE=
GOPROXY=https://proxy.golang.org,direct
GOCACHE=/Users/chrismalek/Library/Caches/go-build
GOFLAGS=
GONOPROXY=
GOPATH=/Users/chrismalek/code/go
GOROOT=/usr/local/opt/go/libexec
GOMOD=/dev/null
GO111MODULE=on
GOSUMDB=sum.golang.org
GOINSECURE=
GOMODCACHE=
GONOSUMDB=

[Trace - 09:33:00.391 AM] Sending response 'client/registerCapability - (2)' in 2ms.
Result: 

[Trace - 09:33:00.404 AM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/08/08 09:33:00 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, but found .git/config in /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit\n\tto create a module there, run:\n\tgo mod init\n: packages.Load error\n"}

[Trace - 09:33:00.404 AM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/08/08 09:33:00 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, but found .git/config in /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit\n\tto create a module there, run:\n\tgo mod init\n\n\tsnapshot=0\n\tdirectory=\n\tquery=[./ builtin]\n\tpackages=0\n"}

[Error - 9:33:00 AM] 2020/08/08 09:33:00 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, but found .git/config in /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit
    to create a module there, run:
    go mod init
: packages.Load error

[Error - 9:33:00 AM] 2020/08/08 09:33:00 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, but found .git/config in /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit
    to create a module there, run:
    go mod init

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

[Trace - 09:33:00.420 AM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/08/08 09:33:00 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module, but found .git/config in /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit\n\tto create a module there, run:\n\tgo mod init\n\n\tsnapshot=0\n\tdirectory=\n\tquery=[./]\n\tpackages=0\n"}

[Trace - 09:33:00.420 AM] Received notification 'window/showMessage'.
Params: {"type":1,"message":"The code in the workspace failed to compile (see the error message below).\nIf you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new.\ngo [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module, but found .git/config in /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit\n\tto create a module there, run:\n\tgo mod init\n: packages.Load error"}

[Trace - 09:33:00.420 AM] Received notification 'window/logMessage'.
Params: {"type":1,"message":"2020/08/08 09:33:00 The code in the workspace failed to compile (see the error message below).\nIf you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new.: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module, but found .git/config in /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit\n\tto create a module there, run:\n\tgo mod init\n: packages.Load error\n\tsnapshot=0\n\tdirectory=file:///Users/chrismalek/Library/Mobile%20Documents/com~apple~CloudDocs/code/chg-ps-audit\n"}

[Error - 9:33:00 AM] 2020/08/08 09:33:00 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module, but found .git/config in /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit
    to create a module there, run:
    go mod init

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

[Error - 9:33:00 AM] 2020/08/08 09:33:00 The code in the workspace failed to compile (see the error message below).
If you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new.: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module, but found .git/config in /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit
    to create a module there, run:
    go mod init
: packages.Load error
    snapshot=0
    directory=file:///Users/chrismalek/Library/Mobile%20Documents/com~apple~CloudDocs/code/chg-ps-audit

It cannot find the go.mod file nor the main file but I assure you they are there.

I did notice it is showing this /Users/chrismalek/Library/Mobile Documents/com~apple~CloudDocs/code/chg-ps-audit\n\tto

I am not sure if that \ntto at the end is from some log but that is NOT a directory. It looks like there are some escape sequences there. Maybe that is the source of the bug.

Let me know if I can provide any other details. I am not deep into the weeds of how gopls works.

stamblerre commented 4 years ago

@chrismalek: gopls currently requires that you open a directory at or below the root of your module--in your case, the backend directory. You can use View -> Add Folder to Workspace to add the backend directory to your workspace. Future versions of gopls will handle this use case and make the workaround unnecessary.

chrismalek commented 4 years ago

@stamblerre thank you. That worked. Thanks for your expertise.

leguminosa commented 4 years ago

@stamblerre I haven't received any error pop-up like yesterday, are there by any means new releases / fixes already?

stamblerre commented 4 years ago

@leguminosa: No, there haven't been any new releases since this issue was filed. Please open a new issue if you encounter this problem again.

baronliu commented 4 years ago

I have the same problem in my php workspace . It seems gopls also works in non go projects. What should I do?

go version go1.14.4 linux/amd64 golang.org/x/tools/gopls 0.4.4 vscode-go 0.16.1

@stamblerre

stamblerre commented 4 years ago

@baronliu: Please provide your gopls logs - the instructions on how to do this can be found here.

baronliu commented 4 years ago

`[Trace - 10:35:21.869 AM] Sending request 'initialize - (0)'. Params: {"processId":2613,"clientInfo":{"name":"vscode","version":"1.47.3"},"rootPath":"/data/workspace/phpWorkspace/testtest","rootUri":"file:///data/workspace/phpWorkspace/testtest","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]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]}},"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]}},"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}},"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},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"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},"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}},"window":{"workDoneProgress":true}},"initializationOptions":{},"trace":"off","workspaceFolders":[{"uri":"file:///data/workspace/phpWorkspace/testtest","name":"testtest"}]}

[Trace - 10:35:21.876 AM] Received response 'initialize - (0)' in 6ms. 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":["generate","fill_struct","regenerate_cgo","test","tidy","undeclared_name","upgrade_dependency","vendor","extract_variable","extract_function"]},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":"gopls","version":"Build info\n----------\ngolang.org/x/tools/gopls 0.4.4\n golang.org/x/tools/gopls@v0.4.4 h1:8djGYsaZ0ByP0vaXg4T+mnyfDcHpWKSZ+tpQSGv9ahk=\n github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n github.com/google/go-cmp@v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=\n github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\n golang.org/x/mod@v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=\n golang.org/x/sync@v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=\n golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c h1:jLQLIAedRoS9I2Py7l/ZAGGzUxLFsdg42JXEpS/a+ow=\n golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=\n honnef.co/go/tools@v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=\n mvdan.cc/gofumpt@v0.0.0-20200709182408-4fd085cb6d5f h1:gi7cb8HTDZ6q8VqsUpkdoFi3vxwHMneQ6+Q5Ap5hjPE=\n mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=\n\nGo info\n-------\ngo version go1.14.4 linux/amd64\n\n"}}

[Trace - 10:35:21.879 AM] Sending notification 'initialized'. Params: {}

[Trace - 10:35:21.884 AM] Received request 'workspace/configuration - (1)'. Params: {"items":[{"scopeUri":"file:///data/workspace/phpWorkspace/testtest","section":"gopls"},{"scopeUri":"file:///data/workspace/phpWorkspace/testtest","section":"gopls-testtest"}]}

[Trace - 10:35:21.885 AM] Received notification 'window/logMessage'. Params: {"type":3,"message":"2020/08/13 10:35:21 Build info\n----------\ngolang.org/x/tools/gopls 0.4.4\n golang.org/x/tools/gopls@v0.4.4 h1:8djGYsaZ0ByP0vaXg4T+mnyfDcHpWKSZ+tpQSGv9ahk=\n github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n github.com/google/go-cmp@v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=\n github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\n golang.org/x/mod@v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=\n golang.org/x/sync@v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=\n golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c h1:jLQLIAedRoS9I2Py7l/ZAGGzUxLFsdg42JXEpS/a+ow=\n golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=\n honnef.co/go/tools@v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=\n mvdan.cc/gofumpt@v0.0.0-20200709182408-4fd085cb6d5f h1:gi7cb8HTDZ6q8VqsUpkdoFi3vxwHMneQ6+Q5Ap5hjPE=\n mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=\n\nGo info\n-------\ngo version go1.14.4 linux/amd64\n\n\n"}

[Info - 10:35:21 AM] 2020/08/13 10:35:21 Build info

golang.org/x/tools/gopls 0.4.4 golang.org/x/tools/gopls@v0.4.4 h1:8djGYsaZ0ByP0vaXg4T+mnyfDcHpWKSZ+tpQSGv9ahk= github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/google/go-cmp@v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= golang.org/x/mod@v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/sync@v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA= golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c h1:jLQLIAedRoS9I2Py7l/ZAGGzUxLFsdg42JXEpS/a+ow= golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= honnef.co/go/tools@v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8= mvdan.cc/gofumpt@v0.0.0-20200709182408-4fd085cb6d5f h1:gi7cb8HTDZ6q8VqsUpkdoFi3vxwHMneQ6+Q5Ap5hjPE= mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=

Go info

go version go1.14.4 linux/amd64

[Trace - 10:35:21.890 AM] Sending response 'workspace/configuration - (1)' in 5ms. Result: [null,null]

[Trace - 10:35:21.921 AM] Received notification 'window/logMessage'. Params: {"type":3,"message":"2020/08/13 10:35:21 go env for /data/workspace/phpWorkspace/testtest\n(root )\n(valid build configuration = false)\n(build flags: [])\nGOMODCACHE=\nGOROOT=/usr/local/go\nGOINSECURE=\nGONOSUMDB=\nGOPRIVATE=\nGOCACHE=/root/.cache/go-build\nGOFLAGS=\nGOMOD=/dev/null\nGONOPROXY=\nGOPROXY=https://proxy.golang.org,direct\nGO111MODULE=on\nGOPATH=/root/go\nGOSUMDB=sum.golang.org\n\n"}

[Trace - 10:35:21.922 AM] Received request 'client/registerCapability - (2)'. Params: {"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"},{"id":"workspace/didChangeWatchedFiles","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"/*/.{go,mod,sum}","kind":7}]}}]}

[Info - 10:35:21 AM] 2020/08/13 10:35:21 go env for /data/workspace/phpWorkspace/testtest (root ) (valid build configuration = false) (build flags: []) GOMODCACHE= GOROOT=/usr/local/go GOINSECURE= GONOSUMDB= GOPRIVATE= GOCACHE=/root/.cache/go-build GOFLAGS= GOMOD=/dev/null GONOPROXY= GOPROXY=https://proxy.golang.org,direct GO111MODULE=on GOPATH=/root/go GOSUMDB=sum.golang.org

[Trace - 10:35:21.926 AM] Sending response 'client/registerCapability - (2)' in 3ms. Result:

[Trace - 10:35:21.931 AM] Received notification 'window/logMessage'. Params: {"type":1,"message":"2020/08/13 10:35:21 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, but found .git/config in /data/workspace/phpWorkspace/testtest\n\tto create a module there, run:\n\tgo mod init\n\n\tsnapshot=0\n\tdirectory=\n\tquery=[./ builtin]\n\tpackages=0\n"}

[Trace - 10:35:21.931 AM] Received notification 'window/logMessage'. Params: {"type":1,"message":"2020/08/13 10:35:21 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, but found .git/config in /data/workspace/phpWorkspace/testtest\n\tto create a module there, run:\n\tgo mod init\n: packages.Load error\n"}

[Error - 10:35:21 AM] 2020/08/13 10:35:21 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, but found .git/config in /data/workspace/phpWorkspace/testtest to create a module there, run: go mod init

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

[Error - 10:35:21 AM] 2020/08/13 10:35:21 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, but found .git/config in /data/workspace/phpWorkspace/testtest to create a module there, run: go mod init : packages.Load error

[Trace - 10:35:21.938 AM] Received notification 'window/showMessage'. Params: {"type":1,"message":"The code in the workspace failed to compile (see the error message below).\nIf you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new.\ngo [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module, but found .git/config in /data/workspace/phpWorkspace/testtest\n\tto create a module there, run:\n\tgo mod init\n: packages.Load error"}

[Trace - 10:35:21.939 AM] Received notification 'window/logMessage'. Params: {"type":1,"message":"2020/08/13 10:35:21 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module, but found .git/config in /data/workspace/phpWorkspace/testtest\n\tto create a module there, run:\n\tgo mod init\n\n\tsnapshot=0\n\tdirectory=\n\tquery=[./]\n\tpackages=0\n"}

[Trace - 10:35:21.939 AM] Received notification 'window/logMessage'. Params: {"type":1,"message":"2020/08/13 10:35:21 The code in the workspace failed to compile (see the error message below).\nIf you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new.: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module, but found .git/config in /data/workspace/phpWorkspace/testtest\n\tto create a module there, run:\n\tgo mod init\n: packages.Load error\n\tsnapshot=0\n\tdirectory=file:///data/workspace/phpWorkspace/testtest\n"}

[Error - 10:35:21 AM] 2020/08/13 10:35:21 go/packages.Load: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module, but found .git/config in /data/workspace/phpWorkspace/testtest to create a module there, run: go mod init

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

[Error - 10:35:21 AM] 2020/08/13 10:35:21 The code in the workspace failed to compile (see the error message below). If you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new.: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module, but found .git/config in /data/workspace/phpWorkspace/testtest to create a module there, run: go mod init : packages.Load error snapshot=0 directory=file:///data/workspace/phpWorkspace/testtest

`

stamblerre commented 4 years ago

It looks like you are using modules, but gopls cannot find the module root. Currently, gopls requires that you open your directory at or below your module root (the directory containing the go.mod). Does gopls work if you do that?

baronliu commented 4 years ago

@stamblerre I installed the vscode-go plugin in vscode with gopls. I not only use vscode to develop go projects, but also use it to develop PHP projects. It is normal for PHP projects without go module. But gopls will report the above error. So what I want to know is why gopls detects a non go project and thinks it should uses go module. Some of my PHP projects will have the above-mentioned tips, but some do not. After analyzing the differences, I found that when my PHP project uses git submodule, it will report the above error. So I wonder if gopls treats the project that uses git submodule as go submodule, even if it is not a go project. This problem is also a recent problem, not before.

stamblerre commented 4 years ago

gopls should only be initialized when you are working in a directory that contains Go code. If you are opening a directory that contains both Go and PHP, you can use VS Code's workspace folders features. Add the module root to your workspace by selecting View -> Add Folder to Workspace.

ti-mo commented 4 years ago

@stamblerre Same happens here, despite using workspace folders as you describe above. Some of my workspace folders contain .go files, some don't. Since a recent update, VSCode trips over my notes folder (incidentally the first folder in my workspace, alphabetically). This folder contains only .md files and dirs.

This is the full error:

The code in the workspace failed to compile (see the error message below).
If you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new.
go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./]: exit status 1: go: cannot find main module, but found .git/config in /home/timo/documents/notes
    to create a module there, run:
    cd .. && go mod init
: packages.Load error

Please let me know if there's any other troubleshooting I can do to help find the root cause!

ma7ik commented 4 years ago

I am facing the same issue.


❯ tree .
.
└── env_var.go

0 directories, 1 file
❯ gopls -rpc.trace -v check env_var.go                                  
2020/08/17 20:02:37 Info:2020/08/17 20:02:37 Build info
----------
golang.org/x/tools/gopls 0.4.4
    golang.org/x/tools/gopls@(devel)
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/google/go-cmp@v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=                                                                                                            
    golang.org/x/mod@v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=                                                                                                                    
    golang.org/x/sync@v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=                                                                                       
    golang.org/x/tools@v0.0.0-20200729181040-64cdafbe085c => ../                                                                                                                               
    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=                                                                                    
    honnef.co/go/tools@v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=                                                                                                         
    mvdan.cc/gofumpt@v0.0.0-20200709182408-4fd085cb6d5f h1:gi7cb8HTDZ6q8VqsUpkdoFi3vxwHMneQ6+Q5Ap5hjPE=                                                                                        
    mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=                                                                                                                   

Go info                                                                                                                                                                                        
-------                                                                                                                                                                                        
go version go1.14.7 linux/amd64                                                                                                                                                                

2020/08/17 20:02:37 Info:2020/08/17 20:02:37 go env for /home/user/Go/test                                                                                                               
(root )                                                                                                                                                                                        
(valid build configuration = false)                                                                                                                                                            
(build flags: [])                                                                                                                                                                              
GONOSUMDB=                                                                                                                                                                                     
GOCACHE=/home/user/.cache/go-build                                                                                                                                                           
GOFLAGS=                                                                                                                                                                                       
GOINSECURE=                                                                                                                                                                                    
GO111MODULE=on                                                                                                                                                                                 
GOMODCACHE=                                                                                                                                                                                    
GONOPROXY=
GOMOD=/dev/null
GOPATH=/home/user/Go
GOPRIVATE=
GOSUMDB=sum.golang.org
GOPROXY=https://proxy.golang.org,direct
GOROOT=/usr/lib/go

2020/08/17 20:02:37 Error:2020/08/17 20:02:37 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
2020/08/17 20:02:37 Error:2020/08/17 20:02:37 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=
        query=[./ builtin]
        packages=0
2020/08/17 20:02:37 Error:2020/08/17 20:02:37 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=
        query=[./]
        packages=0
2020/08/17 20:02:37 Error:2020/08/17 20:02:37 The code in the workspace failed to compile (see the error message below).
If you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new.: 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/user/Go/test
2020/08/17 20:02:37 Error:2020/08/17 20:02:37 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=
        query=[./]
        packages=0
2020/08/17 20:02:37 Error:2020/08/17 20:02:37 The code in the workspace failed to compile (see the error message below).
If you believe this is a mistake, please file an issue: https://github.com/golang/go/issues/new.: 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/user/Go/test
heschi commented 4 years ago

This issue was fixed by https://golang.org/cl/248620, which has not yet been released. You can wait for the next release, or use the master version of gopls.