Merge from vscode 5b9869eb02fa4c96205a74d05cad9164dfd06d60 (#5607)

This commit is contained in:
Anthony Dresser
2019-05-24 12:20:30 -07:00
committed by GitHub
parent 361ada4963
commit bcc449b524
126 changed files with 3096 additions and 2255 deletions

View File

@@ -147,43 +147,45 @@ export class OpenFileHandler extends QuickOpenHandler {
return this.doFindResults(query, token, this.cacheState.cacheKey, maxSortedResults);
}
private doFindResults(query: IPreparedQuery, token: CancellationToken, cacheKey?: string, maxSortedResults?: number): Promise<FileQuickOpenModel> {
private async doFindResults(query: IPreparedQuery, token: CancellationToken, cacheKey?: string, maxSortedResults?: number): Promise<FileQuickOpenModel> {
const queryOptions = this.doResolveQueryOptions(query, cacheKey, maxSortedResults);
let iconClass: string;
let iconClass: string | undefined = undefined;
if (this.options && this.options.forceUseIcons && !this.themeService.getFileIconTheme()) {
iconClass = 'file'; // only use a generic file icon if we are forced to use an icon and have no icon theme set otherwise
}
return this.getAbsolutePathResult(query).then(result => {
if (token.isCancellationRequested) {
return Promise.resolve(<ISearchComplete>{ results: [] });
let complete: ISearchComplete | undefined = undefined;
const result = await this.getAbsolutePathResult(query);
if (token.isCancellationRequested) {
complete = <ISearchComplete>{ results: [] };
}
// If the original search value is an existing file on disk, return it immediately and bypass the search service
else if (result) {
complete = <ISearchComplete>{ results: [{ resource: result }] };
}
else {
complete = await this.searchService.fileSearch(this.queryBuilder.file(this.contextService.getWorkspace().folders.map(folder => folder.uri), queryOptions), token);
}
const results: QuickOpenEntry[] = [];
if (!token.isCancellationRequested) {
for (const fileMatch of complete.results) {
const label = basename(fileMatch.resource);
const description = this.labelService.getUriLabel(dirname(fileMatch.resource), { relative: true });
results.push(this.instantiationService.createInstance(FileEntry, fileMatch.resource, label, description, iconClass));
}
}
// If the original search value is an existing file on disk, return it immediately and bypass the search service
if (result) {
return Promise.resolve(<ISearchComplete>{ results: [{ resource: result }] });
}
return this.searchService.fileSearch(this.queryBuilder.file(this.contextService.getWorkspace().folders.map(folder => folder.uri), queryOptions), token);
}).then(complete => {
const results: QuickOpenEntry[] = [];
if (!token.isCancellationRequested) {
for (const fileMatch of complete.results) {
const label = basename(fileMatch.resource);
const description = this.labelService.getUriLabel(dirname(fileMatch.resource), { relative: true });
results.push(this.instantiationService.createInstance(FileEntry, fileMatch.resource, label, description, iconClass));
}
}
return new FileQuickOpenModel(results, <IFileSearchStats>complete.stats);
});
return new FileQuickOpenModel(results, <IFileSearchStats>complete.stats);
}
private getAbsolutePathResult(query: IPreparedQuery): Promise<URI | undefined> {
private async getAbsolutePathResult(query: IPreparedQuery): Promise<URI | undefined> {
const detildifiedQuery = untildify(query.original, this.environmentService.userHome);
if (isAbsolute(detildifiedQuery)) {
const workspaceFolders = this.contextService.getWorkspace().folders;
@@ -191,12 +193,16 @@ export class OpenFileHandler extends QuickOpenHandler {
workspaceFolders[0].uri.with({ path: detildifiedQuery }) :
URI.file(detildifiedQuery);
return this.fileService.resolve(resource).then(
stat => stat.isDirectory ? undefined : resource,
error => undefined);
try {
const stat = await this.fileService.resolve(resource);
return stat.isDirectory ? undefined : resource;
} catch (error) {
// ignore
}
}
return Promise.resolve(undefined);
return undefined;
}
private doResolveQueryOptions(query: IPreparedQuery, cacheKey?: string, maxSortedResults?: number): IFileQueryBuilderOptions {