-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: duplicate module in workspace with experimentalWorkspaceModule #45184
Comments
Thanks for filing this issue. It looks like your Go module cache ( Also, can you please share your |
Hi @stamblerre , Yes, Thanks! |
It looks like you need to add
It is pretty atypical for the module cache to be in the workspace, so I would suggest avoiding that if at all possible. It won't work with experimental workspace module mode because you will run into this exact problem that you're seeing with the duplicate modules--experimental workspace mode does not support multiple modules with the same path and different versions in the workspace. If necessary, you can configure a module cache that is outside of your GOPATH by using the GOMODCACHE environment variable. |
@stamblerre, Please find the attachment for verbose logs. gopls-vscode-duplicate-workspace-error-logs.log On move my module cache to different path, Would I be able to copy the content from current cache and put it in different path? Or would it have to be loaded when |
I would create an empty directory that you want to use for your new module cache, set the GOMODCACHE variable to point to that directory, and then your module cache will be populated automatically whenever you build your code or open the editor. There is no need to manually populate it. |
It looks like the |
Yeah, I could see that this has been used in multiple place. I fixed it. Now, I'm seeing different issue. Below is the screenshot. These are from the GoKafka package. Should I replace the module name? I have added the filter Also, I have one another issue. When I hover on any function/variable/anything, I don't see any definition. Should I enable any specific setting to enable this? |
I believe the directory filters are actually relative to your project root, which was my mistake earlier. For the original directory filter you shared about, it should be If you want to exclude the kafka package, you will want something like |
@stamblerre , Issue after setting up the custom GOMODCACHE - I use a custom location for GOMODCACHE ( When I do Is there a way to get the modules into GOPATH instead of GOMODCACHE? Or Is there a way to make vscode to read the modules from GOMODCACHE instead of GOPATH? |
@iamshreeram: It sounds like you are still trying to operate in GOPATH mode in some way, but you are using modules (if you have a GOMODCACHE). The VS Code Go plugin uses |
@stamblerre , Thanks for prompt response. The issue is just with plugin or vscode. Below is the error when I hover on
When I build or run the code through the terminal, things go well without any errors. Any thoughts? |
It looks like |
|
I will need at least the start of the log to fully understand the issue. Where is the |
Please find the attachment for gopls-server.log. |
It doesn't seem like |
@stamblerre , Yes. Auto completion works well when I open just Attaching my vscode settings |
I'm not seeing the |
@stamblerre , with |
@iamshreeram: I'm not entirely sure what you are trying to achieve--you are trying to autocomplete something that is only in your GOPATH? You either need to operate in module mode, in which case your GOPATH does not matter, or you can switch back to GOPATH mode. Experimental workspace module mode requires you to use modules. If you have a concrete example of a problem, I will need to see a full log file and a full explanation of the issue. |
Please find the attachment for gopls-server.log. This was pulled before adding |
|
@stamblerre , Sure. Please find the attachment. |
As a datapoint I disabled experimentalWorkspaceModule because of this In my case we have a few submodules In this case goproject2 shows up twice because it is our submodule, and a submodule of a dependency we have. Admittedly it's a strange project structure but we chose it because we can craft very efficient makefiles that let us modify dependencies quickly. I wish the following statement were true: "if go build can build knows that to do with your file, then gopls can resolve the same dependencies go build will" |
@iamshreeram: Do you have many workspace folders in your workspace? I am not sure how that will play with experimentalWorkspaceModule mode. But I do see an error:
Is it possible to remove the duplicate module? @benbuzbee: Why do you need experimentalWorkspaceModule if you only have one |
Thanks for following up @stamblerre subproject1 expands to the structure i listed above. In essence, the use case is a repo with a go module and with submodules that are also go modules. Some modules may be repeated as submodules of submodules etc. My work around then is using a multi-root workspace with experimentalWorkspaceModule = false; but that has its limitations |
|
If identically named modules appear in the workspace multiple times, I am not sure how to resolve the case and choose one of them, but think the error message is correct and working as intended. |
No. We configured the GOMODCACHE environment variable earlier to handle the fact that your module cache was in your workspace. GOPATH will only be used when you are in GOPATH mode, i.e. GO111MODULE=off. The log you shared above shows that you seem to be in GOPATH mode, but it's hard to tell because you are missing |
Maybe same case here:
|
@p1gd0g: That should not happen. Please open a new issue and follow the steps here: https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#file-an-issue. |
Our organization has the same issue. Pretty similar setup as well. Any update on this? or workaround? |
The proposal for workspace mode was accepted and shipped in go1.18 #45713 This tutorial includes more information about how to use workspaces! |
Closing this as go.work is the (non-experimental) solution for multi-module workspaces. Please open a separate issue for any problems using go.work files. |
Issue
I use multi-module workspace (kinda monorepo). I'm getting below error from gopls for all the modules in pkg -
I found I have different versions of sarama. But I believe that is not causing this. because, The error is pointing all the modules. I have attached the screenshot with this for more details.
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
What did you do?
gopls
settingsWhat did you expect to see?
No errors or warnings.
What did you see instead?
Error that says
Below is the screenshot of error:
The text was updated successfully, but these errors were encountered: