Skip to content

files: support ! exclude exceptions in files.exclude and search.exclude - #344980

Merged
Logan Ramos (lramos15) merged 11 commits into
mainfrom
agents/vscode-negated-globs-explanation
Oct 30, 2026
Merged

Logan Ramos (lramos15) merged 11 commits into
mainfrom
agents/vscode-negated-globs-explanation

Conversation

@lramos15

@lramos15 Logan Ramos (lramos15) commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Fixes #869. Implements the approach discussed in #134415.

What changed

A !-prefixed key in files.exclude or search.exclude is now an exclude exception:

"files.exclude": {
  "node_modules": true,
  "!node_modules/@types": true // shown, including everything inside it
}

Rule: a path is excluded if it, or one of its parent folders, matches an exclude pattern, and neither the path nor any parent folder matches an exception.

  • Order doesn't matter. Settings scopes merge as before, and an exception key can be set to false in another scope to disable it.
  • Exceptions only show things. They never add exclusions, so {"!*.js": true} alone has no effect. This avoids the "negations match everything" problem raised in Add !-prefix parsing to glob util #134415.
  • false is unchanged. It still disables a key.
  • No exceptions, no change. parseExcludeExpression returns exactly what glob.parse returns.
  • Exceptions override .gitignore, both for explorer.excludeGitIgnore and for search ignore files.
  • Exceptions are relative to the folder. Absolute ! keys are ignored. They still apply when an absolute exclude pattern matches.
  • Version control folders stay excluded. .git, .svn, .hg and .jj are not re-included or walked under an exception unless an exception names them, for example !.git/hooks.
  • Only these two settings are affected. files.watcherExclude, files.readonly*, explorer.autoRevealExclude, workbench.localHistory.exclude and the extension API keep treating ! literally. Exclude patterns from the search view input and from the API are escaped to {!}.

Where it applies

  • glob.ts: new parseExcludeExpression, which exposes matches, matchesExclude, isExcepted and couldExceptionMatchBeneath.
  • Explorer: shows excepted items and the folders that lead to them. Those folders are not dimmed. An exception that starts with ** shows every folder that could contain a match.
  • Search, Node (ripgrep): ripgrep cannot express exceptions and does not descend into excluded folders. After the normal run, the file and text engines run ripgrep once more per folder, with --no-ignore and these -g globs:
    • !*, then folder-only globs for the folders that lead to each exception (for example /node_modules/), then the exceptions themselves. Only those folders are walked.
    • If an exception starts with **, only the exceptions are whitelisted, because the whole folder has to be walked anyway.
    • The results are checked against the exceptions with VS Code's glob matcher, because ripgrep globs can match more (ripgrep matches **.js at any depth). Results already reported by the normal run are skipped, the query's includes are applied, and folders of the query that are inside the searched folder are skipped.
  • Tree walks, everywhere else: the explorer, breadcrumbs, the web-worker search, the file-system provider search, the file walkers and the Agents window file search all share glob.evaluateExcludeTreeEntry, which decides whether an entry is excluded and whether to walk into it. This also fixes QueryGlobTester.includedInQuery ignoring synchronous exclude matches when it evaluates sibling clauses asynchronously.
  • Extension search providers receive the same excludes as today, without exceptions, so exceptions aren't honored there yet.
  • Other readers of these settings: the Problems view and quick open history.
  • Settings: the schemas for both settings accept ! keys with their own description. The Settings editor and settings.json diagnostics are in the follow-up Support exclude exceptions in the Settings editor and settings.json #345013.
  • Telemetry: searchComplete and textSearchComplete now report exception counts, and searchComplete also reports exception run count and time. All new fields are measurements.

Known limits

  • No re-excluding inside an exception. That needs ordered rules, which settings objects can't express.
  • Exceptions starting with ** make the explorer show every folder in excluded regions, and make search walk the whole folder without ignore files.

How to test

  1. Add "files.exclude": { "node_modules": true, "!node_modules/@types": true } to workspace settings. In the explorer, only node_modules/@types should be visible under node_modules, and node_modules should not be dimmed.
  2. Quick open and text search should find files under node_modules/@types only. This should also work when node_modules is gitignored.
  3. Replace the exception with !**/node_modules/@types and check that nested node_modules/@types folders are found too.

Performance

Measured on this repo (about 21k files, gitignored node_modules), median of 7 warm runs with the built-in ripgrep engines. The extra runs were measured again for the single run per folder: 8 ms for !node_modules/@types and 1190 ms for !**/node_modules/@types.

Configuration File search Text search
Default excludes, no exceptions 164 ms 944 ms
!node_modules/@types 170 ms (extra run: 8 ms) 931 ms
!**/node_modules/@types 1210 ms (extra run: 1035 ms) 1208 ms
  • No exceptions: no change. parseExcludeExpression(...).matches is the plain glob.parse result, ripgrep runs once with the same arguments, and no deduplication set is created. Micro-benchmark: 25.1 vs 25.7 ms per 10k parses of the default excludes; identical matching speed over 200k paths.
  • Exceptions with a folder path: one extra ripgrep run that only walks the folders leading to the exceptions.
  • Exceptions starting with **: one extra run over the whole folder, including gitignored folders. This is the cost of making !**/node_modules/@types work when node_modules is gitignored. To limit the cost:
    • Exceptions don't look into .git, .svn, .hg or .jj unless an exception names them. This applies to search and the explorer, and saved about 110 ms with a 2 GB .git.
    • settings.json shows an info hint on these exceptions (Support exclude exceptions in the Settings editor and settings.json #345013).
    • The unanchoredExcludeExceptionCount and excludeExceptionTime telemetry fields track how often this happens and what it costs.
  • Memory: only paths that match an exception are kept for deduplication.

Validation

Run on the branch merged with current main:

  • npm run typecheck-client: passed
  • npm run valid-layers-check: passed
  • npm run eslint -- <changed files>: passed
  • ./scripts/test.sh --runGlob "**/{base/test/common/glob,workbench/test/common/resources,services/search/test/**/*,contrib/search/test/**/*,contrib/files/test/**/*,contrib/markers/test/**/*,services/history/test/**/*,api/test/node/extHostSearch}.test.js": 615 passing, 4 pending
  • ./scripts/test-integration.sh --run src/vs/workbench/services/search/test/node/{fileSearch,textSearch,search,rawSearchService}.integrationTest.ts: 100 passing. These run real ripgrep and cover exceptions, .gitignore, nested roots, folder includes, existence queries, result limits, casing, symbolic links, .. segments, nested folders with different casing, and exception results that ripgrep matches but VS Code globs don't.
  • The regression tests for the review findings fail without the fixes and pass with them. A second review by GPT-6 Astra and Claude Opus 5.5 found no remaining issues.
  • Manual check in a Code OSS build with {"**/node_modules": true, "!node_modules/@types": true, "!build/keep.txt": true} and a gitignored build/:
    • Explorer: shows only node_modules/@types/** and build/keep.txt, without dimming the folders leading to them.
    • Quick open and text search: find only the excepted files.
    • Settings changes: disabling and re-enabling the exception updates the explorer without a reload.
  • CI: passed on Windows, macOS and Linux for the previous commit.
  • Not run: remote or virtual workspaces.

A `!`-prefixed key in files.exclude or search.exclude now marks an exception: matching paths and everything inside them are not excluded, even when another pattern or .gitignore excludes them. Exceptions never add exclusions and do not depend on key order, so settings scopes still merge as before, and `false` keeps disabling a key. Expressions without exceptions parse exactly as before.

The explorer shows the folders that lead to an exception, search re-includes excepted paths with an extra ripgrep run per exception root, and the Settings editor gains an Add Exception action plus a quick fix for `"pattern": false` entries that disable nothing. Other glob settings and the extension API keep treating `!` literally.

Fixes #869

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 14:48
- Do not let exception-run text matches that are filtered out use up the result limit
- Evaluate web search excludes once, with folder exceptions, instead of re-checking global excludes per file
- Treat brace alternatives with a path separator as variable length when pruning folders
- Apply absolute exceptions that start with the searched folder in ripgrep runs and in the post-filter
- Do not infer existence from the exit code of an exception run
- Keep exceptions relative in the breadcrumbs picker
- Resolve exception run roots to their casing on disk and skip roots that pass through a symbolic link when links are not followed
- Only remember excepted paths of the main ripgrep run for deduplication, and avoid repeated configuration lookups in settings.json diagnostics

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved exception-matching and search-filtering defects can hide eligible files and produce incorrect results, while settings handling can generate duplicate keys and misleading labels.

12 open issues
What changed in this PR

Adds order-independent ! exceptions to files.exclude and search.exclude, addressing #869 using the approach discussed in #134415. The change connects exception matching to Explorer, built-in search, and related file-filtering features.

Changes:

  • Adds exception-aware glob parsing and traversal, plus additional ripgrep runs for excluded or ignored paths.
  • Adds settings descriptions, an Add Exception button, and a Convert to Exception quick fix.
  • Adds regression tests and search telemetry for exception usage and execution costs.
File Description
src/​vs/​workbench/​test/​common/​resources.test.ts Tests exception-aware resource matching.
src/​vs/​workbench/​services/​search/​worker/​localFileSearch.ts Adds exception-aware worker traversal.
src/​vs/​workbench/​services/​search/​test/​node/​textSearch.integrationTest.ts Tests text search exceptions and ignored files.
src/​vs/​workbench/​services/​search/​test/​node/​ripgrepTextSearchEngineUtils.test.ts Tests exception-run arguments.
src/​vs/​workbench/​services/​search/​test/​node/​ripgrepSearchUtils.test.ts Tests exception grouping and relative roots.
src/​vs/​workbench/​services/​search/​test/​node/​fileSearch.integrationTest.ts Tests file search recovery, includes, and nested roots.
src/​vs/​workbench/​services/​search/​test/​common/​search.test.ts Tests query filtering, provider patterns, and counts.
src/​vs/​workbench/​services/​search/​test/​common/​fileSystemFileSearchProvider.test.ts Tests exception-aware filesystem traversal.
src/​vs/​workbench/​services/​search/​test/​browser/​queryBuilder.test.ts Tests literal ! escaping outside settings.
src/​vs/​workbench/​services/​search/​node/​ripgrepTextSearchEngine.ts Adds text search exception runs and deduplication.
src/​vs/​workbench/​services/​search/​node/​ripgrepSearchUtils.ts Plans exception runs from literal prefixes.
src/​vs/​workbench/​services/​search/​node/​ripgrepSearchProvider.ts Declares built-in exception support.
src/​vs/​workbench/​services/​search/​node/​ripgrepFileSearch.ts Builds ripgrep arguments for exception runs.
src/​vs/​workbench/​services/​search/​node/​fileSearch.ts Coordinates extra runs, filtering, and timing.
src/​vs/​workbench/​services/​search/​common/​textSearchManager.ts Passes exceptions to supporting providers.
src/​vs/​workbench/​services/​search/​common/​searchService.ts Reports exception telemetry measurements.
src/​vs/​workbench/​services/​search/​common/​searchExtTypesInternal.ts Defines internal exception-support contracts.
src/​vs/​workbench/​services/​search/​common/​search.ts Adds shared exception filtering and counting.
src/​vs/​workbench/​services/​search/​common/​queryBuilder.ts Escapes non-setting exclusion patterns.
src/​vs/​workbench/​services/​search/​common/​fileSystemFileSearchProvider.ts Traverses excluded ancestors toward exceptions.
src/​vs/​workbench/​services/​search/​common/​fileSearchManager.ts Updates provider exclusions and inherited filtering.
src/​vs/​workbench/​services/​history/​browser/​historyService.ts Uses exception-aware quick-open history filtering.
src/​vs/​workbench/​contrib/​search/​browser/​search.common.contribution.ts Documents and validates search exceptions.
src/​vs/​workbench/​contrib/​preferences/​test/​browser/​settingsWidgets.test.ts Tests the Add Exception interaction.
src/​vs/​workbench/​contrib/​preferences/​test/​browser/​preferencesRenderers.test.ts Tests diagnostics and conversion edits.
src/​vs/​workbench/​contrib/​preferences/​browser/​settingsWidgets.ts Adds exception input and descriptive labels.
src/​vs/​workbench/​contrib/​preferences/​browser/​settingsTree.ts Enables exception controls for supported settings.
src/​vs/​workbench/​contrib/​preferences/​browser/​preferencesRenderers.ts Adds ineffective-override diagnostics and conversion.
src/​vs/​workbench/​contrib/​markers/​test/​browser/​markersFilterOptions.test.ts Tests Problems view exception matching.
src/​vs/​workbench/​contrib/​markers/​browser/​markersFilterOptions.ts Applies exceptions to Problems filtering.
src/​vs/​workbench/​contrib/​files/​test/​browser/​explorerFilesFilter.test.ts Tests Explorer visibility along exception paths.
src/​vs/​workbench/​contrib/​files/​browser/​views/​explorerViewer.ts Preserves exception paths through excluded folders.
src/​vs/​workbench/​contrib/​files/​browser/​files.contribution.ts Documents and validates file exceptions.
src/​vs/​workbench/​common/​resources.ts Adds an exception-aware resource matcher.
src/​vs/​workbench/​browser/​parts/​editor/​breadcrumbsPicker.ts Integrates exceptions into breadcrumb filtering.
src/​vs/​sessions/​contrib/​editor/​browser/​emptyFileEditorSearch.ts Applies exceptions to Agents window file traversal.
src/​vs/​base/​test/​common/​glob.test.ts Tests exception semantics and traversal checks.
src/​vs/​base/​common/​glob.ts Implements exception parsing and matching helpers.

Review effort: Balanced

Comment thread src/vs/base/common/glob.ts Resolved
Comment thread src/vs/workbench/common/resources.ts Resolved
Exceptions no longer look into version control folders such as .git unless an exception names them, in search runs and in the explorer, and settings.json flags exceptions that make search walk the whole folder.

Co-authored-by: Copilot <[email protected]>
- Keep files below excluded folders hidden in the breadcrumbs picker when it shows a folder that leads to an exception
- Apply relative and absolute exceptions in the quick open history matcher, whichever path the exclude matched
- Do not offer converting a false pattern into an existing exception key, and inspect local and remote user settings separately
- Only describe ! patterns as exceptions in the Settings editor for settings that support them
- Resolve exception run roots case-insensitively when globs ignore case, starting from the closest unambiguous folder
- Treat an absolute exception for the searched folder itself as the whole folder

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Exception searches can return files outside the requested root and bypass the default 20,000-match limit without reporting limitHit.

3 open issues
3 previously missed issues

In code that hasn't changed since last review

Medium severity Preserve ancestor exceptions for nested search roots

src/​vs/​workbench/​services/​search/​common/​search.ts:749

An absolute exception naming an ancestor of the search root is discarded here: !/workspace/allowed should also cover a search rooted at /workspace/allowed/subproject. Both QueryGlobTester and ripgrep exception runs then lose the exception, hiding files when a search is narrowed to that subfolder or it becomes a nested workspace root. Recognize roots already covered by the exception before trying to strip the root prefix.

Medium severity Exclude nested query roots from outer exception runs

src/​vs/​workbench/​services/​search/​node/​ripgrepTextSearchEngine.ts:65

With query roots /workspace and /workspace/node_modules/@types, excluding node_modules and excepting !node_modules/@types lets the outer exception run and the nested root's normal run report the same text matches. This per-folder deduplication set cannot remove those duplicates, which TextSearchManager accepts and counts toward the result limit. Exclude nested query roots from the outer exception run, as file search already does.

Medium severity Convert absolute exceptions to folder-relative paths

src/​vs/​workbench/​services/​search/​worker/​localFileSearch.ts:181

For a query rooted at /workspace, { 'node_modules': true, '!/workspace/node_modules/@types': true } prunes node_modules because this walker compares the unchanged absolute exception against folder-relative paths. Neither web-worker file search nor text search can then return the excepted files. Apply the same folder-relative exception conversion used by QueryGlobTester before parsing these expressions.

12 resolved since last review

Review effort: Balanced

Comment thread src/vs/base/common/glob.ts Resolved
- Search the paths that exceptions re-include with a single pruned ripgrep
  run per folder (`-g '!*'` plus the path components of each exception)
  instead of one run per literal prefix, which removes root resolution for
  casing, symbolic links and missing folders
- Share one tree walk helper, `evaluateExcludeTreeEntry`, between the
  explorer, breadcrumbs, file walkers and search providers
- Only support folder-relative exceptions; absolute `!` keys are ignored
- Move the Settings editor and settings.json changes to a follow-up PR

Co-authored-by: Copilot <[email protected]>
Whitelisting the folders that lead to an exception with globs such as
`**` listed every file, so a text search read all files when an exception
starts with `**`. Folders that lead to an exception now use folder-only
globs, and runs for exceptions that can match at any depth only whitelist
the exceptions.

Co-authored-by: Copilot <[email protected]>
- Limit accepted text search results to the default limit when the query
  does not specify one, so results of exclude exception runs, which are not
  limited by ripgrep, stay bounded and report `limitHit`
- Expand brace groups when finding the version control folders that an
  exception names, so `!{.git,.hg}/hooks` looks into both folders
- Test that exceptions with a `..` segment do not search outside the folder

Co-authored-by: Copilot <[email protected]>
…-globs-explanation

# Conflicts:
#	src/vs/workbench/test/common/resources.test.ts
- Check text search results of the exception run against the exceptions,
  because ripgrep globs can match more than VS Code globs (`**.js`), and
  skip folders of the query that are inside the searched folder, as file
  search does
- Keep version control folders excluded under an exception unless an
  exception names them, so the explorer and the JS search paths agree
  with ripgrep
- Traverse folders for exceptions with a globstar inside braces, such as
  `{**,foo}/keep.txt`
- Apply folder-relative exceptions when an absolute exclude pattern
  matches in quick open history
- Record the exclude exception time before the search completes

Co-authored-by: Copilot <[email protected]>
- Only traverse every folder for a brace alternative that is a globstar,
  such as `{**,foo}`; `**` within a segment, as in `**.js`, matches a
  single segment
- Find the folders of a text query that are inside a folder with the
  glob case setting, as file search does, so differently cased nested
  folders are skipped by the exclude exception run

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active issues leave case-insensitive ignore exceptions inconsistent across glob matching and search filtering, while Explorer Find incorrectly excludes directories containing excepted files.

3 open issues
3 resolved since last review

Review effort: Balanced

Comment thread src/vs/base/common/glob.ts Resolved
Explorer Find dropped folder hits that `.gitignore` hides even when the
explorer shows them because an exclude exception matches beneath them.

Co-authored-by: Copilot <[email protected]>
@lramos15
Logan Ramos (lramos15) marked this pull request as ready for review October 30, 2026 15:10
@lramos15
Logan Ramos (lramos15) merged commit f85fab9 into main Oct 30, 2026
55 checks passed
@lramos15
Logan Ramos (lramos15) deleted the agents/vscode-negated-globs-explanation branch October 30, 2026 16:33
@vs-code-engineering vs-code-engineering Bot added this to the 1.145.0 milestone Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exclude all files except for...

3 participants