From cf6b330a45796210a2dc927b065867a0c71cb5a4 Mon Sep 17 00:00:00 2001 From: Josh Pinkney Date: Mon, 24 Jun 2019 12:14:30 -0400 Subject: [PATCH] Added mappings from vscode commands to internal commands Signed-off-by: Josh Pinkney --- packages/plugin-ext/src/common/index.ts | 1 + .../plugin-ext/src/common/known-commands.ts | 329 ++++++++++++++++++ .../keybindings-contribution-handler.ts | 13 +- .../plugin-ext/src/plugin/command-registry.ts | 8 +- .../plugin-ext/src/plugin/type-converters.ts | 60 +--- 5 files changed, 348 insertions(+), 63 deletions(-) create mode 100644 packages/plugin-ext/src/common/known-commands.ts diff --git a/packages/plugin-ext/src/common/index.ts b/packages/plugin-ext/src/common/index.ts index 9d653b922fe83..70fe4d10aa5f9 100644 --- a/packages/plugin-ext/src/common/index.ts +++ b/packages/plugin-ext/src/common/index.ts @@ -18,3 +18,4 @@ export * from './plugin-protocol'; export * from './plugin-api-rpc'; export * from './plugin-ext-api-contribution'; +export * from './known-commands'; diff --git a/packages/plugin-ext/src/common/known-commands.ts b/packages/plugin-ext/src/common/known-commands.ts new file mode 100644 index 0000000000000..a0dcc7d17ef11 --- /dev/null +++ b/packages/plugin-ext/src/common/known-commands.ts @@ -0,0 +1,329 @@ +/******************************************************************************** + * Copyright (C) 2019 Red Hat, Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { Range as R, Position as P, Location as L } from 'vscode-languageserver-types'; +import URI from 'vscode-uri'; +import * as theia from '@theia/plugin'; + +// Here is a mapping of VSCode commands to monaco commands with their conversions +export namespace KnownCommands { + + /** + * Commands that you want to apply custom conversions to rather than pass through the automatic args converter. + * Would be useful in the case where theia provides some command and you need to provide custom conversions + */ + // tslint:disable-next-line:no-any + export const transformers: { [id: string]: [string, (args: any[] | undefined) => any[] | undefined] } = {}; + transformers['editor.action.showReferences'] = ['textEditor.commands.showReferences', createConversionFunction( + (uri: URI) => uri.toString(), + fromPositionToP, + toArrayConversion(fromLocationToL))]; + + export function mapped(id: string): boolean { + return !!mappings[id]; + } + + /** + * Commands that have a name in theia that is different from their name in vscode + */ + export const mappings: { [id: string]: string } = {}; + + /** + * Mapping of all editor.action commands to their monaco counterpart. + * executeCommand inside of the plugin command registry will automatically convert + * incoming arguments from vscode api types to monaco types + */ + mappings['editor.action.select.all'] = 'monaco.editor.action.select.all'; + mappings['editor.action.toggleHighContrast'] = 'monaco.editor.action.toggleHighContrast'; + mappings['editor.action.moveCarretLeftAction'] = 'monaco.editor.action.moveCarretLeftAction'; + mappings['editor.action.moveCarretRightAction'] = 'monaco.editor.action.moveCarretRightAction'; + mappings['editor.action.transposeLetters'] = 'monaco.editor.action.transposeLetters'; + mappings['editor.action.clipboardCopyWithSyntaxHighlightingAction'] = 'monaco.editor.action.clipboardCopyWithSyntaxHighlightingAction'; + mappings['editor.action.commentLine'] = 'monaco.editor.action.commentLine'; + mappings['editor.action.addCommentLine'] = 'monaco.editor.action.addCommentLine'; + mappings['editor.action.removeCommentLine'] = 'monaco.editor.action.removeCommentLine'; + mappings['editor.action.blockComment'] = 'monaco.editor.action.blockComment'; + mappings['editor.action.showContextMenu'] = 'monaco.editor.action.showContextMenu'; + mappings['cursorUndo'] = 'monaco.cursorUndo'; + mappings['editor.unfold'] = 'monaco.editor.unfold'; + mappings['editor.unfoldRecursively'] = 'monaco.editor.unfoldRecursively'; + mappings['editor.fold'] = 'monaco.editor.fold'; + mappings['editor.foldRecursively'] = 'monaco.editor.foldRecursively'; + mappings['editor.foldAll'] = 'monaco.editor.foldAll'; + mappings['editor.unfoldAll'] = 'monaco.editor.unfoldAll'; + mappings['editor.foldAllBlockComments'] = 'monaco.editor.foldAllBlockComments'; + mappings['editor.foldAllMarkerRegions'] = 'monaco.editor.foldAllMarkerRegions'; + mappings['editor.unfoldAllMarkerRegions'] = 'monaco.editor.unfoldAllMarkerRegions'; + mappings['editor.foldLevel1'] = 'monaco.editor.foldLevel1'; + mappings['editor.foldLevel2'] = 'monaco.editor.foldLevel2'; + mappings['editor.foldLevel3'] = 'monaco.editor.foldLevel3'; + mappings['editor.foldLevel4'] = 'monaco.editor.foldLevel4'; + mappings['editor.foldLevel5'] = 'monaco.editor.foldLevel5'; + mappings['editor.foldLevel6'] = 'monaco.editor.foldLevel6'; + mappings['editor.foldLevel7'] = 'monaco.editor.foldLevel7'; + mappings['editor.action.fontZoomIn'] = 'monaco.editor.action.fontZoomIn'; + mappings['editor.action.fontZoomOut'] = 'monaco.editor.action.fontZoomOut'; + mappings['editor.action.fontZoomReset'] = 'monaco.editor.action.fontZoomReset'; + mappings['editor.action.formatDocument'] = 'monaco.editor.action.formatDocument'; + mappings['editor.action.formatSelection'] = 'monaco.editor.action.formatSelection'; + mappings['editor.action.copyLinesUpAction'] = 'monaco.editor.action.copyLinesUpAction'; + mappings['editor.action.copyLinesDownAction'] = 'monaco.editor.action.copyLinesDownAction'; + mappings['editor.action.moveLinesUpAction'] = 'monaco.editor.action.moveLinesUpAction'; + mappings['editor.action.moveLinesDownAction'] = 'monaco.editor.action.moveLinesDownAction'; + mappings['editor.action.sortLinesAscending'] = 'monaco.editor.action.sortLinesAscending'; + mappings['editor.action.sortLinesDescending'] = 'monaco.editor.action.sortLinesDescending'; + mappings['editor.action.trimTrailingWhitespace'] = 'monaco.editor.action.trimTrailingWhitespace'; + mappings['editor.action.deleteLines'] = 'monaco.editor.action.deleteLines'; + mappings['editor.action.indentLines'] = 'monaco.editor.action.indentLines'; + mappings['editor.action.outdentLines'] = 'monaco.editor.action.outdentLines'; + mappings['editor.action.insertLineBefore'] = 'monaco.editor.action.insertLineBefore'; + mappings['editor.action.insertLineAfter'] = 'monaco.editor.action.insertLineAfter'; + mappings['deleteAllLeft'] = 'monaco.deleteAllLeft'; + mappings['deleteAllRight'] = 'monaco.deleteAllRight'; + mappings['editor.action.joinLines'] = 'monaco.editor.action.joinLines'; + mappings['editor.action.transpose'] = 'monaco.editor.action.transpose'; + mappings['editor.action.transformToUppercase'] = 'monaco.editor.action.transformToUppercase'; + mappings['editor.action.transformToLowercase'] = 'monaco.editor.action.transformToLowercase'; + mappings['editor.action.transformToTitlecase'] = 'monaco.editor.action.transformToTitlecase'; + mappings['editor.action.smartSelect.expand'] = 'monaco.editor.action.smartSelect.expand'; + mappings['editor.action.smartSelect.shrink'] = 'monaco.editor.action.smartSelect.shrink'; + mappings['editor.action.forceRetokenize'] = 'monaco.editor.action.forceRetokenize'; + mappings['editor.action.toggleTabFocusMode'] = 'monaco.editor.action.toggleTabFocusMode'; + mappings['editor.action.gotoLine'] = 'monaco.editor.action.gotoLine'; + mappings['editor.action.quickOutline'] = 'monaco.editor.action.quickOutline'; + mappings['editor.action.inPlaceReplace.up'] = 'monaco.editor.action.inPlaceReplace.up'; + mappings['editor.action.inPlaceReplace.down'] = 'monaco.editor.action.inPlaceReplace.down'; + mappings['editor.action.diffReview.next'] = 'monaco.editor.action.diffReview.next'; + mappings['editor.action.diffReview.prev'] = 'monaco.editor.action.diffReview.prev'; + mappings['editor.action.selectToBracket'] = 'monaco.editor.action.selectToBracket'; + mappings['editor.action.jumpToBracket'] = 'monaco.editor.action.jumpToBracket'; + mappings['actions.findWithSelection'] = 'monaco.actions.findWithSelection'; + mappings['editor.action.nextMatchFindAction'] = 'monaco.editor.action.nextMatchFindAction'; + mappings['editor.action.previousMatchFindAction'] = 'monaco.editor.action.previousMatchFindAction'; + mappings['editor.action.nextSelectionMatchFindAction'] = 'monaco.editor.action.nextSelectionMatchFindAction'; + mappings['editor.action.previousSelectionMatchFindAction'] = 'monaco.editor.action.previousSelectionMatchFindAction'; + mappings['editor.action.openLink'] = 'monaco.editor.action.openLink'; + mappings['editor.action.quickFix'] = 'monaco.editor.action.quickFix'; + mappings['editor.action.refactor'] = 'monaco.editor.action.refactor'; + mappings['editor.action.sourceAction'] = 'monaco.editor.action.sourceAction'; + mappings['editor.action.organizeImports'] = 'monaco.editor.action.organizeImports'; + mappings['editor.action.autoFix'] = 'monaco.editor.action.autoFix'; + mappings['editor.action.fixAll'] = 'monaco.editor.action.fixAll'; + mappings['editor.action.rename'] = 'monaco.editor.action.rename'; + mappings['editor.action.insertCursorAbove'] = 'monaco.editor.action.insertCursorAbove'; + mappings['editor.action.insertCursorBelow'] = 'monaco.editor.action.insertCursorBelow'; + mappings['editor.action.insertCursorAtEndOfEachLineSelected'] = 'monaco.editor.action.insertCursorAtEndOfEachLineSelected'; + mappings['editor.action.addSelectionToNextFindMatch'] = 'monaco.editor.action.addSelectionToNextFindMatch'; + mappings['editor.action.addSelectionToPreviousFindMatch'] = 'monaco.editor.action.addSelectionToPreviousFindMatch'; + mappings['editor.action.moveSelectionToNextFindMatch'] = 'monaco.editor.action.moveSelectionToNextFindMatch'; + mappings['editor.action.moveSelectionToPreviousFindMatch'] = 'monaco.editor.action.moveSelectionToPreviousFindMatch'; + mappings['editor.action.selectHighlights'] = 'monaco.editor.action.selectHighlights'; + mappings['editor.action.changeAll'] = 'monaco.editor.action.changeAll'; + mappings['editor.action.addCursorsToBottom'] = 'monaco.editor.action.addCursorsToBottom'; + mappings['editor.action.addCursorsToTop'] = 'monaco.editor.action.addCursorsToTop'; + mappings['editor.action.triggerParameterHints'] = 'monaco.editor.action.triggerParameterHints'; + mappings['editor.action.wordHighlight.next'] = 'monaco.editor.action.wordHighlight.next'; + mappings['editor.action.wordHighlight.prev'] = 'monaco.editor.action.wordHighlight.prev'; + mappings['editor.action.wordHighlight.trigger'] = 'monaco.editor.action.wordHighlight.trigger'; + mappings['editor.action.showAccessibilityHelp'] = 'monaco.editor.action.showAccessibilityHelp'; + mappings['editor.action.inspectTokens'] = 'monaco.editor.action.inspectTokens'; + mappings['editor.action.marker.next'] = 'monaco.editor.action.marker.next'; + mappings['editor.action.marker.prev'] = 'monaco.editor.action.marker.prev'; + mappings['editor.action.marker.nextInFiles'] = 'monaco.editor.action.marker.nextInFiles'; + mappings['editor.action.marker.prevInFiles'] = 'monaco.editor.action.marker.prevInFiles'; + mappings['editor.action.showHover'] = 'monaco.editor.action.showHover'; + mappings['editor.action.revealDefinition'] = 'monaco.editor.action.revealDefinition'; + mappings['editor.action.revealDefinitionAside'] = 'monaco.editor.action.revealDefinitionAside'; + mappings['editor.action.peekDefinition'] = 'monaco.editor.action.peekDefinition'; + mappings['editor.action.revealDeclaration'] = 'monaco.editor.action.revealDeclaration'; + mappings['editor.action.peekDeclaration'] = 'monaco.editor.action.peekDeclaration'; + mappings['editor.action.goToImplementation'] = 'monaco.editor.action.goToImplementation'; + mappings['editor.action.peekImplementation'] = 'monaco.editor.action.peekImplementation'; + mappings['editor.action.goToTypeDefinition'] = 'monaco.editor.action.goToTypeDefinition'; + mappings['editor.action.peekTypeDefinition'] = 'monaco.editor.action.peekTypeDefinition'; + mappings['editor.action.referenceSearch.trigger'] = 'monaco.editor.action.referenceSearch.trigger'; + mappings['editor.action.triggerSuggest'] = 'monaco.editor.action.triggerSuggest'; + mappings['closeReferenceSearchEditor'] = 'monaco.closeReferenceSearchEditor'; + mappings['cancelSelection'] = 'monaco.cancelSelection'; + mappings['cursorBottom'] = 'monaco.cursorBottom'; + mappings['cursorBottomSelect'] = 'monaco.cursorBottomSelect'; + mappings['cursorDown'] = 'monaco.cursorDown'; + mappings['cursorDownSelect'] = 'monaco.cursorDownSelect'; + mappings['cursorEnd'] = 'monaco.cursorEnd'; + mappings['cursorEndSelect'] = 'monaco.cursorEndSelect'; + mappings['cursorHome'] = 'monaco.cursorHome'; + mappings['cursorHomeSelect'] = 'monaco.cursorHomeSelect'; + mappings['cursorLeft'] = 'monaco.cursorLeft'; + mappings['cursorLeftSelect'] = 'monaco.cursorLeftSelect'; + mappings['cursorPageDown'] = 'monaco.cursorPageDown'; + mappings['cursorPageDownSelect'] = 'monaco.cursorPageDownSelect'; + mappings['cursorPageUp'] = 'monaco.cursorPageUp'; + mappings['cursorPageUpSelect'] = 'monaco.cursorPageUpSelect'; + mappings['cursorRight'] = 'monaco.cursorRight'; + mappings['cursorRightSelect'] = 'monaco.cursorRightSelect'; + mappings['cursorTop'] = 'monaco.cursorTop'; + mappings['cursorTopSelect'] = 'monaco.cursorTopSelect'; + mappings['cursorUp'] = 'monaco.cursorUp'; + mappings['cursorUpSelect'] = 'monaco.cursorUpSelect'; + mappings['deleteLeft'] = 'monaco.deleteLeft'; + mappings['deleteRight'] = 'monaco.deleteRight'; + mappings['editor.action.selectAll'] = 'monaco.editor.action.selectAll'; + mappings['expandLineSelection'] = 'monaco.expandLineSelection'; + mappings['outdent'] = 'monaco.outdent'; + mappings['scrollLineDown'] = 'monaco.scrollLineDown'; + mappings['scrollLineUp'] = 'monaco.scrollLineUp'; + mappings['scrollPageDown'] = 'monaco.scrollPageDown'; + mappings['scrollPageUp'] = 'monaco.scrollPageUp'; + mappings['tab'] = 'monaco.tab'; + mappings['removeSecondaryCursors'] = 'monaco.removeSecondaryCursors'; + mappings['cursorWordEndRight'] = 'monaco.cursorWordEndRight'; + mappings['cursorWordEndRightSelect'] = 'monaco.cursorWordEndRightSelect'; + mappings['cursorWordStartLeft'] = 'monaco.cursorWordStartLeft'; + mappings['cursorWordStartLeftSelect'] = 'monaco.cursorWordStartLeftSelect'; + mappings['deleteWordLeft'] = 'monaco.deleteWordLeft'; + mappings['deleteWordRight'] = 'monaco.deleteWordRight'; + mappings['editor.cancelOperation'] = 'monaco.editor.cancelOperation'; + mappings['editor.gotoNextSymbolFromResult'] = 'monaco.editor.gotoNextSymbolFromResult'; + mappings['editor.gotoNextSymbolFromResult.cancel'] = 'monaco.editor.gotoNextSymbolFromResult.cancel'; + mappings['openReferenceToSide'] = 'monaco.openReferenceToSide'; + mappings['toggleExplainMode'] = 'monaco.toggleExplainMode'; + mappings['closeFindWidget'] = 'monaco.closeFindWidget'; + mappings['editor.action.replaceAll'] = 'monaco.editor.action.replaceAll'; + mappings['editor.action.replaceOne'] = 'monaco.editor.action.replaceOne'; + mappings['editor.action.selectAllMatches'] = 'monaco.editor.action.selectAllMatches'; + mappings['toggleFindCaseSensitive'] = 'monaco.toggleFindCaseSensitive'; + mappings['toggleFindInSelection'] = 'monaco.toggleFindInSelection'; + mappings['toggleFindRegex'] = 'monaco.toggleFindRegex'; + mappings['toggleFindWholeWord'] = 'monaco.toggleFindWholeWord'; + mappings['jumpToNextSnippetPlaceholder'] = 'monaco.jumpToNextSnippetPlaceholder'; + mappings['jumpToPrevSnippetPlaceholder'] = 'monaco.jumpToPrevSnippetPlaceholder'; + mappings['leaveEditorMessage'] = 'monaco.leaveEditorMessage'; + mappings['leaveSnippet'] = 'monaco.leaveSnippet'; + mappings['closeMarkersNavigation'] = 'monaco.closeMarkersNavigation'; + mappings['goToNextReferenceFromEmbeddedEditor'] = 'monaco.goToNextReferenceFromEmbeddedEditor'; + mappings['goToPreviousReferenceFromEmbeddedEditor'] = 'monaco.goToPreviousReferenceFromEmbeddedEditor'; + mappings['closeParameterHints'] = 'monaco.closeParameterHints'; + mappings['showNextParameterHint'] = 'monaco.showNextParameterHint'; + mappings['showPrevParameterHint'] = 'monaco.showPrevParameterHint'; + mappings['acceptSelectedSuggestion'] = 'monaco.acceptSelectedSuggestion'; + mappings['acceptSelectedSuggestionOnEnter'] = 'monaco.acceptSelectedSuggestionOnEnter'; + mappings['hideSuggestWidget'] = 'monaco.hideSuggestWidget'; + mappings['insertBestCompletion'] = 'monaco.insertBestCompletion'; + mappings['insertNextSuggestion'] = 'monaco.insertNextSuggestion'; + mappings['insertPrevSuggestion'] = 'monaco.insertPrevSuggestion'; + mappings['selectNextPageSuggestion'] = 'monaco.selectNextPageSuggestion'; + mappings['selectNextSuggestion'] = 'monaco.selectNextSuggestion'; + mappings['selectPrevPageSuggestion'] = 'monaco.selectPrevPageSuggestion'; + mappings['selectPrevSuggestion'] = 'monaco.selectPrevSuggestion'; + mappings['toggleSuggestionDetails'] = 'monaco.toggleSuggestionDetails'; + mappings['toggleSuggestionFocus'] = 'monaco.toggleSuggestionFocus'; + mappings['acceptRenameInput'] = 'monaco.acceptRenameInput'; + mappings['cancelRenameInput'] = 'monaco.cancelRenameInput'; + mappings['closeAccessibilityHelp'] = 'monaco.closeAccessibilityHelp'; + mappings['history.showNext'] = 'monaco.history.showNext'; + mappings['history.showPrevious'] = 'monaco.history.showPrevious'; + mappings['closeReferenceSearch'] = 'monaco.closeReferenceSearch'; + mappings['goToNextReference'] = 'monaco.goToNextReference'; + mappings['goToPreviousReference'] = 'monaco.goToPreviousReference'; + + /** + * Navigation + */ + mappings['workbench.action.gotoLine'] = 'monaco.editor.action.gotoLine'; + mappings['workbench.action.gotoSymbol'] = 'monaco.editor.action.quickOutline'; + mappings['workbench.actions.view.problems'] = 'problemsView:toggle'; + + /** + * File Management + */ + mappings['workbench.action.files.saveAs'] = 'file.saveAs'; + + /** + * Display + */ + mappings['workbench.view.explorer'] = 'navigator.reveal'; + mappings['workbench.view.search'] = 'search-in-workspace.toggle'; + mappings['workbench.view.scm'] = 'scmView:toggle'; + mappings['workbench.view.debug'] = 'debug:toggle'; + mappings['workbench.view.extensions'] = 'pluginsView:toggle'; + mappings['workbench.action.output.toggleOutput'] = 'output:toggle'; + mappings['workbench.action.terminal.openNativeConsole'] = 'terminal:new'; + + /** + * Search + */ + mappings['workbench.view.search'] = 'search-in-workspace.open'; + + // Map all the properties from exclusions from their vscode command to their theia command + for (const mappedFrom in transformers) { + if (!transformers.hasOwnProperty(mappedFrom)) { + continue; + } + const mappedTo = transformers[mappedFrom]; + mappings[mappedFrom] = mappedTo[0]; + } + + // tslint:disable-next-line:no-any + export function map(id: string, args: any[] | undefined, toDo: (mappedId: string, mappedArgs: any[] | undefined) => T): T { + if (transformers[id]) { + return toDo(transformers[id][0], transformers[id][1](args)); + } else { + return toDo(id, args); + } + } + + // tslint:disable-next-line:no-any + type ConversionFunction = ((parameter: any) => any) | undefined; + // tslint:disable-next-line:no-any + function createConversionFunction(...conversions: ConversionFunction[]): (args: any[] | undefined) => any[] | undefined { + // tslint:disable-next-line:no-any + return function (args: any[] | undefined): any[] | undefined { + if (!args) { + return args; + } + // tslint:disable-next-line:no-any + return args.map(function (arg: any, index: number): any { + if (index < conversions.length) { + const conversion = conversions[index]; + if (conversion) { + return conversion(arg); + } + } + return arg; + }); + }; + } + + function fromPositionToP(p: theia.Position): P { + return P.create(p.line, p.character); + } + + function fromRangeToR(r: theia.Range): R { + return R.create(fromPositionToP(r.start), fromPositionToP(r.end)); + } + + function fromLocationToL(l: theia.Location): L { + return L.create(l.uri.toString(), fromRangeToR(l.range)); + } + +} + +function toArrayConversion(f: (a: T) => U): (a: T[]) => U[] { + // tslint:disable-next-line:typedef + return function (a: T[]) { + return a.map(f); + }; +} diff --git a/packages/plugin-ext/src/main/browser/keybindings/keybindings-contribution-handler.ts b/packages/plugin-ext/src/main/browser/keybindings/keybindings-contribution-handler.ts index b8d9f707de875..dd86b603b7f1b 100644 --- a/packages/plugin-ext/src/main/browser/keybindings/keybindings-contribution-handler.ts +++ b/packages/plugin-ext/src/main/browser/keybindings/keybindings-contribution-handler.ts @@ -15,7 +15,7 @@ ********************************************************************************/ import { injectable, inject } from 'inversify'; -import { PluginContribution, Keybinding as PluginKeybinding } from '../../../common'; +import { PluginContribution, Keybinding as PluginKeybinding, KnownCommands } from '../../../common'; import { Keybinding, KeybindingRegistry, KeybindingScope } from '@theia/core/lib/browser/keybinding'; import { ILogger } from '@theia/core/lib/common/logger'; import { OS } from '@theia/core/lib/common/os'; @@ -56,7 +56,16 @@ export class KeybindingsContributionPointHandler { if (!keybinding) { return undefined; } - const { command, when } = pluginKeybinding; + let { command, when } = pluginKeybinding; + + /** + * Commands must be converted to their theia counterparts + * otherwise the command registry cannot find a handler + */ + if (KnownCommands.mappings[command]) { + command = KnownCommands.mappings[command]; + } + return { keybinding, command, when }; } diff --git a/packages/plugin-ext/src/plugin/command-registry.ts b/packages/plugin-ext/src/plugin/command-registry.ts index 60b801dbe05f5..ae7284c4b750a 100644 --- a/packages/plugin-ext/src/plugin/command-registry.ts +++ b/packages/plugin-ext/src/plugin/command-registry.ts @@ -23,8 +23,8 @@ import * as model from '../common/plugin-api-rpc-model'; import { CommandRegistryExt, PLUGIN_RPC_CONTEXT as Ext, CommandRegistryMain } from '../common/plugin-api-rpc'; import { RPCProtocol } from '../common/rpc-protocol'; import { Disposable } from './types-impl'; -import { KnownCommands } from './type-converters'; import { DisposableCollection } from '@theia/core'; +import { KnownCommands } from '../common/known-commands'; // tslint:disable-next-line:no-any export type Handler = (...args: any[]) => T | PromiseLike; @@ -102,9 +102,13 @@ export class CommandRegistryImpl implements CommandRegistryExt { executeCommand(id: string, ...args: any[]): PromiseLike { if (this.handlers.has(id)) { return this.executeLocalCommand(id, ...args); - } else { + } else if (KnownCommands.transformers.hasOwnProperty(id)) { + // Using the KnownCommand exclusions, convert the commands manually return KnownCommands.map(id, args, (mappedId: string, mappedArgs: any[] | undefined) => this.proxy.$executeCommand(mappedId, ...mappedArgs)); + } else { + const mappedID = KnownCommands.mappings[id] || id; + return this.proxy.$executeCommand(mappedID, args); } } // tslint:enable:no-any diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index bb0227dc41413..6a240460706aa 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -36,7 +36,7 @@ import URI from 'vscode-uri'; const SIDE_GROUP = -2; const ACTIVE_GROUP = -1; -import { SymbolInformation, Range as R, Position as P, SymbolKind as S, Location as L } from 'vscode-languageserver-types'; +import { SymbolInformation, Range as R, Position as P, SymbolKind as S } from 'vscode-languageserver-types'; import { Item } from './quick-open'; export function toViewColumn(ep?: EditorPosition): theia.ViewColumn | undefined { @@ -506,64 +506,6 @@ export namespace SignatureHelp { } } -export namespace KnownCommands { - // tslint:disable: no-any - const mappings: { [id: string]: [string, (args: any[] | undefined) => any[] | undefined] } = {}; - mappings['editor.action.showReferences'] = ['textEditor.commands.showReferences', createConversionFunction( - (uri: URI) => uri.toString(), - fromPositionToP, - toArrayConversion(fromLocationToL))]; - - export function mapped(id: string): boolean { - return !!mappings[id]; - } - - export function map(id: string, args: any[] | undefined, toDo: (mappedId: string, mappedArgs: any[] | undefined) => T): T { - if (mappings[id]) { - return toDo(mappings[id][0], mappings[id][1](args)); - } else { - return toDo(id, args); - } - } - - type conversionFunction = ((parameter: any) => any) | undefined; - function createConversionFunction(...conversions: conversionFunction[]): (args: any[] | undefined) => any[] | undefined { - return function (args: any[] | undefined): any[] | undefined { - if (!args) { - return args; - } - return args.map(function (arg: any, index: number): any { - if (index < conversions.length) { - const conversion = conversions[index]; - if (conversion) { - return conversion(arg); - } - } - return arg; - }); - }; - } - // tslint:enable: no-any - function fromPositionToP(p: theia.Position): P { - return P.create(p.line, p.character); - } - - function fromRangeToR(r: theia.Range): R { - return R.create(fromPositionToP(r.start), fromPositionToP(r.end)); - } - - function fromLocationToL(l: theia.Location): L { - return L.create(l.uri.toString(), fromRangeToR(l.range)); - } - -} - -function toArrayConversion(f: (a: T) => U): (a: T[]) => U[] { - return function (a: T[]): U[] { - return a.map(f); - }; -} - // tslint:disable-next-line:no-any export function fromWorkspaceEdit(value: theia.WorkspaceEdit, documents?: any): WorkspaceEditDto { const result: WorkspaceEditDto = {