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: confusing behavior when using a go.work
with duplicate module paths
#53933
Comments
Hi, could you try restarting gopls and collecting logs, as described here? |
Yes, when your source contain syntax errors, the autocompletion stops working in most cases. On your screenshot you have an error, you create a variable |
@wtask no, it's not that case. Even if I'm changing the variable name to something else, it's still not working. BTW the autocompletion and suggestion is not working on other workspaces/projects of mine. |
@findleyr I have tried also to restart gopls, but it's still not working. |
@esimov can you plesae try capturing logs? That will help us diagnose the problem. |
It's not needed to save it after renaming, it should work instantly on typing, at least it worked that way until I have encountered this problem. |
Correct, saving shouldn't matter in this case. The likely scenario is that you were broken by the upgrade to gopls@v0.9.0, but before downgrading I would like to capture logs so that we can understand the failure. |
These are the errors I'm getting: [Error - 4:48:17 PM] 2022/07/08 16:48:17 imports fixes: AllImportsFixes: found module "github.com/gorilla/websocket" twice in the workspace
file="/home/.../cache.go"
[Error - 4:48:17 PM] 2022/07/08 16:48:17 imports fixes: AllImportsFixes: found module "github.com/gorilla/websocket" twice in the workspace
file="/home/.../range_test.go"
[Error - 4:48:17 PM] 2022/07/08 16:48:17 imports fixes: AllImportsFixes: found module "github.com/gorilla/websocket" twice in the workspace
file="/home/.../range_test.go" I'm not sure why gorilla websocket is considered to be interfered with my module, since I don't use it at all. I'm using in another module, but as I mentioned I didn't had this problem before updating to the latest vscode version, so it' might be related to an issue in the latest release. |
Thank you for that. This is helpful. Are you using either a |
Yes, I do have a |
Got it. I believe I have found the bug. We are failing on some old logic for the Can you try removing all but one module from your |
I have already tried it, but the issue didn't went away. As it might help you in identifying the problem the gorilla websocket module is saved into the vendor folder, so it's not imported directly, it's loaded from the vendor folder, so this package is showing in two places, but in different vendor folders.
Note: I have replaced the actual project names. |
Are there any updates about the issue? |
I have the same issue, no auto suggestion anymore. |
This is a gopls regression that we will fix for v0.9.2, scheduled for early August (though once it is fixed you can of course rebuild gopls from master). However, I am not able to reproduce with a @dzpt thank you for the signal boost, and for sharing that this does not affect v0.8.4. Transferring to the gopls issue tracker. |
go.work
CC @hyangah |
Change https://go.dev/cl/417593 mentions this issue: |
exactly. |
Progress on this has been a bit slow because several team members have been out (myself included), but understanding and fixing this is among our top priorities. However, I am still unable to reproduce this. Given the workspace layout below, everything works fine. I have two vendored copies of "github.com/gorilla/websocket" in the workspace, and everything still works. A couple additional questions:
|
No, it's not. It's in the root directory of where my projects are located. As a side note, if I'm reverting gopls to v0.8.4 these errors are not showing anymore. Another annoying thing which is quite hard to explain is that from time-to-time the package autoimport functionality stopped working. In this case I need to run |
Since I don't reproduce this using the workspace above, I wonder if the "AllImportsFixes" error may be a red herring: that particular error should not necessarily prevent other functionality. @esimov could you please confirm the directory you open from vs code? If possible, could you (or anyone else) also please share a full log from a session that exhibits the behavior? |
EDIT: after repro'ing I can see that this doesn't yet fix the problem. |
Aha, I believe I have reproduced the behavior you are observing. Your comment about I should be able to fix this tomorrow and cut a prerelease. However, in the meantime you should be able to work around this by removing the vendored modules from your I am not sure whether this warrants an ad-hoc patch release next week, assuming the workaround above (removing the vendored modules from your |
Ok, assuming folks can confirm that updating their
So, there are many things to fix, but also I don't understand the go command behavior here. (CC @bcmills for questions about the go command behavior with respect to duplicated module paths). |
If so, I would call that a |
@findleyr in many cases I'm opting to load modules from the vendor folder, because it happens, that due to the changes occurred in the dependent packages, these are causing breaking code changes and it's quite inconvenient in many cases to update the code to the latest release. Another reason why I'm loading the module dependencies from the vendor folder is missing or incomplete functionalities which could be extended to my own needs. What is strange is that gopls is complaining about the same module is loaded twice, but from different vendor folder. |
go.work
go.work
with duplicate module paths
@esimov there can only be one module per module path in a As a corollary: vendoring does not work as expected when using go.work. In the future, the To work on two different copies of a module, open two separate VS Code workspace folders using different This is a confusing UX. We'll use this issue to track improving that experience in gopls. |
That wouldn't be a problem until the desired functionality is not affected (a possible side effect would be using different versions of the same package as vendored modules).
That's not quite user friendly in my opinion, but I can live with it if we don't have a better approach. |
My understanding is that vendored modules aren't complete copies of the original modules. They contain only packages required for the main module. When a workspace containing module |
When a go.work file fails to validate, the workspace is left in an invalid state: we will detect that the workspace is defined by the go.work, but will not actually parse any active modules. This should be a critical error. Fix this by adding allowing the workspace to surface critical errors via a new cache.workspace.criticalError method. Additionally: - only build the workspace mod file in workspace.build if the mode is fileSystemWorkspace (in all other modes the modfile is already determined) - rename workspace.invalidate to workspace.Clone, to be consistent with other data structures - rename CriticalError.DiagList to CriticalError.Diagnostics - add several TODOs for observations while reading the code - create a new file for regtests related to broken workspaces - make the regtest sandbox panic when duplicate paths are present in the sandbox file set (an error I made while writing the test) Updates golang/go#53933 Change-Id: If8625ab190129bc9c57e784314bc9cc92644c955 Reviewed-on: https://go-review.googlesource.com/c/tools/+/417593 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Findley <rfindley@google.com>
Closing as I think the "confusing" bit of this should hopefully be resolved by the new error message. Opened #54261 for generally improving the experience of working on packages outside the workspace. |
A new gopls has been released but unfortunately the issue I have mentioned related to the autocompletion shown in the snapshot is still not fixed. |
@esimov the fix here was to make it an error when there are duplicate module paths in modules in your go.work file. We do not plan to change the restriction that there can only be one module per module path in your go.work: this is fundamental to the design of go workspaces. #54261 tracks improving the user experience such that some features will still work even if the go.work file is broken. |
As a follow up, I'm sorry to say, but unfortunately the last gopls version which is working with the above described configuration and project settings is v0.8.4. I was waiting to show up v0.9 and later on v0.10, but none of them are working: the autocompletion is broken completely. |
What version of Go, VS Code & VS Code Go extension are you using?
Version Information
go version
to get version of Go from the VS Code integrated terminal.gopls -v version
to get version of Gopls from the VS Code integrated terminal.code -v
orcode-insiders -v
to get version of VS Code or VS Code Insiders.Share the Go related settings you have added/edited
Describe the bug
I'm working on a WSL environment and Vscode suddenly stopped showing the suggestions and the code autocompletion functionality has stopped working too. I've tried reinstalling the Go tools by pressing
CTRL+Shift+P
and selectingGo: Install/Update Tools
. I ran also thego mod tidy
command to update the required packages. Another attempt was to executego work use -r ./
, because this helped in this case golang/vscode-go#2259, but didn't helped here. Instead I was getting something like in the snapshot below:The package autoimport also is not working anymore. I'm out of ideas what else could I try.
The text was updated successfully, but these errors were encountered: