Skip to content

Commit

Permalink
add setting editor.gotoLocation.multipleReferences etc and deprecate …
Browse files Browse the repository at this point in the history
…editor.gotoLocation.multiple #83752
  • Loading branch information
jrieken committed Nov 5, 2019
1 parent 567ae20 commit ca03719
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 18 deletions.
65 changes: 53 additions & 12 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,35 +1287,71 @@ class EditorFontSize extends SimpleEditorOption<EditorOption.fontSize, number> {

//#region gotoLocation

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?: 'peek' | 'gotoAndPeek' | 'goto';
multiple?: GoToLocationValues;
multipleDefinitions?: GoToLocationValues;
multipleTypeDefinitions?: GoToLocationValues;
multipleDeclarations?: GoToLocationValues;
multipleImplemenations?: GoToLocationValues;
multipleReferences?: GoToLocationValues;
}

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

class EditorGoToLocation extends BaseEditorOption<EditorOption.gotoLocation, GoToLocationOptions> {

constructor() {
const defaults: GoToLocationOptions = { multiple: 'peek' };
const defaults: GoToLocationOptions = {
multiple: 'peek',
multipleDefinitions: 'peek',
multipleTypeDefinitions: 'peek',
multipleDeclarations: 'peek',
multipleImplemenations: 'peek',
multipleReferences: 'peek',
};
const jsonSubset = {
type: 'string',
enum: ['peek', 'gotoAndPeek', 'goto'],
default: defaults.multiple,
enumDescriptions: [
nls.localize('editor.gotoLocation.multiple.peek', 'Show peek view of the results (default)'),
nls.localize('editor.gotoLocation.multiple.gotoAndPeek', 'Go to the primary result and show a peek view'),
nls.localize('editor.gotoLocation.multiple.goto', 'Go to the primary result and enable peek-less navigation to others')
]
};
super(
EditorOption.gotoLocation, 'gotoLocation', defaults,
{
'editor.gotoLocation.multiple': {
description: nls.localize('editor.gotoLocation.multiple', "Controls the behavior of 'Go To' commands, like Go To Definition, when multiple target locations exist."),
type: 'string',
enum: ['peek', 'gotoAndPeek', 'goto'],
default: defaults.multiple,
enumDescriptions: [
nls.localize('editor.gotoLocation.multiple.peek', 'Show peek view of the results (default)'),
nls.localize('editor.gotoLocation.multiple.gotoAndPeek', 'Go to the primary result and show a peek view'),
nls.localize('editor.gotoLocation.multiple.goto', 'Go to the primary result and enable peek-less navigation to others')
]
deprecationMessage: nls.localize('editor.gotoLocation.multiple.deprecated', "This setting is deprecated, please use separate settings like 'editor.editor.gotoLocation.multipleDefinitions' or 'editor.editor.gotoLocation.multipleImplemenations' instead."),
},
'editor.gotoLocation.multipleDefinitions': {
description: nls.localize('editor.editor.gotoLocation.multipleDefinitions', "Controls the behavior the 'Go to Definition'-command when multiple target locations exist."),
...jsonSubset,
},
'editor.gotoLocation.multipleTypeDefinitions': {
description: nls.localize('editor.editor.gotoLocation.multipleTypeDefinitions', "Controls the behavior the 'Go to Type Definition'-command when multiple target locations exist."),
...jsonSubset,
},
'editor.gotoLocation.multipleDeclarations': {
description: nls.localize('editor.editor.gotoLocation.multipleDeclarations', "Controls the behavior the 'Go to Declaration'-command when multiple target locations exist."),
...jsonSubset,
},
'editor.gotoLocation.multipleImplemenations': {
description: nls.localize('editor.editor.gotoLocation.multipleImplemenattions', "Controls the behavior the 'Go to Implemenations'-command when multiple target locations exist."),
...jsonSubset,
},
'editor.gotoLocation.multipleReferences': {
description: nls.localize('editor.editor.gotoLocation.multipleReferences', "Controls the behavior the 'Go to References'-command when multiple target locations exist."),
...jsonSubset,
},
}
);
Expand All @@ -1327,7 +1363,12 @@ class EditorGoToLocation extends BaseEditorOption<EditorOption.gotoLocation, GoT
}
const input = _input as IGotoLocationOptions;
return {
multiple: EditorStringEnumOption.stringSet<'peek' | 'gotoAndPeek' | 'goto'>(input.multiple, this.defaultValue.multiple, ['peek', 'gotoAndPeek', 'goto'])
multiple: EditorStringEnumOption.stringSet<GoToLocationValues>(input.multiple, this.defaultValue.multiple!, ['peek', 'gotoAndPeek', 'goto']),
multipleDefinitions: input.multipleDefinitions ?? EditorStringEnumOption.stringSet<GoToLocationValues>(input.multipleDefinitions, 'peek', ['peek', 'gotoAndPeek', 'goto']),
multipleTypeDefinitions: input.multipleTypeDefinitions ?? EditorStringEnumOption.stringSet<GoToLocationValues>(input.multipleTypeDefinitions, 'peek', ['peek', 'gotoAndPeek', 'goto']),
multipleDeclarations: input.multipleDeclarations ?? EditorStringEnumOption.stringSet<GoToLocationValues>(input.multipleDeclarations, 'peek', ['peek', 'gotoAndPeek', 'goto']),
multipleImplemenations: input.multipleImplemenations ?? EditorStringEnumOption.stringSet<GoToLocationValues>(input.multipleImplemenations, 'peek', ['peek', 'gotoAndPeek', 'goto']),
multipleReferences: input.multipleReferences ?? EditorStringEnumOption.stringSet<GoToLocationValues>(input.multipleReferences, 'peek', ['peek', 'gotoAndPeek', 'goto']),
};
}
}
Expand Down
32 changes: 27 additions & 5 deletions src/vs/editor/contrib/gotoSymbol/goToCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefiniti
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { EditorStateCancellationTokenSource, CodeEditorStateFlag } from 'vs/editor/browser/core/editorState';
import { ISymbolNavigationService } from 'vs/editor/contrib/gotoSymbol/symbolNavigation';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { EditorOption, GoToLocationValues } from 'vs/editor/common/config/editorOptions';
import { isStandalone } from 'vs/base/browser/browser';
import { URI } from 'vs/base/common/uri';

