Skip to content

Conversation

@acdzh
Copy link
Contributor

@acdzh acdzh commented Oct 27, 2025

For problem details, please refer to this issue: #273517

The cause of this problem lies in the expandSearchPathPatterns function in the src/vs/workbench/services/search/common/queryBuilder.ts file. This function is responsible for converting the raw content entered by the user in the Include/Exclude text boxes into formal file paths.

The specific problem is in this sub-function within expandSearchPathPatterns:

const expandedSearchPaths = searchPaths.flatMap(searchPath => {
	// 1 open folder => just resolve the search paths to absolute paths
	let { pathPortion, globPortion } = splitGlobFromPath(searchPath);

	if (globPortion) {
		globPortion = normalizeGlobPattern(globPortion);
	}

	// One pathPortion to multiple expanded search paths (e.g. duplicate matching workspace folders)
	const oneExpanded = this.expandOneSearchPath(pathPortion);

	// Expanded search paths to multiple resolved patterns (with ** and without)
	return oneExpanded.flatMap(oneExpandedResult => this.resolveOneSearchPathPattern(oneExpandedResult, globPortion));
});

Before calling this.expandOneSearchPath to get the real path, the file path has already been corrupted by the splitGlobFromPath function.

Here are two examples to illustrate. Before reading the examples, please check this issue for background information.

Example 1

If our searchPath is ./monorepo (dev), after being processed by the splitGlobFromPath function, we get a pathPortion with the value './' and a globPortion with the value 'monorepo (dev)'.

image

Consequently, in the this.expandOneSearchPath function, because the passed parameter is './', the Include parameter does not take effect, resulting in a search across all folders.

image

Example 2

If our searchPath is ./apps/vscode (dev), after being processed by the splitGlobFromPath function, we get a pathPortion with the value './apps' and a globPortion with the value 'vscode (dev)'.

Since './apps' does not exist, an error is triggered. However, the folder ./apps/vscode (dev) actually exists in the project.

image

Solution

We move the processing of splitGlobFromPath down into the this.expandOneSearchPath function. When checking if searchPath is a project folder path, we use the original searchPath for the check instead of the pathPortion trimmed by splitGlobFromPath.

… characters

When using multi-folder workspaces, if a workspace folder name contains glob
characters, the search functionality would fail to match correctly due to
incorrect path processing. This fix ensures we use the original searchPath
instead of the processed pathPortion to determine workspace folder matches,
preventing glob characters in folder names from being incorrectly truncated
by splitGlobFromPath.

Fixes search issues in workspaces where folder names include special glob
characters like *, ?, [], (), etc.
@acdzh
Copy link
Contributor Author

acdzh commented Oct 27, 2025

After fixed:

image image

@acdzh
Copy link
Contributor Author

acdzh commented Oct 27, 2025

@microsoft-github-policy-service agree

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.

2 participants