mirror of
https://github.com/Microsoft/vscode
synced 2024-07-07 19:50:26 +00:00
Fix fuzzy searching for findFiles2 (#204768)
* progress on making fuzzy option * finish connection to findfiles API
This commit is contained in:
parent
bcf9b4ff0f
commit
90cebfaeb2
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,8 @@ export interface ICommonQueryProps<U extends UriComponents> {
|
|||
_reason?: string;
|
||||
|
||||
folderQueries: IFolderQuery<U>[];
|
||||
// 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<U extends UriComponents> 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 !!(<ISerializedFileMatch>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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user