-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
UPDATE: The summary of the accepted proposal at: #42965 (comment).
Problem
For non-trivial (often multi-language) projects it's often desirable to make all the Go tools (including gopls
) ignore certain directories.
Some of the examples could be the huge amount of files within node_modules
, or bazel-*
directories generated by Bazel. This causes many operations with ./...
wildcards taking longer than desired. Also gopls
often eats up a lot of CPU in VS Code depending on what you are doing.
Prior Art
This is something that has been discussed in several issues before, but seems like people couldn't get agree on a solution.
- proposal: cmd/go: ignore directories containing
.goignore
in file scans #30058 - x/tools/imports: should not scan bazel-out directories #35914
- x/tools/gopls: add a setting to ignore certain directories #42473
Some tools started to have their own solutions which causes fragmentation and is cumbersome.
For example goimports
have its own machinery for this - .goimportsignore
file in this case. But it's not working with Go Modules.
Other tools have a hard-coded list of directories to ignore, like .git
and so on.
It seems like having a global solution that all the Go ecosystem could understand would make sense to solve this kind of problem.
Recently a workaround for this was to place a dummy go.mod
file in the directories you wanted to ignore. But this is not easily portable between users of the project, because often these directories can be re-created on the user's machine and aren't even checked-in. Asking people to sprinkle some go.mod
files all around every time is cumbersome.
@robpike was against of creating more dot files (#30058 (comment)).
Proposed Solution
Here're some of the options that this could be implemented with.
Use(Rejected becausego.mod
file for specifying directories to ignore.go.mod
is not a catch-all config file likepackage.json
in NodeJS).Use a separate(This would go against Rob's desire to avoid new dot files, and although being in the spirit with other tools:.goignore
file..dockerignore
,.gitignore
,.bazelignore
, etc. is concerning. The concerns are discussed in this thread).- Use the
go.work
file that's coming in the next Go 1.18 release. - Have a separate
go.ignore
file that would specify directories to ignore.
/cc @tj @stamblerre
Metadata
Metadata
Assignees
Labels
Type
Projects
Status