Skip to content

Commit

Permalink
Merge pull request #160789 from microsoft/joh/issue160300
Browse files Browse the repository at this point in the history
look up alternative commands in the right map
  • Loading branch information
jrieken authored Sep 13, 2022
2 parents 7889b8a + 787468a commit 9b80ed6
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/vs/editor/contrib/gotoSymbol/browser/goToCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeE
import { EditorOption, GoToLocationValues } from 'vs/editor/common/config/editorOptions';
import * as corePosition from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
import { IEditorAction, ScrollType } from 'vs/editor/common/editorCommon';
import { ScrollType } from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { ITextModel } from 'vs/editor/common/model';
import { isLocationLink, Location, LocationLink } from 'vs/editor/common/languages';
Expand Down Expand Up @@ -56,9 +56,6 @@ export interface SymbolNavigationActionConfig {
muteMessage: boolean;
}




export class SymbolNavigationAnchor {

static is(thing: any): thing is SymbolNavigationAnchor {
Expand All @@ -79,7 +76,7 @@ export class SymbolNavigationAnchor {

export abstract class SymbolNavigationAction extends EditorAction2 {

private static _allSymbolNavigationCommands = new Set<string>();
private static _allSymbolNavigationCommands = new Map<string, SymbolNavigationAction>();
private static _activeAlternativeCommands = new Set<string>();

readonly configuration: SymbolNavigationActionConfig;
Expand All @@ -101,7 +98,7 @@ export abstract class SymbolNavigationAction extends EditorAction2 {
constructor(configuration: SymbolNavigationActionConfig, opts: IAction2Options) {
super(SymbolNavigationAction.aaa(opts));
this.configuration = configuration;
SymbolNavigationAction._allSymbolNavigationCommands.add(opts.id);
SymbolNavigationAction._allSymbolNavigationCommands.set(opts.id, this);
}

override runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, arg?: SymbolNavigationAnchor | unknown, range?: Range): Promise<void> {
Expand All @@ -113,6 +110,7 @@ export abstract class SymbolNavigationAction extends EditorAction2 {
const progressService = accessor.get(IEditorProgressService);
const symbolNavService = accessor.get(ISymbolNavigationService);
const languageFeaturesService = accessor.get(ILanguageFeaturesService);
const instaService = accessor.get(IInstantiationService);

const model = editor.getModel();
const position = editor.getPosition();
Expand All @@ -128,11 +126,11 @@ export abstract class SymbolNavigationAction extends EditorAction2 {

alert(references.ariaMessage);

let altAction: IEditorAction | null | undefined;
let altAction: SymbolNavigationAction | null | undefined;
if (references.referenceAt(model.uri, position)) {
const altActionId = this._getAlternativeCommand(editor);
if (!SymbolNavigationAction._activeAlternativeCommands.has(altActionId) && SymbolNavigationAction._allSymbolNavigationCommands.has(altActionId)) {
altAction = editor.getAction(altActionId);
altAction = SymbolNavigationAction._allSymbolNavigationCommands.get(altActionId)!;
}
}

Expand All @@ -147,9 +145,9 @@ export abstract class SymbolNavigationAction extends EditorAction2 {
} else if (referenceCount === 1 && altAction) {
// already at the only result, run alternative
SymbolNavigationAction._activeAlternativeCommands.add(this.desc.id);
altAction.run().finally(() => {
instaService.invokeFunction((accessor) => altAction!.runEditorCommand(accessor, editor, arg, range).finally(() => {
SymbolNavigationAction._activeAlternativeCommands.delete(this.desc.id);
});
}));

} else {
// normal results handling
Expand Down

0 comments on commit 9b80ed6

Please sign in to comment.