-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/cmd/gopls: import organization fails on certain packages #31977
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
Comments
Does running |
@stamblerre Yes. |
Same behavior here.
|
|
Yes. Also, gopls works fine for some files. It's inconsistent.
I can reproduce the problem both in the root (where |
Got it. Thank you. |
@atombender: Are you able to offer the contents of the Go file and the |
As I said, it's just a skeleton file with just an empty |
I did see the main file in the logs you attached, but I was more curious about the Also, just checking, is the file saved on disk? If the file isn't saved yet, |
Yes, it's saved. Everything being imported is within the same Go module. I haven't noticed any patterns to the problem. I'll see if I can create a minimally reproducible case here now. More logging might be useful. After using |
For the record, my experience with gopls + VSCode on Mac mirrors @atombender; several times a day, I notice that auto-importing and autocompletion have stopped working. Restarting VSCode (and, therefore, gopls) typically solves the issue for awhile. I'd happily run it in some diagnostic mode and report back, if it helps. edit: I'm on go version go1.12.4 darwin/amd64, in a project using modules, with a go.mod and go.sum, outside of GOPATH. edit 2: It may also be worth noting the project vendors via |
We will try to add some more logging to understand better why this happens. I've never had this happen, but there seem to be quite a few people reporting that |
I can confirm that as well, even in non-go mod repos. |
Same issue for me with both modules or non-modules projects. Restarting vscode does the trick. |
Same issue for me... but restarting doesn't fix it. Nothing seems to fix it. Import organization only works like 5% of the time for me. |
For those who are having this experience, can you attach your |
If those logs include a "no room in queue" output that correlates to roughly when the problem started, then it's likely related to #32368. If so please update and report back. |
@freeformz Not in my case. Log is in original issue. |
@atombender: When you see the diagnostic from the language server that your package is not imported, can you hover over the error and see a "Quick Fix" suggestion? And if so, does it offer you the "Organize All Imports" quick fix? |
I updated yesterday and still got the no room in queue bug : [Error - 1:47:00 PM] Request textDocument/documentSymbol failed. |
Might not be related but it also doesn't work most of the time when adding a new file. [Error - 8:03:36 PM] unable to check package for [filename]: parse: no package found for [filename] Once vscode is restarted, new file is correctly recognized. |
@ericrenard: Do you mind filing separate issues for these cases? I think it will be easiest to help everyone debug their cases in separate issues - even when the bugs seem similar, they are often unrelated. |
Here's a log from a current editing session where imports aren't being reorganized. In this case, it refuses to remove unused imports after I commented out a section of code, and it's not adding a third-party import ( In this case, the "quick fix" button fixes the unused imports, whereas the "quick fix" on the "Undeclared name: gorm" error shows "No code actions available".
|
Can you try adding "editor.codeActionsOnSaveTimeout": 3000 to your VSCode configuration? The default value is |
@stamblerre That didn't help, unfortunately. I can reproduce this consistently in my project. I have a If I then undo to put back all the imports, and save, all the errors remain, even though the imports are back, and the log starts getting I can tar up the project and email it to you privately if that would help? |
@stamblerre Thanks, but I'm not seeing anything different with that setting. Gopls is still trying to format and resolve imports, and I can see things like |
Oh, I'm sorry, I forgot to mention that you would also want to set the |
|
That can't be right, that disables format-on-save altogether, even "go.formatTool": "goimports",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.codeActionsOnSaveTimeout": 30000
"go.useLanguageServer": true,
"go.languageServerExperimentalFeatures": {
"diagnostics": true,
"format": false
},
"go.languageServerFlags": [
"-trace"
] |
Yes, my apologies, I did mean "go.formatTool": "goimports", // or "goreturns", depending on your preference
"go.languageServerExperimentalFeatures": {
"format": false,
},
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": false,
}, |
Same as what I had, but I reloaded the window again (which I'd already done) and it suddenly worked, for some reason, thanks! Also, for some reason for the |
No, with these settings I'm still seeing import processing in the log, and considerable slowness:
Also seeing lines like As you can imagine, dealing with 60-second delays when saving a file and waiting for formatting to happen is painful. Killing |
Right now, it looks like Inserting some debug information, Turning the |
Sorry about spamming this issue, but there's definitely something funky going on with the VSCode Go extension. I had a file where imports were not being added, as usual. I'm running The In the meantime, I've noticed messages like this:
The file in question is a new file in a new folder that I created in VSCode, inside another package. In this new file, Gopls was completely nonfunctional until I restarted it. |
Update: I can confirm that after a while, VSCode just stops invoking |
Update: Watching the log with some patience, the above problem seems to actually be caused by Gopls blocking VSCode's execution of
(As I said before, I commented out the import organization code in Gopls to avoid the weird long stalls, so it shouldn't be doing anything here.) But It's as if Gopls is building up a queue of changes and choking on them. And this isn't like I'm a particularly fast typer or anything. It happens constantly. |
It seems like |
I didn't realize there were two code paths to import organization. Will try that, thanks. |
Still seeing the same weirdness where VSCode just stops invoking |
Change https://golang.org/cl/183718 mentions this issue: |
@ianthehat How does this fix relate to this issue? |
This issue seems to cover multiple bugs that have some symptoms in common. Most of the things in it seem to be related to gopls ceasing to communicate with the editor client, often with the no room in queue message, which should be fixed. |
That's just part of it, I think. I'd leave this issue open for now. It also relates to with the currently very slow import organization code that apparently is being rewritten. |
Re-opened to track the imports-related issues. This may be a duplicate of #32360. |
@stamblerre You said you re-opened, but it's still closed. |
This issue is outdated due to the latest changes to gopls and imports. To track issues relating to slow import organization, please follow #32750. |
This abandons the limited size queue Instead we kick a go-routine per request, but have each request wait for the previous request to say it is okay to continue. This allows each request to control when it is finished with tasks that required strict ordering without every blocking the routine that handles replies. It also protects against repeated or missing replies. Fixes golang/go#32631 Fixes golang/go#32589 Fixes golang/go#32467 Fixes golang/go#32360 Fixes golang/go#31977 Change-Id: Icd071620052351ec7f8fac136f1b8e3f97d4bb2d Reviewed-on: https://go-review.googlesource.com/c/tools/+/183718 Run-TryBot: Ian Cottrell <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
N/A, I think.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
Saved file in VSCode that contains a reference to a struct in a different package, within the same module. I expected the import to be added to
import
.What did you see instead?
Nothing was added. This usually works, but there appears to be some packages that just don't work with import organization. This works fine with Go's standard library packages as well as third-party packages.
The file is a skeleton
main.go
, where I addedsite := models.Site{}
. Themodels
package is a package inside the same module.I don't know much about gopls and how to report diagnostics, but here's the log file with RPC logging enabled: gopls.log.
The text was updated successfully, but these errors were encountered: