-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: remove the "expandWorkspaceToModule" setting #63536
Comments
I think I have a use, but I'm not sure where to comment, so here it goes. What I'm noticing is that using neovim's lsp implementation I'm running into this issue: neovim/neovim#23291 I most recently noticed this issue after adding a
Content of
Combine this with the gopls issue with globbing seen here: #41504 We get the following behaviour:
I think this behaviour is related to this issue and the In my case I would expect Alternative behaviour could be only loading the glob for any root (sub-path) that matches a I'm all ears to hear about workarounds or solutions to my problem. |
Thanks for raising this issue, and for the detailed explanation of the performance bottleneck you're experiencing. I was unaware of that neovim issue, and will keep it in mind. I think I may not have explained clearly that the current default behavior will remain unchanged (which is I looked into your use case, and don't think that it is affected by |
I filed #63742 to follow up on the overly broad watch patterns. |
Thank you for the clarification. I think the behaviour of Since this is kind of a 2-part issue (nvim lsp watch files implementation + gopls overbroad watchfiles glob) I decided to try to change the lspconfig.gopls.setup({
on_attach = [...],
capabilities = [...],
settings = [...],
-- override root_path for issue: https://github.com/golang/go/issues/63536
root_path = function(fname)
local root_files = {
'go/go.mod', -- monorepo override so root_path is ./monorepo/go/** not ./monorepo/**
'go.work',
'go.mod',
'.git',
}
-- return first parent dir that homes a found root_file
return lspconfig.util.root_pattern(unpack(root_files))(fname) or lspconfig.util.path.dirname(fname)
end,
}) And now the number of watchfiles is back down in the ~3k instead of in the ~15k. Note: The neovim lsp watchfiles function being slow still exists, but the delay is ~20ms and not like ~20s. Alternatively users can just disable the watchfiles function entirely following steps here: neovim/neovim#23291 (comment) |
I use this setting with vscode. My work uses some fairly large mono repos with Bazel. Most of the Go parts can use the standard Go tools, but not all. I like to open just the directory I am working on (e.g. a single library, or a single main program), since then all of VSCode's search and navigation features work well, without stuff I don't care about. To be clear, the directory looks approximately like:
And I open the sub-directory within the Go module called
which as far as I understand it, should remove everything from gopls's build, but it does not seem to work. I have also tried variants that include If I set |
I have the same use case as @evanj. I use vs-code and my work uses a very large monorepo and bazel and I like to load only the service directories I care about (eg I haven't touched my config in a long time, but I distinctly remember having to add I will experiment with turning it off, since maybe the heuristics used etc have improved and report back, but I imagine it is still an issue. |
Thanks very much for the detailed feedback! I think it's probably incorrect to expand the workspace if GOPACKAGESDRIVER is set, so perhaps we can just fix the default behavior in that case. I'll investigate. |
Coming back to this, I will note that in the case @evanj is reporting it sounds like there is no GOPACKAGESDRIVER involved. It just so happens that some things still work in the absence of a bazel driver. So my comment above was misguided. After digging into this more, I've actually come to the conclusion that most of the way gopls behaves with It is still problematic to have a setting that affects gopls' core behavior so deeply (if only for the implications on test coverage), so we should still endeavor to remove this setting, but in removing it I think we should also change the default behavior. This may cause churn for users of e.g. vim or emacs clients that implicitly relied on gopls choosing the correct workspace. So perhaps we should keep this setting for one more release cycle, with a different default. |
Change https://go.dev/cl/550075 mentions this issue: |
In the above CL, I'm removing the deprecation warning, based on the feedback here. This needs more thought. Bumping any decision to [email protected]. |
@findleyr What will be the scope of functionalities supported when a user opens a directory narrower than a module boundary?
VS Code, and other traditional editors supports opening individual files without opening from a folder (e.g. by running |
@hyangah I agree that it makes sense to spell out these capabilities explicitly. The most critical implication of "workspace package" is the set of packages that are eagerly type-checked on every keystroke, for the purposes of computing diagnostics. If the user opens a narrower workspace folder with expandWorkspaceToModule=false, we won't include packages outside of this folder in the eager diagnostics, even if they are in the same module. This means that there is potentially a significant reduction in CPU while editing, but diagnostics for non-workspace packages could go stale. Consequently, we don't show diagnostics for packages outside of the workspace. With regard to other operations:
Interesting: do you know which directory is sent as workspace folder in this case? At the very least gopls will work, though it might have an undesirable scope. Fundamentally I think the argument for removing this setting is one of orthogonality. Users already have a way to specify the scope of their workspace: the workspace folder. gopls deciding on a different scope is an overlapping feature, and not obvious to the user. But I'm no longer sure what is right, so let's delay any decision. |
When I opened x/tools/cmd/godoc/main.go, I see
But this doesn't work when a file from the other directory opens from the same window (vscode reuses the current window to open a new file). gopls tries to analyze the file reported with
|
@hyangah in the absence of a preference (no workspace folder) we can continue to expand the workspace.
It will be. |
This CL rewrites various logic related to the workspace scope in terms of View root and ViewType, as defined by zero config gopls (golang/go#57979). Specifically: - viewDefinition.goCommandDir is redefined as viewDefinition.root, and no longer has any relationship to the 'expandWorkspaceToModule' setting. For all view types cases the view root is a logical root, and it is OK to run the Go command from this root. The previous semantics existed to indirectly implement 'expandWorkspaceToModule'. - expandWorkspaceToModule is reinterpreted in the workspace package algorithm. This is essentially equivalent to the previous behavior (though that is hard to see), since view.contains used the union of workspace folder and 'goCommandDir'. - FileWatchingGlobPatterns is rewritten, based on recent updates to VS Code and feedback from golang/go#63536. Notably, in module mode we need only watch active modules, which may have a significant impact on performance. More work is required to verify the new behavior, particularly on windows, but I believe the current approach is at least principled. - Fix windows file patterns to be '/'-separated, which is required by the spec. Updates golang/go#63536 Updates golang/go#57979 Fixes golang/go#63742 Change-Id: I07ac703d61467eed8f101cb123469591a58aa5a4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/550075 Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
Per the rationale provided in #57514: remove this unnecessary setting, in favor of always expanding/contracting the workspace as necessary (the current behavior with
"expandWorkspaceToModule": true
). If you need this setting, please leave a comment explaining why.The text was updated successfully, but these errors were encountered: