diff --git a/extensions/vscode-api-tests/src/editor.test.ts b/extensions/vscode-api-tests/src/editor.test.ts index 1eafbc23530607d0eb48328406f3199973c03d77..54806f0b92acd1bfbeb19e0df721d3a244f99db0 100644 --- a/extensions/vscode-api-tests/src/editor.test.ts +++ b/extensions/vscode-api-tests/src/editor.test.ts @@ -41,8 +41,9 @@ suite('editor tests', () => { .appendText(' snippet'); return withRandomFileEditor('', (editor, doc) => { - return editor.edit(snippetString).then(inserted => { - assert.ok(inserted); + editor.edit(snippetString); + + return editor.edit(() => {}).then(() => { assert.equal(doc.getText(), 'This is a placeholder snippet'); assert.ok(doc.isDirty); }); @@ -59,8 +60,9 @@ suite('editor tests', () => { new Position(0, 12) ); - return editor.edit(snippetString).then(inserted => { - assert.ok(inserted); + editor.edit(snippetString); + + return editor.edit(() => {}).then(() => { assert.equal(doc.getText(), 'This has been replaced'); assert.ok(doc.isDirty); }); diff --git a/src/vs/editor/contrib/snippet/common/snippetController.ts b/src/vs/editor/contrib/snippet/common/snippetController.ts index 2251065a43d88afdbcd3802a7c348a8051fc1458..2e05552bbd450b5e46831ae60520fb7a4bff672d 100644 --- a/src/vs/editor/contrib/snippet/common/snippetController.ts +++ b/src/vs/editor/contrib/snippet/common/snippetController.ts @@ -467,10 +467,6 @@ export class SnippetController { return SnippetController.ID; } - public get inSnippetMode() { - return this._inSnippetMode.get(); - } - public insertSnippet(template: string, overwriteBefore: number, overwriteAfter: number): void { const snippet = CodeSnippet.fromTextmate(template, this._variableResolver); this.run(snippet, overwriteBefore, overwriteAfter); diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index ebaf887395c2c291cdf02118a806841d77041cf2..71d937c190723b08b9130510698b562323a98dac 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -939,11 +939,10 @@ declare module 'vscode' { /** * Enters snippet mode in the editor with the specified snippet. * - * @param snippet The snippet to insert + * @param snippet The snippet to insert in this edit. * @param options The undo/redo behaviour around this edit. By default, undo stops will be created before and after this edit. - * @return A promise that resolves with a value indicating if the editor entered snippet mode. */ - edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable; + edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): void; /** * Adds a set of decorations to the text editor. If a set of decorations already exists with diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 9eb68707f5f0211c031f10fcdf76988780445eac..b6fcae69618985258a06d0ed2c0ee3ed3efd9212 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -112,11 +112,11 @@ declare module 'vscode' { /** * Enters snippet mode in the editor with the specified snippet. * - * @param snippet The snippet to insert + * @param snippet The snippet to insert in this edit. * @param options The undo/redo behaviour around this edit. By default, undo stops will be created before and after this edit. - * @return A promise that resolves with a value indicating if the editor entered snippet mode. */ - edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable; + edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): void; + } export interface SCMResourceThemableDecorations { diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 72e0002891fb8f96783310158db60bf39c73a001..c3b4b79e787afe84787cd515b5867c6e6c2134b6 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -137,7 +137,7 @@ export abstract class MainThreadEditorsShape { $tryRevealRange(id: string, range: editorCommon.IRange, revealType: TextEditorRevealType): TPromise { throw ni(); } $trySetSelections(id: string, selections: editorCommon.ISelection[]): TPromise { throw ni(); } $tryApplyEdits(id: string, modelVersionId: number, edits: editorCommon.ISingleEditOperation[], opts: IApplyEditsOptions): TPromise { throw ni(); } - $tryInsertSnippet(id: string, template: string, opts: IInsertSnippetOptions): TPromise { throw ni(); } + $tryInsertSnippet(id: string, template: string, opts: IInsertSnippetOptions): TPromise { throw ni(); } } export abstract class MainThreadTreeExplorersShape { diff --git a/src/vs/workbench/api/node/extHostEditors.ts b/src/vs/workbench/api/node/extHostEditors.ts index 3a65e8da293cd516a9252f1e72428e7579d5d969..d81a46e5e75528f997d1a480e849f7fdabfc5be5 100644 --- a/src/vs/workbench/api/node/extHostEditors.ts +++ b/src/vs/workbench/api/node/extHostEditors.ts @@ -596,11 +596,11 @@ class ExtHostTextEditor implements vscode.TextEditor { // ---- editing edit(callback: (edit: TextEditorEdit) => void, options: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable; - edit(snippet: SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable; + edit(snippet: SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; }): void; - edit(callbackOrSnippet: ((edit: TextEditorEdit) => void) | SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable { + edit(callbackOrSnippet: ((edit: TextEditorEdit) => void) | SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable | void { if (SnippetString.isSnippetString(callbackOrSnippet)) { - return this._proxy.$tryInsertSnippet(this._id, callbackOrSnippet.value, options); + this._proxy.$tryInsertSnippet(this._id, callbackOrSnippet.value, options); } else { let edit = new TextEditorEdit(this._documentData.document, options); callbackOrSnippet(edit); diff --git a/src/vs/workbench/api/node/mainThreadEditors.ts b/src/vs/workbench/api/node/mainThreadEditors.ts index 13b1016a707ff26bbbd16ba221032515c774b587..3b5f54e6b6666340366699e86f1e41567dca9e2e 100644 --- a/src/vs/workbench/api/node/mainThreadEditors.ts +++ b/src/vs/workbench/api/node/mainThreadEditors.ts @@ -293,11 +293,12 @@ export class MainThreadEditors extends MainThreadEditorsShape { return TPromise.as(this._textEditorsMap[id].applyEdits(modelVersionId, edits, opts)); } - $tryInsertSnippet(id: string, template: string, opts: IInsertSnippetOptions): TPromise { + $tryInsertSnippet(id: string, template: string, opts: IInsertSnippetOptions): TPromise { if (!this._textEditorsMap[id]) { return TPromise.wrapError('TextEditor disposed'); } - return TPromise.as(this._textEditorsMap[id].insertSnippet(template, opts)); + this._textEditorsMap[id].insertSnippet(template, opts); + return TPromise.as(null); } $registerTextEditorDecorationType(key: string, options: IDecorationRenderOptions): void { diff --git a/src/vs/workbench/api/node/mainThreadEditorsTracker.ts b/src/vs/workbench/api/node/mainThreadEditorsTracker.ts index a9e8c13538fbcc4b0a445b2b9c6949941ede032f..389f6a9076ad934cb43a0b6d00bbe22bf3f703c0 100644 --- a/src/vs/workbench/api/node/mainThreadEditorsTracker.ts +++ b/src/vs/workbench/api/node/mainThreadEditorsTracker.ts @@ -394,9 +394,6 @@ export class MainThreadTextEditor { insertSnippet(template: string, opts: IInsertSnippetOptions) { const snippetController = SnippetController.get(this._codeEditor); - if (snippetController.inSnippetMode) { - return false; - } this._codeEditor.focus(); @@ -409,8 +406,6 @@ export class MainThreadTextEditor { if (opts.undoStopAfter) { this._codeEditor.pushUndoStop(); } - - return true; } }