diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 74c45b792de077008a13317701798731208873f3..fe962ece0a65da2a9add0981cb0a2f457ed72ce5 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -1287,6 +1287,8 @@ class EditorFontSize extends SimpleEditorOption { //#region gotoLocation +export type GoToLocationValues = 'peek' | 'gotoAndPeek' | 'goto'; + /** * Configuration options for go to location */ @@ -1294,7 +1296,12 @@ 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>; @@ -1302,20 +1309,49 @@ export type GoToLocationOptions = Readonly>; class EditorGoToLocation extends BaseEditorOption { 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, }, } ); @@ -1327,7 +1363,12 @@ class EditorGoToLocation extends BaseEditorOption(input.multiple, this.defaultValue.multiple, ['peek', 'gotoAndPeek', 'goto']) + multiple: EditorStringEnumOption.stringSet(input.multiple, this.defaultValue.multiple!, ['peek', 'gotoAndPeek', 'goto']), + multipleDefinitions: input.multipleDefinitions ?? EditorStringEnumOption.stringSet(input.multipleDefinitions, 'peek', ['peek', 'gotoAndPeek', 'goto']), + multipleTypeDefinitions: input.multipleTypeDefinitions ?? EditorStringEnumOption.stringSet(input.multipleTypeDefinitions, 'peek', ['peek', 'gotoAndPeek', 'goto']), + multipleDeclarations: input.multipleDeclarations ?? EditorStringEnumOption.stringSet(input.multipleDeclarations, 'peek', ['peek', 'gotoAndPeek', 'goto']), + multipleImplemenations: input.multipleImplemenations ?? EditorStringEnumOption.stringSet(input.multipleImplemenations, 'peek', ['peek', 'gotoAndPeek', 'goto']), + multipleReferences: input.multipleReferences ?? EditorStringEnumOption.stringSet(input.multipleReferences, 'peek', ['peek', 'gotoAndPeek', 'goto']), }; } } diff --git a/src/vs/editor/contrib/gotoSymbol/goToCommands.ts b/src/vs/editor/contrib/gotoSymbol/goToCommands.ts index e52390d77e341b86f57c33bf29c0caa3a8103eed..b6651cd7a0daefa355b290a670d0b4253846cb1d 100644 --- a/src/vs/editor/contrib/gotoSymbol/goToCommands.ts +++ b/src/vs/editor/contrib/gotoSymbol/goToCommands.ts @@ -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'; @@ -108,16 +108,18 @@ 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 { - 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(); @@ -125,7 +127,7 @@ abstract class SymbolNavigationAction extends EditorAction { // keep remaining locations around when using // 'goto'-mode - if (gotoLocation.multiple === 'goto') { + if (gotoLocation === 'goto') { symbolNavService.put(next); } } @@ -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 @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index af28f20e735a63082cdfcf79d3f74fc7e1a1cf6d..69ead512a47b4d40c5f80fdcfd0b976d87d09f7f 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3060,6 +3060,8 @@ declare namespace monaco.editor { export type EditorFindOptions = Readonly>; + export type GoToLocationValues = 'peek' | 'gotoAndPeek' | 'goto'; + /** * Configuration options for go to location */ @@ -3067,7 +3069,12 @@ declare namespace monaco.editor { /** * 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>;