-
Notifications
You must be signed in to change notification settings - Fork 728
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
Enhance go.mod resolution to look at all parent folders between a .go file and project root. #2249
Comments
I thought the go language server works if there is only one single subdirectory in the workspace with @james-lawrence If you are using go1.18+, you may be interested in configuring I proposed #2132 to automate handling of |
@hyangah go.work solves a different problem. this is about resolving go.mod correctly for any given go file open by the editor. |
@hyangah yes gopls will narrow the workspace to a single module if it exists, but if two modules exist in subdirectories then it doesn't know what to do, because it doesn't know how to construct the build list. @james-lawrence there is a long history here, and this is not as trivial as it may seem at first. Suppose I open moduleA/a.go and moduleB/b.go in my workspace. Now suppose both moduleA and moduleB depend on a (different!) version of moduleC. If you jump to definition from moduleA->moduleC and moduleB->moduleC, would you expect to go to the same place, or different places? If you answer 'the same place', then gopls has (for now) a way to do what you want: So the solution is to create a |
@findleyr current open buffer is the correct solution here. vscode gives plugins enough information to find the correct go.mod file to use based on the current file. I understand it may be difficult for this project; but the underlying solution to the problem is fairly trivial. |
@james-lawrence agreed. We want to change this behavior. |
The future version of gopls will offer the zero-config gopls workspace feature. That implements various heuristics to infer the right workspace folder. One of the scenarios it's targeting is exactly this. |
Is your feature request related to a problem? Please describe.
Yes. I'm always frustrated when I'm working on a .go file and because I open vscode in the directory above the directory the go.mod file exists. none of the tooling works because the plugin thinks its not in a go project.
Describe the solution you'd like
the plugin should resolve the go.mod file by checking the parent files of the file being operated on.
Describe alternatives you've considered
none really, I've solved the same issue for a tool called hover resolving the pubspec file.
The text was updated successfully, but these errors were encountered: