Quick Open: match queries with leading workspace folder name#318517
Open
yogeshwaran-c wants to merge 1 commit into
Open
Quick Open: match queries with leading workspace folder name#318517yogeshwaran-c wants to merge 1 commit into
yogeshwaran-c wants to merge 1 commit into
Conversation
…-root workspaces Fixes microsoft#208840 In a multi-root workspace (or any workspace whose folder name/basename differs from its path), typing a fully-qualified relative path such as `workspace_1/test_file.txt` or `Source/main.py` would return no results from Quick Open's file picker. `getRelativePathFileResults` resolved each query against every workspace folder by calling `folder.toResource(query.original)`, which produced `<folderUri>/workspace_1/test_file.txt` -- a path that does not exist when the workspace folder itself is `workspace_1`. Add a second resolution attempt that strips a leading path segment when it matches the workspace folder's `name` or the basename of its URI (case-insensitively). Results are de-duplicated through a `ResourceMap` so a file that matches both the original and the stripped query is only returned once. This addresses the common case of pasting paths from GitHub diffs or other multi-root checkouts where the first segment is the workspace folder name.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support in the "Go to File" / anything quick access for queries that begin with a workspace folder's name or basename (e.g. folderName/path/to/file.txt), by stripping that leading segment and re-resolving relative to the folder. Also deduplicates results across folders.
Changes:
- Introduce
stripWorkspaceFolderPrefixhelper and use it ingetAbsolutePathFileResultsto also try the query with a leading workspace-folder segment removed. - Extract per-folder resolution into
tryAddRelativePathFileResultand deduplicate results using aResourceMap. - Add unit tests for
stripWorkspaceFolderPrefix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/vs/workbench/contrib/search/browser/anythingQuickAccess.ts | Adds prefix-stripping behavior, refactors file-result collection, dedupes results. |
| src/vs/workbench/contrib/search/test/browser/anythingQuickAccess.test.ts | New tests covering separator handling, case-insensitive match, partial match rejection, and remainder preservation. |
| try { | ||
| const stat = await this.fileService.stat(resource); | ||
| if (stat.isFile) { | ||
| const cased = await this.matchFilenameCasing(resource); |
Comment on lines
+15
to
+16
| function makeFolder(uri: string, name?: string): IWorkspaceFolder { | ||
| const folderUri = URI.file(uri); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #208840
What this PR does
In a multi-root workspace (or any workspace whose folder display name / basename appears in the path the user pastes), typing a fully-qualified relative path such as
workspace_1/test_file.txtorSource/main.pyreturns no results from Quick Open's file picker.The relative-path resolver in
AnythingQuickAccessProvider.getRelativePathFileResultsresolves each query against every workspace folder viafolder.toResource(query.original), which produces<folderUri>/workspace_1/test_file.txt— a path that does not exist when the workspace folder itself isworkspace_1.This PR adds a second resolution attempt that strips a leading path segment when it matches the workspace folder's
nameor the basename of its URI (case-insensitively). For example:workspace_1,workspace_2. User typesworkspace_1/test_file.txt→ file is now found.{ "name": "Source", "path": "code" }. User typesSource/main.pyorcode/main.py→ file is now found.The original behavior (using
query.originalas-is) is preserved, so single-root relative queries that already work continue to work. Results are de-duplicated via aResourceMapso a file matched by both the original and the stripped query is returned only once.Stripping only fires when the first segment is an exact, case-insensitive match to the folder's name or basename —
workspace_12/x.tsagainst folderworkspace_1does not strip. Empty remainders (e.g.workspace_1/) are ignored to avoid matching the folder itself.Implementation
getRelativePathFileResultsnow uses aResourceMapinstead of aURI[]to handle the dedup.tryAddRelativePathFileResultfactors out the stat + casing-resolution step so it can be reused for both the as-typed and prefix-stripped queries.stripWorkspaceFolderPrefix(query, folder)performs the prefix check. It is exported so it can be unit-tested without the full Quick Access scaffolding.Testing
src/vs/workbench/contrib/search/test/browser/anythingQuickAccess.test.tscovering:/and\separatorsSourcevscode)workspace_12against folderworkspace_1)