Skip to content

Quick Open: match queries with leading workspace folder name#318517

Open
yogeshwaran-c wants to merge 1 commit into
microsoft:mainfrom
yogeshwaran-c:fix/quick-open-multiroot-folder-prefix
Open

Quick Open: match queries with leading workspace folder name#318517
yogeshwaran-c wants to merge 1 commit into
microsoft:mainfrom
yogeshwaran-c:fix/quick-open-multiroot-folder-prefix

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

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.txt or Source/main.py returns no results from Quick Open's file picker.

The relative-path resolver in AnythingQuickAccessProvider.getRelativePathFileResults resolves each query against every workspace folder via folder.toResource(query.original), which produces <folderUri>/workspace_1/test_file.txt — a path that does not exist when the workspace folder itself is workspace_1.

This PR adds 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). For example:

  • Multi-root workspace with workspace_1, workspace_2. User types workspace_1/test_file.txt → file is now found.
  • Workspace folder { "name": "Source", "path": "code" }. User types Source/main.py or code/main.py → file is now found.

The original behavior (using query.original as-is) is preserved, so single-root relative queries that already work continue to work. Results are de-duplicated via a ResourceMap so 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.ts against folder workspace_1 does not strip. Empty remainders (e.g. workspace_1/) are ignored to avoid matching the folder itself.

Implementation

  • getRelativePathFileResults now uses a ResourceMap instead of a URI[] to handle the dedup.
  • A new private helper tryAddRelativePathFileResult factors out the stat + casing-resolution step so it can be reused for both the as-typed and prefix-stripped queries.
  • A new exported pure helper stripWorkspaceFolderPrefix(query, folder) performs the prefix check. It is exported so it can be unit-tested without the full Quick Access scaffolding.

Testing

  • Added focused unit tests in src/vs/workbench/contrib/search/test/browser/anythingQuickAccess.test.ts covering:
    • no separator in the query
    • leading separator
    • basename match with both / and \ separators
    • display-name match where it differs from the URI basename (Source vs code)
    • case-insensitive match
    • partial-prefix non-match (workspace_12 against folder workspace_1)
    • nested path remainders
    • empty-remainder rejection

…-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.
Copilot AI review requested due to automatic review settings May 27, 2026 06:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 stripWorkspaceFolderPrefix helper and use it in getAbsolutePathFileResults to also try the query with a leading workspace-folder segment removed.
  • Extract per-folder resolution into tryAddRelativePathFileResult and deduplicate results using a ResourceMap.
  • 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File quick open does not match exact file paths in multi-root workspace

3 participants