prep SymbolEntry for new features, stop ignoring non-'file'-schema resources, stop ignoring result not getting a highlight

This commit is contained in:
Johannes Rieken 2016-08-02 12:48:19 +02:00
parent fe8bb5b484
commit 36a2a04f86

View file

@ -7,12 +7,11 @@
import {TPromise} from 'vs/base/common/winjs.base';
import nls = require('vs/nls');
import {ThrottledDelayer} from 'vs/base/common/async';
import URI from 'vs/base/common/uri';
import {QuickOpenHandler, EditorQuickOpenEntry} from 'vs/workbench/browser/quickopen';
import {QuickOpenModel, QuickOpenEntry, IHighlight} from 'vs/base/parts/quickopen/browser/quickOpenModel';
import {IAutoFocus} from 'vs/base/parts/quickopen/common/quickOpen';
import {QuickOpenModel, QuickOpenEntry} from 'vs/base/parts/quickopen/browser/quickOpenModel';
import {IAutoFocus/*, Mode, IEntryRunContext*/} from 'vs/base/parts/quickopen/common/quickOpen';
import filters = require('vs/base/common/filters');
import {IRange} from 'vs/editor/common/editorCommon';
import {Range} from 'vs/editor/common/core/range';
import {EditorInput, IWorkbenchEditorConfiguration} from 'vs/workbench/common/editor';
import labels = require('vs/base/common/labels');
import {IResourceInput} from 'vs/platform/editor/common/editor';
@ -21,83 +20,68 @@ import {IInstantiationService} from 'vs/platform/instantiation/common/instantiat
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {ITypeBearing, getNavigateToItems} from 'vs/workbench/parts/search/common/search';
import {ITypeBearing, INavigateTypesSupport, getNavigateToItems} from 'vs/workbench/parts/search/common/search';
class SymbolEntry extends EditorQuickOpenEntry {
private name: string;
private parameters: string;
private description: string;
private resource: URI;
private type: string;
private range: IRange;
constructor(
name: string,
parameters: string,
description: string,
resource: URI,
type: string,
range: IRange,
highlights: IHighlight[],
private _bearing: ITypeBearing,
private _provider: INavigateTypesSupport,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IConfigurationService private configurationService: IConfigurationService
@IConfigurationService private _configurationService: IConfigurationService,
@IWorkspaceContextService private _contextService: IWorkspaceContextService
) {
super(editorService);
this.name = name;
this.parameters = parameters;
this.description = description;
this.resource = resource;
this.type = type;
this.range = range;
this.setHighlights(highlights);
}
public getLabel(): string {
return this.name + this.parameters;
return this._bearing.name;
}
public getAriaLabel(): string {
return nls.localize('entryAriaLabel', "{0}, symbols picker", this.getLabel());
}
public getName(): string {
return this.name;
}
public getParameters(): string {
return this.parameters;
}
public getDescription(): string {
return this.description;
}
public getType(): string {
return this.type;
let result = this._bearing.containerName;
if (!result) {
result = labels.getPathLabel(this._bearing.resourceUri, this._contextService);
}
return result;
}
public getIcon(): string {
return this.type;
return this._bearing.type;
}
public getInput(): IResourceInput | EditorInput {
let input: IResourceInput = {
resource: this.resource,
resource: this._bearing.resourceUri,
options: {
pinned: !this.configurationService.getConfiguration<IWorkbenchEditorConfiguration>().workbench.editor.enablePreviewFromQuickOpen
pinned: !this._configurationService.getConfiguration<IWorkbenchEditorConfiguration>().workbench.editor.enablePreviewFromQuickOpen
}
};
if (this.range) {
input.options.selection = {
startLineNumber: this.range.startLineNumber,
startColumn: this.range.startColumn
};
if (this._bearing.range) {
input.options.selection = Range.collapseToStart(this._bearing.range);
}
return input;
}
public static compare(elementA: SymbolEntry, elementB: SymbolEntry, searchValue: string): number {
// Sort by Type if name is identical
const elementAName = elementA.getLabel().toLowerCase();
const elementBName = elementB.getLabel().toLowerCase();
if (elementAName === elementBName) {
let elementAType = elementA._bearing.type;
let elementBType = elementB._bearing.type;
return elementAType.localeCompare(elementBType);
}
return QuickOpenEntry.compare(elementA, elementB, searchValue);
}
}
export interface IOpenSymbolOptions {
@ -150,77 +134,36 @@ export class OpenSymbolHandler extends QuickOpenHandler {
return promise.then(e => new QuickOpenModel(e));
}
private doGetResults(searchValue: string): TPromise<QuickOpenEntry[]> {
private doGetResults(searchValue: string): TPromise<SymbolEntry[]> {
return getNavigateToItems(searchValue).then(bearings => {
return this.toQuickOpenEntries(bearings, searchValue);
});
}
private toQuickOpenEntries(types: ITypeBearing[], searchValue: string): SymbolEntry[] {
let results: SymbolEntry[] = [];
const results: SymbolEntry[] = [];
// Convert to Entries
types.forEach(element => {
for (const element of types) {
if (this.options.skipLocalSymbols && !!element.containerName) {
return; // ignore local symbols if we are told so
continue; // ignore local symbols if we are told so
}
// Find Highlights
let highlights = filters.matchesFuzzy(searchValue, element.name);
if (highlights) {
let resource = element.resourceUri;
if (resource.scheme === 'file') {
let path = labels.getPathLabel(resource, this.contextService);
let container: string = void (0);
// Type is top level in module with path spec, use path info then (/folder/file.ts)
if (element.containerName === path) {
container = path;
}
// Type is top level in module with url spec, find last segment to produce a short description (http://.../file.ts)
else if (element.containerName === resource.toString() && element.containerName.indexOf('/') >= 0) {
container = element.containerName.substr(element.containerName.lastIndexOf('/') + 1);
}
// Type is inside a module or other type, find last segment to produce a short description (.../folder/file.ts.CompResult)
else if (element.containerName && element.containerName.indexOf('.') >= 0) {
container = element.containerName.substr(element.containerName.lastIndexOf('.') + 1);
}
// Fallback
else {
container = element.containerName || path;
}
results.push(this.instantiationService.createInstance(SymbolEntry, element.name, element.parameters, container, resource, element.type, element.range, highlights));
}
}
});
const entry = this.instantiationService.createInstance(SymbolEntry, element, undefined);
entry.setHighlights(filters.matchesFuzzy(searchValue, entry.getLabel()));
results.push(entry);
}
// Sort (Standalone only)
if (!this.options.skipSorting) {
return results.sort(this.sort.bind(this, searchValue.toLowerCase()));
searchValue = searchValue.toLowerCase();
return results.sort((a, b) => SymbolEntry.compare(a, b, searchValue));
}
return results;
}
private sort(searchValue: string, elementA: SymbolEntry, elementB: SymbolEntry): number {
// Sort by Type if name is identical
let elementAName = elementA.getName().toLowerCase();
let elementBName = elementB.getName().toLowerCase();
if (elementAName === elementBName) {
let elementAType = elementA.getType();
let elementBType = elementB.getType();
return elementAType.localeCompare(elementBType);
}
return QuickOpenEntry.compare(elementA, elementB, searchValue);
}
public getGroupLabel(): string {
return nls.localize('symbols', "symbol results");
}