Skip to content

Commit

Permalink
no highlights for deprecated workspace symbols, also tweak sorting, #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Aug 23, 2019
1 parent f610ae3 commit 5458ae7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 52 deletions.
35 changes: 0 additions & 35 deletions src/vs/base/parts/quickopen/browser/quickOpenModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ITree, IActionProvider } from 'vs/base/parts/tree/browser/tree';
import { IconLabel, IIconLabelValueOptions } from 'vs/base/browser/ui/iconLabel/iconLabel';
import { IQuickNavigateConfiguration, IModel, IDataSource, IFilter, IAccessiblityProvider, IRenderer, IRunner, Mode, IEntryRunContext } from 'vs/base/parts/quickopen/common/quickOpen';
import { IAction, IActionRunner } from 'vs/base/common/actions';
import { compareAnything } from 'vs/base/common/comparers';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { HighlightedLabel } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
import * as DOM from 'vs/base/browser/dom';
Expand Down Expand Up @@ -576,37 +575,3 @@ export class QuickOpenModel implements
return entry.run(mode, context);
}
}

/**
* A good default sort implementation for quick open entries respecting highlight information
* as well as associated resources.
*/
export function compareEntries(elementA: QuickOpenEntry, elementB: QuickOpenEntry, lookFor: string): number {

// Give matches with label highlights higher priority over
// those with only description highlights
const labelHighlightsA = elementA.getHighlights()[0] || [];
const labelHighlightsB = elementB.getHighlights()[0] || [];
if (labelHighlightsA.length && !labelHighlightsB.length) {
return -1;
}

if (!labelHighlightsA.length && labelHighlightsB.length) {
return 1;
}

// Fallback to the full path if labels are identical and we have associated resources
let nameA = elementA.getLabel()!;
let nameB = elementB.getLabel()!;
if (nameA === nameB) {
const resourceA = elementA.getResource();
const resourceB = elementB.getResource();

if (resourceA && resourceB) {
nameA = resourceA.fsPath;
nameB = resourceB.fsPath;
}
}

return compareAnything(nameA, nameB, lookFor);
}
59 changes: 42 additions & 17 deletions src/vs/workbench/contrib/search/browser/openSymbolHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { URI } from 'vs/base/common/uri';
import { onUnexpectedError } from 'vs/base/common/errors';
import { ThrottledDelayer } from 'vs/base/common/async';
import { QuickOpenHandler, EditorQuickOpenEntry } from 'vs/workbench/browser/quickopen';
import { QuickOpenModel, QuickOpenEntry, compareEntries } from 'vs/base/parts/quickopen/browser/quickOpenModel';
import { QuickOpenModel, QuickOpenEntry, IHighlight } from 'vs/base/parts/quickopen/browser/quickOpenModel';
import { IAutoFocus, Mode, IEntryRunContext } from 'vs/base/parts/quickopen/common/quickOpen';
import * as filters from 'vs/base/common/filters';
import * as strings from 'vs/base/common/strings';
Expand All @@ -28,7 +28,9 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IIconLabelValueOptions } from 'vs/base/browser/ui/iconLabel/iconLabel';

class SymbolEntry extends EditorQuickOpenEntry {
private bearingResolve: Promise<this | undefined> | undefined;

private bearingResolve?: Promise<this | undefined>;
private score?: filters.FuzzyScore;

constructor(
private bearing: IWorkspaceSymbol,
Expand All @@ -41,6 +43,14 @@ class SymbolEntry extends EditorQuickOpenEntry {
super(editorService);
}

setScore(score: filters.FuzzyScore | undefined) {
this.score = score;
}

getHighlights(): [IHighlight[] /* Label */, IHighlight[] | undefined /* Description */, IHighlight[] | undefined /* Detail */] {
return [this.isDeprecated() ? [] : filters.createMatches(this.score), undefined, undefined];
}

getLabel(): string {
return this.bearing.name;
}
Expand All @@ -67,15 +77,17 @@ class SymbolEntry extends EditorQuickOpenEntry {
}

getLabelOptions(): IIconLabelValueOptions | undefined {
return this.bearing.tags && this.bearing.tags.indexOf(SymbolTag.Deprecated) >= 0
? { extraClasses: ['deprecated'] }
: undefined;
return this.isDeprecated() ? { extraClasses: ['deprecated'] } : undefined;
}

getResource(): URI {
return this.bearing.location.uri;
}

private isDeprecated(): boolean {
return this.bearing.tags ? this.bearing.tags.indexOf(SymbolTag.Deprecated) >= 0 : false;
}

run(mode: Mode, context: IEntryRunContext): boolean {

// resolve this type bearing if neccessary
Expand Down Expand Up @@ -118,18 +130,24 @@ class SymbolEntry extends EditorQuickOpenEntry {
return input;
}

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 = symbolKindToCssClass(elementA.bearing.kind);
let elementBType = symbolKindToCssClass(elementB.bearing.kind);
return elementAType.localeCompare(elementBType);
static compare(a: SymbolEntry, b: SymbolEntry, searchValue: string): number {
// order: score, name, kind
if (a.score && b.score) {
if (a.score[0] > b.score[0]) {
return -1;
} else if (a.score[0] < b.score[0]) {
return 1;
}
}

return compareEntries(elementA, elementB, searchValue);
const aName = a.getLabel().toLowerCase();
const bName = b.getLabel().toLowerCase();
let res = aName.localeCompare(bName);
if (res !== 0) {
return res;
}
let aKind = symbolKindToCssClass(a.bearing.kind);
let bKind = symbolKindToCssClass(b.bearing.kind);
return aKind.localeCompare(bKind);
}
}

Expand Down Expand Up @@ -205,14 +223,21 @@ export class OpenSymbolHandler extends QuickOpenHandler {

private fillInSymbolEntries(bucket: SymbolEntry[], provider: IWorkspaceSymbolProvider, types: IWorkspaceSymbol[], searchValue: string): void {

const pattern = strings.stripWildcards(searchValue);
const patternLow = pattern.toLowerCase();

// Convert to Entries
for (let element of types) {
if (this.options.skipLocalSymbols && !!element.containerName) {
continue; // ignore local symbols if we are told so
}

const entry = this.instantiationService.createInstance(SymbolEntry, element, provider);
entry.setHighlights(filters.matchesFuzzy2(searchValue, entry.getLabel()) || []);
entry.setScore(filters.fuzzyScore(
pattern, patternLow, 0,
entry.getLabel(), entry.getLabel().toLowerCase(), 0,
true
));
bucket.push(entry);
}
}
Expand Down

0 comments on commit 5458ae7

Please sign in to comment.