Skip to content
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

Is it possible that we have a parameter in settings to allow user specify the sub-directory as root of Go project #2967

Open
sillydong opened this issue Sep 11, 2023 · 6 comments
Labels
gopls/workspace workspace setup related issues (UX of multi-modules, nested modules, GOPATH handling) Question This is a question, rather than an issue report. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@sillydong
Copy link

Is your feature request related to a problem? Please describe.

image

We always see such message if we open a repo and go.mod is not under the root directory of that repo. I tried the build.expandWorkspaceToModule setting, it does not recognize the sub-directory contains go.mod even it is the only sub-directory which contains go.mod file.

Describe the solution you'd like

Provide a setting to allow user specify the sub-directory as root directory and pass it to go plugins.

Describe alternatives you've considered

I tried build.expandWorkspaceToModule but not helping.

Additional context
Add any other context or screenshots about the feature request here.

@gopherbot gopherbot added this to the Untriaged milestone Sep 11, 2023
@hyangah
Copy link
Contributor

hyangah commented Sep 11, 2023

@sillydong Have you tried Go workspace https://go.dev/blog/get-familiar-with-workspaces ?
When you work with multiple modules at the same time or have a go module somewhere nested under the VS Code workspace, create a go.work file and tell the language server (gopls) the module location.

We hope that a future version of the language server (gopls) will handle this somewhat automatically (golang/go#57979) but until then, go.work is the best option I am aware of.

@hyangah hyangah added gopls/workspace workspace setup related issues (UX of multi-modules, nested modules, GOPATH handling) Question This is a question, rather than an issue report. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Sep 11, 2023
@sillydong
Copy link
Author

It's just when I use go.work, I found it cannot recognize the vendor directory under the module. Even though all deps are vendored in the module directory, it queries and downloads packages from network and there will be error like tidy: diagnosing file://{filepath}/go.mod err: exit status 1: stderr: go: downloading {package}. When I open the module directory as root directory, it can recognize the vendor and parse it in right way.

@sillydong
Copy link
Author

sillydong commented Oct 7, 2023

Like build.expandWorkspaceToModule's behavior, it will detect parent directory and children directories. If there is exactly one child directory containing a go.mod file, narrowing the scope to that directory if it exists. We can see from gopls' output go dir <some directory>. If the repo contains multiple go.mod files, gopls could not determine which directory to use and then errors occur in OUTPUT. The directory it detects fits the vendor well. So is it reasonable to provide a way to set that value manually?

@hyangah
Copy link
Contributor

hyangah commented Oct 12, 2023

How many subdirectories contain go.mod files? Gopls should recognize a module in the subdirectory if there is only one module. (I just verified it is still working) If it fails, I am afraid that implies there are multiple modules underneath. In that case, users will encounter the same issue as soon as they open a file outside the current module boundary.

golang/go#57979 work is underway - which detects module roots automatically. Can we wait for it instead of adding one more configuration which eventually will not be needed and confuse users for longer time?

@sillydong
Copy link
Author

Like I said in #2967 (comment), the directory contains multiple subdirectory that contains go.mod, so I'm hoping if we can allow user to manually set a value for gopls to use in go dir <some directory>

Also I have tried go.work, but it keeps querying for packages even when I have all deps in vendor directory. This cause the workspace to error everywhere.

I will wait and see if golang/go#57979 can fix the situation. Thanks for sharing this info.

@cletter7
Copy link

Hello @hyangah, could you share if there is any timeline for the golang/go#57979? I have a similar issue (described here). Just want to understand when is the feature expected. Or maybe there is some workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/workspace workspace setup related issues (UX of multi-modules, nested modules, GOPATH handling) Question This is a question, rather than an issue report. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants