diff --git a/src/vs/editor/common/modes.ts b/src/vs/editor/common/modes.ts index 251e0c47722..0cf6156acf9 100644 --- a/src/vs/editor/common/modes.ts +++ b/src/vs/editor/common/modes.ts @@ -368,6 +368,7 @@ export interface ISuggestion { overwriteBefore?: number; overwriteAfter?: number; extraEdits?: editorCommon.ISingleEditOperation[]; + command?: Command; } /** diff --git a/src/vs/editor/contrib/suggest/browser/suggestController.ts b/src/vs/editor/contrib/suggest/browser/suggestController.ts index f93dadb47e6..64d63147aa9 100644 --- a/src/vs/editor/contrib/suggest/browser/suggestController.ts +++ b/src/vs/editor/contrib/suggest/browser/suggestController.ts @@ -9,6 +9,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; +import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICommonCodeEditor, IEditorContribution, EditorContextKeys, ModeContextKeys } from 'vs/editor/common/editorCommon'; import { editorAction, ServicesAccessor, EditorAction, EditorCommand, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; @@ -33,6 +34,7 @@ export class SuggestController implements IEditorContribution { constructor( private editor: ICodeEditor, + @ICommandService private commandService: ICommandService, @IInstantiationService instantiationService: IInstantiationService ) { this.model = new SuggestModel(this.editor); @@ -62,9 +64,19 @@ export class SuggestController implements IEditorContribution { private onDidSelectItem(item: CompletionItem): void { if (item) { - const {insertText, overwriteBefore, overwriteAfter, extraEdits} = item.suggestion; + const {insertText, overwriteBefore, overwriteAfter, extraEdits, command} = item.suggestion; const columnDelta = this.editor.getPosition().column - this.model.getTriggerPosition().column; + // todo@joh + // * order of stuff command/extraEdit/actual edit + // * failure of command? + // * wait for command to execute? + if (command) { + this.commandService.executeCommand(command.id, ...command.arguments).then(undefined, err => { + console.error(err); + }); + } + if (Array.isArray(extraEdits)) { this.editor.pushUndoStop(); this.editor.executeEdits('suggestController.extraEdits', extraEdits.map(edit => EditOperation.replace(edit.range, edit.text)));