Expand Down Expand Up @@ -108,24 +108,26 @@ abstract class SymbolNavigationAction extends EditorAction {

protected abstract _getAlternativeCommand(): string;

protected abstract _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues;

private async _onResult(editorService: ICodeEditorService, symbolNavService: ISymbolNavigationService, editor: IActiveCodeEditor, model: ReferencesModel): Promise<void> {

const gotoLocation = editor.getOption(EditorOption.gotoLocation);
if (this._configuration.openInPeek || (gotoLocation.multiple === 'peek' && model.references.length > 1)) {
const gotoLocation = this._getGoToPreference(editor);
if (this._configuration.openInPeek || (gotoLocation === 'peek' && model.references.length > 1)) {
this._openInPeek(editorService, editor, model);

} else {
const next = model.firstReference()!;
const targetEditor = await this._openReference(editor, editorService, next, this._configuration.openToSide);
if (targetEditor && model.references.length > 1 && gotoLocation.multiple === 'gotoAndPeek') {
if (targetEditor && model.references.length > 1 && gotoLocation === 'gotoAndPeek') {
this._openInPeek(editorService, targetEditor, model);
} else {
model.dispose();
}

// keep remaining locations around when using
// 'goto'-mode
if (gotoLocation.multiple === 'goto') {
if (gotoLocation === 'goto') {
symbolNavService.put(next);
}
}
Expand Down Expand Up @@ -190,6 +192,10 @@ export class DefinitionAction extends SymbolNavigationAction {
protected _getAlternativeCommand(): string {
return 'editor.action.referenceSearch.trigger';
}

protected _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues {
return editor.getOption(EditorOption.gotoLocation).multipleDefinitions;
}
}

const goToDefinitionKb = isWeb && !isStandalone
Expand Down Expand Up @@ -309,6 +315,10 @@ class DeclarationAction extends SymbolNavigationAction {
protected _getAlternativeCommand(): string {
return 'editor.action.referenceSearch.trigger';
}

protected _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues {
return editor.getOption(EditorOption.gotoLocation).multipleDeclarations;
}
}

registerEditorAction(class GoToDeclarationAction extends DeclarationAction {
Expand Down Expand Up @@ -390,6 +400,10 @@ class TypeDefinitionAction extends SymbolNavigationAction {
protected _getAlternativeCommand(): string {
return 'editor.action.referenceSearch.trigger';
}

protected _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues {
return editor.getOption(EditorOption.gotoLocation).multipleTypeDefinitions;
}
}

registerEditorAction(class GoToTypeDefinitionAction extends TypeDefinitionAction {
Expand Down Expand Up @@ -475,6 +489,10 @@ class ImplementationAction extends SymbolNavigationAction {
protected _getAlternativeCommand(): string {
return '';
}

protected _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues {
return editor.getOption(EditorOption.gotoLocation).multipleImplemenations;
}
}

registerEditorAction(class GoToImplementationAction extends ImplementationAction {
Expand Down Expand Up @@ -561,6 +579,10 @@ class ReferencesAction extends SymbolNavigationAction {
protected _getAlternativeCommand(): string {
return '';
}

protected _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues {
return editor.getOption(EditorOption.gotoLocation).multipleReferences;
}
}

registerEditorAction(class GoToReferencesAction extends ReferencesAction {
Expand Down
9 changes: 8 additions & 1 deletion src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3060,14 +3060,21 @@ declare namespace monaco.editor {

export type EditorFindOptions = Readonly<Required<IEditorFindOptions>>;

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?: 'peek' | 'gotoAndPeek' | 'goto';
multiple?: GoToLocationValues;
multipleDefinitions?: GoToLocationValues;
multipleTypeDefinitions?: GoToLocationValues;
multipleDeclarations?: GoToLocationValues;
multipleImplemenations?: GoToLocationValues;
multipleReferences?: GoToLocationValues;
}

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

0 comments on commit ca03719

Please sign in to comment.