Skip to content

Commit

Permalink
add alternative command settings, #73081
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 22, 2019
1 parent e465e92 commit 92735e1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
46 changes: 43 additions & 3 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1300,15 +1300,20 @@ export type GoToLocationValues = 'peek' | 'gotoAndPeek' | 'goto';
* Configuration options for go to location
*/
export interface IGotoLocationOptions {
/**
* Control how goto-command work when having multiple results.
*/

multiple?: GoToLocationValues;

multipleDefinitions?: GoToLocationValues;
multipleTypeDefinitions?: GoToLocationValues;
multipleDeclarations?: GoToLocationValues;
multipleImplementations?: GoToLocationValues;
multipleReferences?: GoToLocationValues;

alternativeDefinitionCommand?: string;
alternativeTypeDefinitionCommand?: string;
alternativeDeclarationCommand?: string;
alternativeImplementationCommand?: string;
alternativeReferenceCommand?: string;
}

export type GoToLocationOptions = Readonly<Required<IGotoLocationOptions>>;
Expand All @@ -1323,6 +1328,11 @@ class EditorGoToLocation extends BaseEditorOption<EditorOption.gotoLocation, GoT
multipleDeclarations: 'peek',
multipleImplementations: 'peek',
multipleReferences: 'peek',
alternativeDefinitionCommand: 'editor.action.goToReferences',
alternativeTypeDefinitionCommand: 'editor.action.goToReferences',
alternativeDeclarationCommand: 'editor.action.goToReferences',
alternativeImplementationCommand: '',
alternativeReferenceCommand: '',
};
const jsonSubset: IJSONSchema = {
type: 'string',
Expand Down Expand Up @@ -1360,6 +1370,31 @@ class EditorGoToLocation extends BaseEditorOption<EditorOption.gotoLocation, GoT
description: nls.localize('editor.editor.gotoLocation.multipleReferences', "Controls the behavior the 'Go to References'-command when multiple target locations exist."),
...jsonSubset,
},
'editor.gotoLocation.alternativeDefinitionCommand': {
type: 'string',
default: defaults.alternativeDefinitionCommand,
description: nls.localize('alternativeDefinitionCommand', "Alternative command id that is being executed when the result of 'Go to Definition' is the current location.")
},
'editor.gotoLocation.alternativeTypeDefinitionCommand': {
type: 'string',
default: defaults.alternativeTypeDefinitionCommand,
description: nls.localize('alternativeTypeDefinitionCommand', "Alternative command id that is being executed when the result of 'Go to Type Definition' is the current location.")
},
'editor.gotoLocation.alternativeDeclarationCommand': {
type: 'string',
default: defaults.alternativeDeclarationCommand,
description: nls.localize('alternativeDeclarationCommand', "Alternative command id that is being executed when the result of 'Go to Declaration' is the current location.")
},
'editor.gotoLocation.alternativeImplementationCommand': {
type: 'string',
default: defaults.alternativeImplementationCommand,
description: nls.localize('alternativeImplementationCommand', "Alternative command id that is being executed when the result of 'Go to Implementation' is the current location.")
},
'editor.gotoLocation.alternativeReferenceCommand': {
type: 'string',
default: defaults.alternativeReferenceCommand,
description: nls.localize('alternativeReferenceCommand', "Alternative command id that is being executed when the result of 'Go to Reference' is the current location.")
},
}
);
}
Expand All @@ -1376,6 +1411,11 @@ class EditorGoToLocation extends BaseEditorOption<EditorOption.gotoLocation, GoT
multipleDeclarations: input.multipleDeclarations ?? EditorStringEnumOption.stringSet<GoToLocationValues>(input.multipleDeclarations, 'peek', ['peek', 'gotoAndPeek', 'goto']),
multipleImplementations: input.multipleImplementations ?? EditorStringEnumOption.stringSet<GoToLocationValues>(input.multipleImplementations, 'peek', ['peek', 'gotoAndPeek', 'goto']),
multipleReferences: input.multipleReferences ?? EditorStringEnumOption.stringSet<GoToLocationValues>(input.multipleReferences, 'peek', ['peek', 'gotoAndPeek', 'goto']),
alternativeDefinitionCommand: EditorStringOption.string(input.alternativeDefinitionCommand, this.defaultValue.alternativeDefinitionCommand),
alternativeTypeDefinitionCommand: EditorStringOption.string(input.alternativeTypeDefinitionCommand, this.defaultValue.alternativeTypeDefinitionCommand),
alternativeDeclarationCommand: EditorStringOption.string(input.alternativeDeclarationCommand, this.defaultValue.alternativeDeclarationCommand),
alternativeImplementationCommand: EditorStringOption.string(input.alternativeImplementationCommand, this.defaultValue.alternativeImplementationCommand),
alternativeReferenceCommand: EditorStringOption.string(input.alternativeReferenceCommand, this.defaultValue.alternativeReferenceCommand),
};
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/vs/editor/contrib/gotoSymbol/goToCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ abstract class SymbolNavigationAction extends EditorAction {
alert(references.ariaMessage);

const referenceCount = references.references.length;
const altAction = references.referenceAt(model.uri, pos) && editor.getAction(this._getAlternativeCommand());
const altAction = references.referenceAt(model.uri, pos) && editor.getAction(this._getAlternativeCommand(editor));

if (referenceCount === 0) {
// no result -> show message
Expand Down Expand Up @@ -115,7 +115,7 @@ abstract class SymbolNavigationAction extends EditorAction {

protected abstract _getNoResultFoundMessage(info: IWordAtPosition | null): string;

protected abstract _getAlternativeCommand(): string;
protected abstract _getAlternativeCommand(editor: IActiveCodeEditor): string;

protected abstract _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues;

Expand Down Expand Up @@ -203,8 +203,8 @@ export class DefinitionAction extends SymbolNavigationAction {
: nls.localize('generic.noResults', "No definition found");
}

protected _getAlternativeCommand(): string {
return 'editor.action.goToReferences';
protected _getAlternativeCommand(editor: IActiveCodeEditor): string {
return editor.getOption(EditorOption.gotoLocation).alternativeDefinitionCommand;
}

protected _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues {
Expand Down Expand Up @@ -327,8 +327,8 @@ class DeclarationAction extends SymbolNavigationAction {
: nls.localize('decl.generic.noResults', "No declaration found");
}

protected _getAlternativeCommand(): string {
return 'editor.action.goToReferences';
protected _getAlternativeCommand(editor: IActiveCodeEditor): string {
return editor.getOption(EditorOption.gotoLocation).alternativeDeclarationCommand;
}

protected _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues {
Expand Down Expand Up @@ -412,8 +412,8 @@ class TypeDefinitionAction extends SymbolNavigationAction {
: nls.localize('goToTypeDefinition.generic.noResults', "No type definition found");
}

protected _getAlternativeCommand(): string {
return 'editor.action.goToReferences';
protected _getAlternativeCommand(editor: IActiveCodeEditor): string {
return editor.getOption(EditorOption.gotoLocation).alternativeTypeDefinitionCommand;
}

protected _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues {
Expand Down Expand Up @@ -498,8 +498,8 @@ class ImplementationAction extends SymbolNavigationAction {
: nls.localize('goToImplementation.generic.noResults', "No implementation found");
}

protected _getAlternativeCommand(): string {
return '';
protected _getAlternativeCommand(editor: IActiveCodeEditor): string {
return editor.getOption(EditorOption.gotoLocation).alternativeImplementationCommand;
}

protected _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues {
Expand Down Expand Up @@ -589,8 +589,8 @@ class ReferencesAction extends SymbolNavigationAction {
: nls.localize('references.noGeneric', "No references found");
}

protected _getAlternativeCommand(): string {
return '';
protected _getAlternativeCommand(editor: IActiveCodeEditor): string {
return editor.getOption(EditorOption.gotoLocation).alternativeReferenceCommand;
}

protected _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues {
Expand Down
8 changes: 5 additions & 3 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3066,15 +3066,17 @@ declare namespace monaco.editor {
* Configuration options for go to location
*/
export interface IGotoLocationOptions {
/**
* Control how goto-command work when having multiple results.
*/
multiple?: GoToLocationValues;
multipleDefinitions?: GoToLocationValues;
multipleTypeDefinitions?: GoToLocationValues;
multipleDeclarations?: GoToLocationValues;
multipleImplementations?: GoToLocationValues;
multipleReferences?: GoToLocationValues;
alternativeDefinitionCommand?: string;
alternativeTypeDefinitionCommand?: string;
alternativeDeclarationCommand?: string;
alternativeImplementationCommand?: string;
alternativeReferenceCommand?: string;
}

export type GoToLocationOptions = Readonly<Required<IGotoLocationOptions>>;
Expand Down

0 comments on commit 92735e1

Please sign in to comment.