-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: support matching directories at arbitrary depth using the directoryFilters setting #46438
Comments
In the somewhat related #41504 (comment) I suggested using the |
/cc @heschi here for input, since he designed this feature |
As you say, it's moot now, but FWIW I think using I'm in favor of using |
Change https://golang.org/cl/347297 mentions this issue: |
It is unlikely that users want gopls operating on their node_modules directories, so we should exclude them by default. If a user wants to include them, they can override their directory filters setting. This doesn't exclude *any* directory named "node_modules", so we still need to implement golang/go#46438 to exclude node_modules completely. Change-Id: I03c42208e62390dc35e44ac5176422ddf8dc53f7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/347297 Trust: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org>
Let's use |
@adonovan the main motivation of this issue is to specify rules like "exclude any directory that has name 'node_modules'" (e.g. This is more about file paths, rather than package paths, and is more about editor settings, rather than go build setting. I wonder why we want to invent our own wheel instead of already widely used glob patterns, |
I think Dylan was concerned that |
Change https://go.dev/cl/414317 mentions this issue: |
Change https://go.dev/cl/417588 mentions this issue: |
…t arbitrary depth. In FilterDisallow, change filter to regex form to match with file paths. Add a unit regtest for FilterDisallow. For golang/go#46438 Change-Id: I7de1986c1cb1b65844828fa618b72b1e6b76b5b9 Reviewed-on: https://go-review.googlesource.com/c/tools/+/414317 Run-TryBot: Dylan Le <dungtuanle@google.com> Reviewed-by: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Change https://go.dev/cl/420959 mentions this issue: |
@dle8 Thanks very much for your work on this! Should there be a doc update reflecting the change? Should we change the default value of |
@cespare raises good points, thanks. IMO, the answer to both questions is "yes" :) |
Change https://go.dev/cl/422356 mentions this issue: |
…efault value Add `**` usage to directoryFilters documentation. Change directoryFilters default value to `-**/node_modules` For golang/go#46438 Change-Id: I3ea14ad8a20893d19df4cf8d584a7c7f9b213aab Reviewed-on: https://go-review.googlesource.com/c/tools/+/422356 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
Based on dle8's CL 414454, wire in directoryFilters into the goimports ModuleResolver scan. A few changes/fixes/additions from that CL: - Fix a bug in filter validation that was causing -**/a not to validate. - Fix a bug in regex building where -a was not treated as an excluded prefix (it was matching 'a' anywhere). - Use absolute paths in the SkipPathInScan, so that we can evaluate directory filters relative to the workspace folder. - Add several regression tests. - Consolidate directoryFilters regression tests under a new directoryfilters_test.go file. - Add several TODOs. Fixes golang/go#46438 Change-Id: I55cd3d6410905216cc8cfbdf528f301d67c2bbac Reviewed-on: https://go-review.googlesource.com/c/tools/+/420959 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Le <dungtuanle@google.com>
I have some very large
node_modules
trees that cause gopls to fail. The recently-addeddirectoryFilters
configuration setting is a partial workaround for this, but the paths it accepts are always interpreted relative to the workspace root.There are multiple large
node_modules
directories in my workspace and the set might change in the future. I don't want to keepdirectoryFilters
in sync with this. Instead, I want to globally ignorenode_modules
directories everywhere, in all workspaces, forever. But there doesn't seem to be any way to specify an unrooted path indirectoryFilters
.I suggest adding a way to do this. One question is the syntax to use. If we were designing this from scratch, perhaps a rooted path (
-/myproj/node_modules
) could indicate workspace-relative and unrooted path (-node_modules
) could indicate "match this directory at any depth". (This would be similar to how, for example, gitignore works.)But since that option is foreclosed at this point, here are some other ideas to get us started. A leading
*
could be used to indicate "match at any depth":-*/node_modules
. That resembles, yet is confusingly different from, shell glob syntax, so perhaps*
could mean "match any single directory" and**
could mean "match any depth"; then I could use-**/node_modules
.The text was updated successfully, but these errors were encountered: