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
files: support ! exclude exceptions in files.exclude and search.exclude - #344980
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.
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
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.
Quick open and text search should find files under node_modules/@types only. This should also work when node_modules is gitignored.
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.
./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.
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]>
- 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]>
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.
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.
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]>
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.
Exclude nested query roots from outer exception runs
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.
Convert absolute exceptions to folder-relative paths
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.
- 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]>
- 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]>
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.
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #869. Implements the approach discussed in #134415.
What changed
A
!-prefixed key infiles.excludeorsearch.excludeis now an exclude exception: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.
falsein another scope to disable it.{"!*.js": true}alone has no effect. This avoids the "negations match everything" problem raised in Add!-prefix parsing to glob util #134415.falseis unchanged. It still disables a key.parseExcludeExpressionreturns exactly whatglob.parsereturns..gitignore, both forexplorer.excludeGitIgnoreand for search ignore files.!keys are ignored. They still apply when an absolute exclude pattern matches..git,.svn,.hgand.jjare not re-included or walked under an exception unless an exception names them, for example!.git/hooks.files.watcherExclude,files.readonly*,explorer.autoRevealExclude,workbench.localHistory.excludeand 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: newparseExcludeExpression, which exposesmatches,matchesExclude,isExceptedandcouldExceptionMatchBeneath.**shows every folder that could contain a match.--no-ignoreand these-gglobs:!*, 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.**, only the exceptions are whitelisted, because the whole folder has to be walked anyway.**.jsat 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.glob.evaluateExcludeTreeEntry, which decides whether an entry is excluded and whether to walk into it. This also fixesQueryGlobTester.includedInQueryignoring synchronous exclude matches when it evaluates sibling clauses asynchronously.!keys with their own description. The Settings editor andsettings.jsondiagnostics are in the follow-up Support exclude exceptions in the Settings editor and settings.json #345013.searchCompleteandtextSearchCompletenow report exception counts, andsearchCompletealso reports exception run count and time. All new fields are measurements.Known limits
**make the explorer show every folder in excluded regions, and make search walk the whole folder without ignore files.How to test
"files.exclude": { "node_modules": true, "!node_modules/@types": true }to workspace settings. In the explorer, onlynode_modules/@typesshould be visible undernode_modules, andnode_modulesshould not be dimmed.node_modules/@typesonly. This should also work whennode_modulesis gitignored.!**/node_modules/@typesand check that nestednode_modules/@typesfolders 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/@typesand 1190 ms for!**/node_modules/@types.!node_modules/@types!**/node_modules/@typesparseExcludeExpression(...).matchesis the plainglob.parseresult, 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.**: one extra run over the whole folder, including gitignored folders. This is the cost of making!**/node_modules/@typeswork whennode_modulesis gitignored. To limit the cost:.git,.svn,.hgor.jjunless an exception names them. This applies to search and the explorer, and saved about 110 ms with a 2 GB.git.settings.jsonshows an info hint on these exceptions (Support exclude exceptions in the Settings editor and settings.json #345013).unanchoredExcludeExceptionCountandexcludeExceptionTimetelemetry fields track how often this happens and what it costs.Validation
Run on the branch merged with current
main:npm run typecheck-client: passednpm run valid-layers-check: passednpm 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.{"**/node_modules": true, "!node_modules/@types": true, "!build/keep.txt": true}and a gitignoredbuild/:node_modules/@types/**andbuild/keep.txt, without dimming the folders leading to them.