-
Notifications
You must be signed in to change notification settings - Fork 645
Autoimport not working #2473
Comments
ditto, auto-import and auto-complete for unimported packages fail for me |
Both of those work for me when the |
Yeah, it looks like it's related to gopls. Disabling it (Settings -> Use Language Server) solved it for me too. |
try del "go.useLanguageServer" and reload goimports |
Looking into the vs-code source, and at the settings sections here's what I gathered: 1- When using the language server ( So, it makes sense that 2- Now, enabling the language server isn't sufficient. It needs to be configured, and that part is not easily found in the documentation. You need to make sure to use this configuration(from https://github.com/golang/go/wiki/gopls#editors-instructions) to get the auto-import feature back: "go.useLanguageServer": true,
"go.languageServerExperimentalFeatures": {
"diagnostics": true // for diagnostics as you type
},
"[go]": {
"editor.snippetSuggestions": "none",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
},
"gopls": {
"usePlaceholders": true, // add parameter placeholders when completing a function
"enhancedHover": true, // experimental to improve quality of hover (will be on by default soon)
} Now, unfortunately, on my end, using this configuration restores the import feature, but it breaks the autocompletetion, as seen here: |
For the goimports/gofmt behavior, you need to configure this setting: "[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
} |
@huguesalary: imports should not be related to autocompletion. Does autocompletion work when you turn off the setting? |
@stamblerre The auto completion broke when I enabled the language server, but, disabling the language server did not bring back the auto-completion. Meanwhile, the reformatting also broke. I'm totally unclear about what is going on. |
Can you confirm that the language server is running? Go to "View: Debug Console" -> "Output" tab -> "Tasks" drop down, and check that there is an item titled |
I figured it out. The language server was correctly running. The issue was that the autoimport feature imported This error was completely invisible as far as Fixing this import fixed my issue. |
Glad you were able to resolve your issue, and I'm sorry the errors weren't showing up. We're going to try and do a better job of showing errors to the user - you can track this on golang/go#31668. |
Oh, I don't think the error reporting issue is a
The issue, I think, was
|
#2469 this issue has an solution. jellevandenhooff said,
|
So to summarize,
|
@ramya-rao-a the only visible error was in the And the error was:
|
Same problem, switched back to 0.9.2 and it started working again |
@huguesalary and @zephinzer: do you mind each filing issues in https://github.com/golang/go/issues? I can help you debug it there. |
In the latest beta version of this extension,
If anyone is seeing issues after enabling Closing this issue as most of the concerns have been addressed. Please log new issues for the rest |
The fix to make the setting in #2473 (comment) a default so that users don't have to set them has been released in the latest update (0.10.2) |
I have seen this issue repeatedly, since the functionality was first introduced. It comes and goes over time (on both Mac and Windows). Sometimes it works with |
@fastreles The latest The language server |
Since version 0.10.0 (0.10.1 included), autoimport doesn't work anymore.
This happens in a regular GOPATH as well as using go modules.
I am using Visual Studio Code Version: 1.33.1 on Ubuntu 18.04.2 LTS.
I have selected
goimports
in the settings, but it doesn't work withgoreturn
eitherThe text was updated successfully, but these errors were encountered: