From 54462828cceaf5c8e23e28dbaf135737cfecaaed Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 6 Jan 2020 12:02:32 +0100 Subject: [PATCH] fix #87987 --- .../editor/contrib/gotoSymbol/goToCommands.ts | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/vs/editor/contrib/gotoSymbol/goToCommands.ts b/src/vs/editor/contrib/gotoSymbol/goToCommands.ts index da040c7481e..b0610d605b1 100644 --- a/src/vs/editor/contrib/gotoSymbol/goToCommands.ts +++ b/src/vs/editor/contrib/gotoSymbol/goToCommands.ts @@ -27,7 +27,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis import { INotificationService } from 'vs/platform/notification/common/notification'; import { IEditorProgressService } from 'vs/platform/progress/common/progress'; import { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefinitionsAtPosition, getDeclarationsAtPosition, getReferencesAtPosition } from './goToSymbol'; -import { CommandsRegistry } from 'vs/platform/commands/common/commands'; +import { CommandsRegistry, ICommandService } 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, GoToLocationValues } from 'vs/editor/common/config/editorOptions'; @@ -681,14 +681,11 @@ registerEditorAction(class PeekReferencesAction extends ReferencesAction { class GenericGoToLocationAction extends SymbolNavigationAction { constructor( + config: SymbolNavigationActionConfig, private readonly _references: Location[], - private readonly _gotoMultipleBehaviour: GoToLocationValues | undefined + private readonly _gotoMultipleBehaviour: GoToLocationValues | undefined, ) { - super({ - muteMessage: true, - openInPeek: false, - openToSide: false - }, { + super(config, { id: 'editor.action.goToLocation', label: nls.localize('label.generic', "Go To Any Symbol"), alias: 'Go To Any Symbol', @@ -725,11 +722,12 @@ CommandsRegistry.registerCommand({ { name: 'multiple', description: 'Define what to do when having multiple results, either `peek`, `gotoAndPeek`, or `goto' }, ] }, - handler: async (accessor: ServicesAccessor, resource: any, position: any, references: any, multiple?: any) => { + handler: async (accessor: ServicesAccessor, resource: any, position: any, references: any, multiple?: any, openInPeek?: boolean) => { assertType(URI.isUri(resource)); assertType(corePosition.Position.isIPosition(position)); assertType(Array.isArray(references)); assertType(typeof multiple === 'undefined' || typeof multiple === 'string'); + assertType(typeof openInPeek === 'undefined' || typeof openInPeek === 'boolean'); const editorService = accessor.get(ICodeEditorService); const editor = await editorService.openCodeEditor({ resource }, editorService.getFocusedCodeEditor()); @@ -739,13 +737,29 @@ CommandsRegistry.registerCommand({ editor.revealPositionInCenterIfOutsideViewport(position, ScrollType.Smooth); return editor.invokeWithinContext(accessor => { - const command = new GenericGoToLocationAction(references, multiple as GoToLocationValues); + const command = new GenericGoToLocationAction({ muteMessage: true, openInPeek: Boolean(openInPeek), openToSide: false }, references, multiple as GoToLocationValues); accessor.get(IInstantiationService).invokeFunction(command.run.bind(command), editor); }); } } }); +CommandsRegistry.registerCommand({ + id: 'editor.action.peekLocations', + description: { + description: 'Peek locations from a position in a file', + args: [ + { name: 'uri', description: 'The text document in which to start', constraint: URI }, + { name: 'position', description: 'The position at which to start', constraint: corePosition.Position.isIPosition }, + { name: 'locations', description: 'An array of locations.', constraint: Array }, + { name: 'multiple', description: 'Define what to do when having multiple results, either `peek`, `gotoAndPeek`, or `goto' }, + ] + }, + handler: async (accessor: ServicesAccessor, resource: any, position: any, references: any, multiple?: any) => { + accessor.get(ICommandService).executeCommand('editor.action.goToLocations', resource, position, references, multiple, true); + } +}); + //#endregion @@ -776,6 +790,6 @@ CommandsRegistry.registerCommand({ }); // use NEW command -CommandsRegistry.registerCommandAlias('editor.action.showReferences', 'editor.action.goToLocations'); +CommandsRegistry.registerCommandAlias('editor.action.showReferences', 'editor.action.peekLocations'); //#endregion