mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
add skeleton for ISuggestion#command, #6874
This commit is contained in:
parent
1ee0c147db
commit
90d6808677
|
@ -368,6 +368,7 @@ export interface ISuggestion {
|
||||||
overwriteBefore?: number;
|
overwriteBefore?: number;
|
||||||
overwriteAfter?: number;
|
overwriteAfter?: number;
|
||||||
extraEdits?: editorCommon.ISingleEditOperation[];
|
extraEdits?: editorCommon.ISingleEditOperation[];
|
||||||
|
command?: Command;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
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 { ICommonCodeEditor, IEditorContribution, EditorContextKeys, ModeContextKeys } from 'vs/editor/common/editorCommon';
|
||||||
import { editorAction, ServicesAccessor, EditorAction, EditorCommand, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
|
import { editorAction, ServicesAccessor, EditorAction, EditorCommand, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
|
||||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||||
|
@ -33,6 +34,7 @@ export class SuggestController implements IEditorContribution {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private editor: ICodeEditor,
|
private editor: ICodeEditor,
|
||||||
|
@ICommandService private commandService: ICommandService,
|
||||||
@IInstantiationService instantiationService: IInstantiationService
|
@IInstantiationService instantiationService: IInstantiationService
|
||||||
) {
|
) {
|
||||||
this.model = new SuggestModel(this.editor);
|
this.model = new SuggestModel(this.editor);
|
||||||
|
@ -62,9 +64,19 @@ export class SuggestController implements IEditorContribution {
|
||||||
|
|
||||||
private onDidSelectItem(item: CompletionItem): void {
|
private onDidSelectItem(item: CompletionItem): void {
|
||||||
if (item) {
|
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;
|
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)) {
|
if (Array.isArray(extraEdits)) {
|
||||||
this.editor.pushUndoStop();
|
this.editor.pushUndoStop();
|
||||||
this.editor.executeEdits('suggestController.extraEdits', extraEdits.map(edit => EditOperation.replace(edit.range, edit.text)));
|
this.editor.executeEdits('suggestController.extraEdits', extraEdits.map(edit => EditOperation.replace(edit.range, edit.text)));
|
||||||
|
|
Loading…
Reference in a new issue