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

fix #42726

上级 4ac711ab
......@@ -108,12 +108,12 @@ export class OpenAnythingHandler extends QuickOpenHandler {
const resultPromises: TPromise<QuickOpenModel | FileQuickOpenModel>[] = [];
// 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);
// Symbol Results (unless disabled or a range or absolute path is specified)
if (this.includeSymbols && !searchWithRange) {
resultPromises.push(this.openSymbolHandler.getResults(query.value));
resultPromises.push(this.openSymbolHandler.getResults(query.original));
}
// Join and sort unified
......@@ -263,4 +263,4 @@ export class OpenAnythingHandler extends QuickOpenHandler {
this.pendingSearch = null;
}
}
}
\ No newline at end of file
}
......@@ -32,6 +32,8 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IRange } from 'vs/editor/common/core/range';
import { getOutOfWorkspaceEditorResources } from 'vs/workbench/parts/search/common/search';
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 {
......@@ -122,7 +124,8 @@ export class OpenFileHandler extends QuickOpenHandler {
@IWorkbenchThemeService private themeService: IWorkbenchThemeService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@ISearchService private searchService: ISearchService,
@IEnvironmentService private environmentService: IEnvironmentService
@IEnvironmentService private environmentService: IEnvironmentService,
@IFileService private fileService: IFileService
) {
super();
......@@ -134,50 +137,71 @@ export class OpenFileHandler extends QuickOpenHandler {
}
public getResults(searchValue: string, maxSortedResults?: number): TPromise<FileQuickOpenModel> {
searchValue = searchValue.trim();
const query = prepareQuery(searchValue);
// Respond directly to empty search
if (!searchValue) {
if (!query.value) {
return TPromise.as(new FileQuickOpenModel([]));
}
// Untildify file pattern
searchValue = labels.untildify(searchValue, this.environmentService.userHome);
query.value = labels.untildify(query.value, this.environmentService.userHome);
// 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> {
const query: IQueryOptions = {
private doFindResults(query: IPreparedQuery, cacheKey?: string, maxSortedResults?: number): TPromise<FileQuickOpenModel> {
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),
filePattern: searchValue,
cacheKey: cacheKey
filePattern: query.value,
cacheKey
};
if (typeof maxSortedResults === 'number') {
query.maxResults = maxSortedResults;
query.sortByScore = true;
queryOptions.maxResults = maxSortedResults;
queryOptions.sortByScore = true;
}
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
let queryIsAbsoluteFilePromise: TPromise<URI>;
if (paths.isAbsolute(query.original)) {
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 this.searchService.search(this.queryBuilder.file(folderResources, query)).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 queryIsAbsoluteFilePromise.then(resource => {
if (resource) {
// if the original search value is an existing file on disk, add it to the
// extra file resources to consider (fixes https://github.com/Microsoft/vscode/issues/42726)
queryOptions.extraFileResources.push(resource);
}
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.
先完成此消息的编辑!
想要评论请 注册