diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts index b867766d027..11caa87618d 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts @@ -598,9 +598,8 @@ suite('vscode API - workspace', () => { }); test('`findFiles2`', () => { - return vscode.workspace.findFiles2('*image.png').then((res) => { - assert.strictEqual(res.length, 4); - // TODO: see why this is fuzzy matching + return vscode.workspace.findFiles2('**/image.png').then((res) => { + assert.strictEqual(res.length, 2); }); }); @@ -619,9 +618,8 @@ suite('vscode API - workspace', () => { }); test('findFiles2, exclude', () => { - return vscode.workspace.findFiles2('*image.png', { exclude: '**/sub/**' }).then((res) => { - assert.strictEqual(res.length, 3); - // TODO: see why this is fuzzy matching + return vscode.workspace.findFiles2('**/image.png', { exclude: '**/sub/**' }).then((res) => { + assert.strictEqual(res.length, 1); }); }); diff --git a/src/vs/workbench/api/common/extHostWorkspace.ts b/src/vs/workbench/api/common/extHostWorkspace.ts index dcb32598916..65cee0c4faa 100644 --- a/src/vs/workbench/api/common/extHostWorkspace.ts +++ b/src/vs/workbench/api/common/extHostWorkspace.ts @@ -497,6 +497,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac disregardSearchExcludeSettings: typeof options.useDefaultSearchExcludes === 'boolean' ? !options.useDefaultSearchExcludes : false, maxResults: options.maxResults, excludePattern: excludePattern, + shouldGlobSearch: typeof options.fuzzy === 'boolean' ? !options.fuzzy : true, _reason: 'startFileSearch' }; let folderToUse: URI | undefined; diff --git a/src/vs/workbench/services/search/common/queryBuilder.ts b/src/vs/workbench/services/search/common/queryBuilder.ts index 78b4d0c9227..9124249957a 100644 --- a/src/vs/workbench/services/search/common/queryBuilder.ts +++ b/src/vs/workbench/services/search/common/queryBuilder.ts @@ -72,6 +72,7 @@ export interface IFileQueryBuilderOptions extends ICommonQueryBuilderOptions { exists?: boolean; sortByScore?: boolean; cacheKey?: string; + shouldGlobSearch?: boolean; } export interface ITextQueryBuilderOptions extends ICommonQueryBuilderOptions { @@ -188,6 +189,7 @@ export class QueryBuilder { exists: options.exists, sortByScore: options.sortByScore, cacheKey: options.cacheKey, + shouldGlobMatchFilePattern: options.shouldGlobSearch }; } diff --git a/src/vs/workbench/services/search/common/search.ts b/src/vs/workbench/services/search/common/search.ts index 7803e26cb47..ca93adc467b 100644 --- a/src/vs/workbench/services/search/common/search.ts +++ b/src/vs/workbench/services/search/common/search.ts @@ -81,6 +81,8 @@ export interface ICommonQueryProps { _reason?: string; folderQueries: IFolderQuery[]; + // The include pattern for files that gets passed into ripgrep. + // Note that this will override any ignore files if applicable. includePattern?: glob.IExpression; excludePattern?: glob.IExpression; extraFileResources?: U[]; @@ -95,6 +97,10 @@ export interface IFileQueryProps extends ICommonQueryPr type: QueryType.File; filePattern?: string; + // when walking through the tree to find the result, don't use the filePattern to fuzzy match. + // Instead, should use glob matching. + shouldGlobMatchFilePattern?: boolean; + /** * If true no results will be returned. Instead `limitHit` will indicate if at least one result exists or not. * Currently does not work with queries including a 'siblings clause'. @@ -586,9 +592,11 @@ export function isSerializedFileMatch(arg: ISerializedSearchProgressItem): arg i return !!(arg).path; } -export function isFilePatternMatch(candidate: IRawFileMatch, normalizedFilePatternLowercase: string): boolean { +export function isFilePatternMatch(candidate: IRawFileMatch, filePatternToUse: string, fuzzy = true): boolean { const pathToMatch = candidate.searchPath ? candidate.searchPath : candidate.relativePath; - return fuzzyContains(pathToMatch, normalizedFilePatternLowercase); + return fuzzy ? + fuzzyContains(pathToMatch, filePatternToUse) : + glob.match(filePatternToUse, pathToMatch); } export interface ISerializedFileMatch { diff --git a/src/vs/workbench/services/search/node/fileSearch.ts b/src/vs/workbench/services/search/node/fileSearch.ts index 3abfea8d4f3..9b372b8dedb 100644 --- a/src/vs/workbench/services/search/node/fileSearch.ts +++ b/src/vs/workbench/services/search/node/fileSearch.ts @@ -75,7 +75,7 @@ export class FileWalker { this.errors = []; if (this.filePattern) { - this.normalizedFilePatternLowercase = prepareQuery(this.filePattern).normalizedLowercase; + this.normalizedFilePatternLowercase = config.shouldGlobMatchFilePattern ? null : prepareQuery(this.filePattern).normalizedLowercase; } this.globalExcludePattern = config.excludePattern && glob.parse(config.excludePattern); @@ -579,6 +579,8 @@ export class FileWalker { if (this.normalizedFilePatternLowercase) { return isFilePatternMatch(candidate, this.normalizedFilePatternLowercase); + } else if (this.filePattern) { + return isFilePatternMatch(candidate, this.filePattern, false); } } diff --git a/src/vscode-dts/vscode.proposed.findFiles2.d.ts b/src/vscode-dts/vscode.proposed.findFiles2.d.ts index 45d734153a2..37743a897da 100644 --- a/src/vscode-dts/vscode.proposed.findFiles2.d.ts +++ b/src/vscode-dts/vscode.proposed.findFiles2.d.ts @@ -55,6 +55,12 @@ declare module 'vscode' { * See the vscode setting `"search.followSymlinks"`. */ followSymlinks?: boolean; + + /** + * If set to true, the `filePattern` arg will be fuzzy-searched instead of glob-searched. + * If `filePattern` is a `GlobPattern`, then the fuzzy search will act on the `pattern` of the `RelativePattern` + */ + fuzzy?: boolean; } /**