Skip to content

x/tools/gopls: opening a file in a filtered nested module creates an extra view #81641

Open
golang/tools
#685

Description

@davidbudnick

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.

Demo: https://github.com/davidbudnick/tools-nested-module-demo

What did you expect to see?

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.

CL: https://go.dev/cl/836465

Activity

  1. added
    ToolsThis label describes issues relating to any tools in the x/tools repository.
    goplsIssues related to the Go language server, gopls.
    on Sep 22, 2026
  2. added this to the Unreleased milestone on Sep 22, 2026
  3. gopherbot commented on Sep 22, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/836465 mentions this issue: gopls/internal/cache: honor directoryFilters in view selection

  4. madelinekalil commented on Sep 24, 2026

    @madelinekalil
    Contributor

    Thanks for the bug report and fix! Will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions