You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
x/tools/gopls: opening a file in a filtered nested module creates an extra view #81641
gopls builds an extra view when a file is opened inside a nested module that directoryFilters already excludes. The new view's root sits inside the excluded directory, so the view filters itself out. Each such module adds another view, and memory climbs with them. This shows up with git worktrees excluded by directoryFilters, and with other nested modules under an excluded directory.
What version of Go are you using (go version)?
go version go1.26.0 darwin/arm64
gopls v0.23.0 and current master both create the extra view.
What operating system and processor architecture are you using?
darwin/arm64
What did you do?
The workspace contains a nested module under a directory listed in directoryFilters. For example, other/ is its own module and the gopls settings are:
"directoryFilters": ["-other"]
Open other/main.go.
The same shape happens with a worktree excluded by directoryFilters (for example -.worktrees). That checkout is a second copy of the module. Opening a file there still creates a view. A root go.work does not cover the worktree, because go work rejects the duplicate module path.
One view, rooted at the workspace folder. The filtered module is not loaded.
What did you see instead?
selectViewDefs ignores directoryFilters. The open file is not covered by the workspace view, because that view excludes the directory, so gopls defines a new view rooted at the nested module. That view uses the same filters and excludes its own root.
The demo's load test, one didOpen per nested module under an excluded directory, reports master growing to one view per module (1001 views at 1000 modules) while a build that skips those URIs stays on one view. Memory and gopls.views latency follow the view count. Numbers are in the demo README.
Proposed fix
Skip URIs excluded by the workspace folder's directoryFilters before defining a view. In DidModifyFiles, drop modifications for those URIs before overlays are updated, so the filtered files are not tracked.
Activity
gopherbot commentedon Sep 22, 2026
Change https://go.dev/cl/836465 mentions this issue:
gopls/internal/cache: honor directoryFilters in view selectiongabyhelp commentedon Sep 22, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
madelinekalil commentedon Sep 24, 2026
Thanks for the bug report and fix! Will take a look.