mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +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`', () => {
|
test('`findFiles2`', () => {
|
||||||
return vscode.workspace.findFiles2('*image.png').then((res) => {
|
return vscode.workspace.findFiles2('**/image.png').then((res) => {
|
||||||
assert.strictEqual(res.length, 4);
|
assert.strictEqual(res.length, 2);
|
||||||
// TODO: see why this is fuzzy matching
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -619,9 +618,8 @@ suite('vscode API - workspace', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('findFiles2, exclude', () => {
|
test('findFiles2, exclude', () => {
|
||||||
return vscode.workspace.findFiles2('*image.png', { exclude: '**/sub/**' }).then((res) => {
|
return vscode.workspace.findFiles2('**/image.png', { exclude: '**/sub/**' }).then((res) => {
|
||||||
assert.strictEqual(res.length, 3);
|
assert.strictEqual(res.length, 1);
|
||||||
// TODO: see why this is fuzzy matching
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -497,6 +497,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
|
||||||
disregardSearchExcludeSettings: typeof options.useDefaultSearchExcludes === 'boolean' ? !options.useDefaultSearchExcludes : false,
|
disregardSearchExcludeSettings: typeof options.useDefaultSearchExcludes === 'boolean' ? !options.useDefaultSearchExcludes : false,
|
||||||
maxResults: options.maxResults,
|
maxResults: options.maxResults,
|
||||||
excludePattern: excludePattern,
|
excludePattern: excludePattern,
|
||||||
|
shouldGlobSearch: typeof options.fuzzy === 'boolean' ? !options.fuzzy : true,
|
||||||
_reason: 'startFileSearch'
|
_reason: 'startFileSearch'
|
||||||
};
|
};
|
||||||
let folderToUse: URI | undefined;
|
let folderToUse: URI | undefined;
|
||||||
|
|
|
@ -72,6 +72,7 @@ export interface IFileQueryBuilderOptions extends ICommonQueryBuilderOptions {
|
||||||
exists?: boolean;
|
exists?: boolean;
|
||||||
sortByScore?: boolean;
|
sortByScore?: boolean;
|
||||||
cacheKey?: string;
|
cacheKey?: string;
|
||||||
|
shouldGlobSearch?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITextQueryBuilderOptions extends ICommonQueryBuilderOptions {
|
export interface ITextQueryBuilderOptions extends ICommonQueryBuilderOptions {
|
||||||
|
@ -188,6 +189,7 @@ export class QueryBuilder {
|
||||||
exists: options.exists,
|
exists: options.exists,
|
||||||
sortByScore: options.sortByScore,
|
sortByScore: options.sortByScore,
|
||||||
cacheKey: options.cacheKey,
|
cacheKey: options.cacheKey,
|
||||||
|
shouldGlobMatchFilePattern: options.shouldGlobSearch
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,8 @@ export interface ICommonQueryProps<U extends UriComponents> {
|
||||||
_reason?: string;
|
_reason?: string;
|
||||||
|
|
||||||
folderQueries: IFolderQuery<U>[];
|
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;
|
includePattern?: glob.IExpression;
|
||||||
excludePattern?: glob.IExpression;
|
excludePattern?: glob.IExpression;
|
||||||
extraFileResources?: U[];
|
extraFileResources?: U[];
|
||||||
|
@ -95,6 +97,10 @@ export interface IFileQueryProps<U extends UriComponents> extends ICommonQueryPr
|
||||||
type: QueryType.File;
|
type: QueryType.File;
|
||||||
filePattern?: string;
|
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.
|
* 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'.
|
* 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;
|
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;
|
const pathToMatch = candidate.searchPath ? candidate.searchPath : candidate.relativePath;
|
||||||
return fuzzyContains(pathToMatch, normalizedFilePatternLowercase);
|
return fuzzy ?
|
||||||
|
fuzzyContains(pathToMatch, filePatternToUse) :
|
||||||
|
glob.match(filePatternToUse, pathToMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISerializedFileMatch {
|
export interface ISerializedFileMatch {
|
||||||
|
|
|
@ -75,7 +75,7 @@ export class FileWalker {
|
||||||
this.errors = [];
|
this.errors = [];
|
||||||
|
|
||||||
if (this.filePattern) {
|
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);
|
this.globalExcludePattern = config.excludePattern && glob.parse(config.excludePattern);
|
||||||
|
@ -579,6 +579,8 @@ export class FileWalker {
|
||||||
|
|
||||||
if (this.normalizedFilePatternLowercase) {
|
if (this.normalizedFilePatternLowercase) {
|
||||||
return isFilePatternMatch(candidate, 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"`.
|
* See the vscode setting `"search.followSymlinks"`.
|
||||||
*/
|
*/
|
||||||
followSymlinks?: boolean;
|
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 a new issue