Skip to content

Commit

Permalink
Restore type based global symbole filtering for Ctrl+P (fixes #8502)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jun 30, 2016
1 parent 9dfca5b commit 7df7a47
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(GotoSymbolAction, Goto
{
prefix: GOTO_SYMBOL_PREFIX,
needsEditor: true,
description: env.isMacintosh ? nls.localize('gotoSymbolDescriptionNormalMac', "Go to Symbol") : nls.localize('gotoSymbolDescriptionNormalWin', "Go to Symbol")
description: nls.localize('gotoSymbolDescription', "Go to Symbol in File")
},
{
prefix: GOTO_SYMBOL_PREFIX + SCOPE_PREFIX,
needsEditor: true,
description: nls.localize('gotoSymbolDescriptionScoped', "Go to Symbol by Category")
description: nls.localize('gotoSymbolDescriptionScoped', "Go to Symbol in File by Category")
}
]
)
Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/parts/search/browser/openAnythingHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export class OpenAnythingHandler extends QuickOpenHandler {
this.openSymbolHandler = instantiationService.createInstance(OpenSymbolHandler);
this.openFileHandler = instantiationService.createInstance(OpenFileHandler);

this.openSymbolHandler.setStandalone(false);
this.openSymbolHandler.setOptions({
skipDelay: true, // we have our own delay
skipLocalSymbols: true, // we only want global symbols
skipSorting: true // we sort combined with file results
});

this.resultsToSearchCache = Object.create(null);
this.scorerCache = Object.create(null);
Expand Down
23 changes: 15 additions & 8 deletions src/vs/workbench/parts/search/browser/openSymbolHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,18 @@ class SymbolEntry extends EditorQuickOpenEntry {
}
}

export interface IOpenSymbolOptions {
skipSorting: boolean;
skipLocalSymbols: boolean;
skipDelay: boolean;
}

export class OpenSymbolHandler extends QuickOpenHandler {

private static SEARCH_DELAY = 500; // This delay accommodates for the user typing a word and then stops typing to start searching

private delayer: ThrottledDelayer<QuickOpenEntry[]>;
private isStandalone: boolean;
private options: IOpenSymbolOptions;

constructor(
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
Expand All @@ -116,12 +122,11 @@ export class OpenSymbolHandler extends QuickOpenHandler {
super();

this.delayer = new ThrottledDelayer<QuickOpenEntry[]>(OpenSymbolHandler.SEARCH_DELAY);
this.isStandalone = true;
this.options = Object.create(null);
}

public setStandalone(standalone: boolean) {
this.delayer = standalone ? new ThrottledDelayer<QuickOpenEntry[]>(OpenSymbolHandler.SEARCH_DELAY) : null;
this.isStandalone = standalone;
public setOptions(options: IOpenSymbolOptions) {
this.options = options;
}

public canRun(): boolean | string {
Expand All @@ -136,7 +141,7 @@ export class OpenSymbolHandler extends QuickOpenHandler {
// Respond directly to empty search
if (!searchValue) {
promise = TPromise.as([]);
} else if (this.delayer) {
} else if (!this.options.skipDelay) {
promise = this.delayer.trigger(() => this.doGetResults(searchValue)); // Run search with delay as needed
} else {
promise = this.doGetResults(searchValue);
Expand All @@ -146,7 +151,6 @@ export class OpenSymbolHandler extends QuickOpenHandler {
}

private doGetResults(searchValue: string): TPromise<QuickOpenEntry[]> {

return getNavigateToItems(searchValue).then(bearings => {
return this.toQuickOpenEntries(bearings, searchValue);
});
Expand All @@ -157,6 +161,9 @@ export class OpenSymbolHandler extends QuickOpenHandler {

// Convert to Entries
types.forEach(element => {
if (this.options.skipLocalSymbols && !!element.containerName) {
return; // ignore local symbols if we are told so
}

// Find Highlights
let highlights = filters.matchesFuzzy(searchValue, element.name);
Expand Down Expand Up @@ -193,7 +200,7 @@ export class OpenSymbolHandler extends QuickOpenHandler {
});

// Sort (Standalone only)
if (this.isStandalone) {
if (!this.options.skipSorting) {
return results.sort(this.sort.bind(this, searchValue.toLowerCase()));
}

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/search/browser/search.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ actionBarRegistry.registerActionBarContributor(Scope.VIEWER, ExplorerViewerActio
'vs/workbench/parts/search/browser/openAnythingHandler',
'OpenAnythingHandler',
'',
nls.localize('openAnythingHandlerDescription', "Open Files and Symbols by Name")
nls.localize('openAnythingHandlerDescription', "Open Files and Global Symbols by Name")
)
);

Expand All @@ -151,7 +151,7 @@ actionBarRegistry.registerActionBarContributor(Scope.VIEWER, ExplorerViewerActio
{
prefix: ALL_SYMBOLS_PREFIX,
needsEditor: false,
description: nls.localize('openSymbolDescriptionNormal', "Open Symbol By Name")
description: nls.localize('openSymbolDescriptionNormal', "Open Any Symbol By Name")
}
]
)
Expand Down

0 comments on commit 7df7a47

Please sign in to comment.