提交 4132c13a 编写于 作者: B Benjamin Pasero

fix #42726

上级 4ac711ab
...@@ -108,12 +108,12 @@ export class OpenAnythingHandler extends QuickOpenHandler { ...@@ -108,12 +108,12 @@ export class OpenAnythingHandler extends QuickOpenHandler {
const resultPromises: TPromise<QuickOpenModel | FileQuickOpenModel>[] = []; const resultPromises: TPromise<QuickOpenModel | FileQuickOpenModel>[] = [];
// File Results // File Results
const filePromise = this.openFileHandler.getResults(query.value, OpenAnythingHandler.MAX_DISPLAYED_RESULTS); const filePromise = this.openFileHandler.getResults(query.original, OpenAnythingHandler.MAX_DISPLAYED_RESULTS);
resultPromises.push(filePromise); resultPromises.push(filePromise);
// Symbol Results (unless disabled or a range or absolute path is specified) // Symbol Results (unless disabled or a range or absolute path is specified)
if (this.includeSymbols && !searchWithRange) { if (this.includeSymbols && !searchWithRange) {
resultPromises.push(this.openSymbolHandler.getResults(query.value)); resultPromises.push(this.openSymbolHandler.getResults(query.original));
} }
// Join and sort unified // Join and sort unified
...@@ -263,4 +263,4 @@ export class OpenAnythingHandler extends QuickOpenHandler { ...@@ -263,4 +263,4 @@ export class OpenAnythingHandler extends QuickOpenHandler {
this.pendingSearch = null; this.pendingSearch = null;
} }
} }
} }
\ No newline at end of file
...@@ -32,6 +32,8 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' ...@@ -32,6 +32,8 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IRange } from 'vs/editor/common/core/range'; import { IRange } from 'vs/editor/common/core/range';
import { getOutOfWorkspaceEditorResources } from 'vs/workbench/parts/search/common/search'; import { getOutOfWorkspaceEditorResources } from 'vs/workbench/parts/search/common/search';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { prepareQuery, IPreparedQuery } from 'vs/base/parts/quickopen/common/quickOpenScorer';
import { IFileService } from 'vs/platform/files/common/files';
export class FileQuickOpenModel extends QuickOpenModel { export class FileQuickOpenModel extends QuickOpenModel {
...@@ -122,7 +124,8 @@ export class OpenFileHandler extends QuickOpenHandler { ...@@ -122,7 +124,8 @@ export class OpenFileHandler extends QuickOpenHandler {
@IWorkbenchThemeService private themeService: IWorkbenchThemeService, @IWorkbenchThemeService private themeService: IWorkbenchThemeService,
@IWorkspaceContextService private contextService: IWorkspaceContextService, @IWorkspaceContextService private contextService: IWorkspaceContextService,
@ISearchService private searchService: ISearchService, @ISearchService private searchService: ISearchService,
@IEnvironmentService private environmentService: IEnvironmentService @IEnvironmentService private environmentService: IEnvironmentService,
@IFileService private fileService: IFileService
) { ) {
super(); super();
...@@ -134,50 +137,71 @@ export class OpenFileHandler extends QuickOpenHandler { ...@@ -134,50 +137,71 @@ export class OpenFileHandler extends QuickOpenHandler {
} }
public getResults(searchValue: string, maxSortedResults?: number): TPromise<FileQuickOpenModel> { public getResults(searchValue: string, maxSortedResults?: number): TPromise<FileQuickOpenModel> {
searchValue = searchValue.trim(); const query = prepareQuery(searchValue);
// Respond directly to empty search // Respond directly to empty search
if (!searchValue) { if (!query.value) {
return TPromise.as(new FileQuickOpenModel([])); return TPromise.as(new FileQuickOpenModel([]));
} }
// Untildify file pattern // Untildify file pattern
searchValue = labels.untildify(searchValue, this.environmentService.userHome); query.value = labels.untildify(query.value, this.environmentService.userHome);
// Do find results // Do find results
return this.doFindResults(searchValue, this.cacheState.cacheKey, maxSortedResults); return this.doFindResults(query, this.cacheState.cacheKey, maxSortedResults);
} }
private doFindResults(searchValue: string, cacheKey?: string, maxSortedResults?: number): TPromise<FileQuickOpenModel> { private doFindResults(query: IPreparedQuery, cacheKey?: string, maxSortedResults?: number): TPromise<FileQuickOpenModel> {
const query: IQueryOptions = { return this.doResolveQueryOptions(query, cacheKey, maxSortedResults).then(queryOptions => {
let iconClass: string;
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.searchService.search(this.queryBuilder.file(this.contextService.getWorkspace().folders.map(folder => folder.uri), queryOptions)).then(complete => {
const results: QuickOpenEntry[] = [];
for (let i = 0; i < complete.results.length; i++) {
const fileMatch = complete.results[i];
const label = paths.basename(fileMatch.resource.fsPath);
const description = labels.getPathLabel(resources.dirname(fileMatch.resource), this.contextService, this.environmentService);
results.push(this.instantiationService.createInstance(FileEntry, fileMatch.resource, label, description, iconClass));
}
return new FileQuickOpenModel(results, complete.stats);
});
});
}
private doResolveQueryOptions(query: IPreparedQuery, cacheKey?: string, maxSortedResults?: number): TPromise<IQueryOptions> {
const queryOptions: IQueryOptions = {
extraFileResources: getOutOfWorkspaceEditorResources(this.editorService, this.contextService), extraFileResources: getOutOfWorkspaceEditorResources(this.editorService, this.contextService),
filePattern: searchValue, filePattern: query.value,
cacheKey: cacheKey cacheKey
}; };
if (typeof maxSortedResults === 'number') { if (typeof maxSortedResults === 'number') {
query.maxResults = maxSortedResults; queryOptions.maxResults = maxSortedResults;
query.sortByScore = true; queryOptions.sortByScore = true;
} }
let iconClass: string; let queryIsAbsoluteFilePromise: TPromise<URI>;
if (this.options && this.options.forceUseIcons && !this.themeService.getFileIconTheme()) { if (paths.isAbsolute(query.original)) {
iconClass = 'file'; // only use a generic file icon if we are forced to use an icon and have no icon theme set otherwise const resource = URI.file(query.original);
queryIsAbsoluteFilePromise = this.fileService.resolveFile(resource).then(stat => stat.isDirectory ? void 0 : resource, error => void 0);
} else {
queryIsAbsoluteFilePromise = TPromise.as(null);
} }
const folderResources = this.contextService.getWorkspace().folders.map(folder => folder.uri); return queryIsAbsoluteFilePromise.then(resource => {
return this.searchService.search(this.queryBuilder.file(folderResources, query)).then((complete) => { if (resource) {
const results: QuickOpenEntry[] = []; // if the original search value is an existing file on disk, add it to the
for (let i = 0; i < complete.results.length; i++) { // extra file resources to consider (fixes https://github.com/Microsoft/vscode/issues/42726)
const fileMatch = complete.results[i]; queryOptions.extraFileResources.push(resource);
const label = paths.basename(fileMatch.resource.fsPath);
const description = labels.getPathLabel(resources.dirname(fileMatch.resource), this.contextService, this.environmentService);
results.push(this.instantiationService.createInstance(FileEntry, fileMatch.resource, label, description, iconClass));
} }
return new FileQuickOpenModel(results, complete.stats); return queryOptions;
}); });
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册