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
Comments
CC @hyangah |
@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 @stamblerre this error message is strange - it reports that there is no main module, but according to the |
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"}]} Besides, I found something that the error only occurred when I open the whole home directory as the workspace in vscode. It is hard for me to accept that I should only open my project folder as a workspace as an answer to this issue. Thanks for your help. I do hope that you would fix this issue. |
@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. 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. |
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. |
@hyangah @stamblerre Thanks for your reply. You can close this issue according to your need. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputBesides, 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.
The text was updated successfully, but these errors were encountered: