提交 c21734fd 编写于 作者: J Joel Day

Snippet insertion extension API changes

- Basing snippet insertion failure on a new `_codeEditor` null-check.
- Now returns `Thenable<boolean>`.
- Removed vscode.proposed.d.ts copy of the `TextEditor` change.
- Removing empty options interface.
上级 95fc0327
......@@ -68,6 +68,7 @@
"name": "VS Code API Tests",
"runtimeExecutable": "${execPath}",
"args": [
"${workspaceRoot}",
"${workspaceRoot}/extensions/vscode-api-tests/testWorkspace",
"--extensionDevelopmentPath=${workspaceRoot}/extensions/vscode-api-tests",
"--extensionTestsPath=${workspaceRoot}/extensions/vscode-api-tests/out"
......
......@@ -41,9 +41,8 @@ suite('editor tests', () => {
.appendText(' snippet');
return withRandomFileEditor('', (editor, doc) => {
editor.edit(snippetString);
return editor.edit(() => {}).then(() => {
return editor.edit(snippetString).then(inserted => {
assert.ok(inserted);
assert.equal(doc.getText(), 'This is a placeholder snippet');
assert.ok(doc.isDirty);
});
......@@ -60,9 +59,8 @@ suite('editor tests', () => {
new Position(0, 12)
);
editor.edit(snippetString);
return editor.edit(() => {}).then(() => {
return editor.edit(snippetString).then(inserted => {
assert.ok(inserted);
assert.equal(doc.getText(), 'This has been replaced');
assert.ok(doc.isDirty);
});
......
......@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/// <reference path='../../../../src/vs/vscode.proposed.d.ts'/>
/// <reference path='../../../../src/typings/mocha.d.ts'/>
/// <reference path='../../../../extensions/declares.d.ts'/>
/// <reference path='../../../../extensions/node.d.ts'/>
......
......@@ -941,8 +941,9 @@ declare module 'vscode' {
*
* @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 snippet could be inserted.
*/
edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): void;
edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>;
/**
* Adds a set of decorations to the text editor. If a set of decorations already exists with
......
......@@ -108,17 +108,6 @@ declare module 'vscode' {
getClickCommand?(node: T): string;
}
export interface TextEditor {
/**
* Enters snippet mode in the editor with the specified snippet.
*
* @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.
*/
edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): void;
}
export interface SCMResourceThemableDecorations {
readonly iconPath?: string | Uri;
}
......
......@@ -34,7 +34,7 @@ import { IWorkspaceConfigurationValues } from 'vs/workbench/services/configurati
import { IPickOpenEntry, IPickOptions } from 'vs/platform/quickOpen/common/quickOpen';
import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
import { IWorkspaceSymbol } from 'vs/workbench/parts/search/common/search';
import { IApplyEditsOptions, IInsertSnippetOptions, TextEditorRevealType, ITextEditorConfigurationUpdate, IResolvedTextEditorConfiguration, ISelectionChangeEvent } from './mainThreadEditorsTracker';
import { IApplyEditsOptions, IUndoStopOptions, TextEditorRevealType, ITextEditorConfigurationUpdate, IResolvedTextEditorConfiguration, ISelectionChangeEvent } from './mainThreadEditorsTracker';
import { InternalTreeExplorerNodeContent } from 'vs/workbench/parts/explorers/common/treeExplorerViewModel';
......@@ -137,7 +137,7 @@ export abstract class MainThreadEditorsShape {
$tryRevealRange(id: string, range: editorCommon.IRange, revealType: TextEditorRevealType): TPromise<any> { throw ni(); }
$trySetSelections(id: string, selections: editorCommon.ISelection[]): TPromise<any> { throw ni(); }
$tryApplyEdits(id: string, modelVersionId: number, edits: editorCommon.ISingleEditOperation[], opts: IApplyEditsOptions): TPromise<boolean> { throw ni(); }
$tryInsertSnippet(id: string, template: string, opts: IInsertSnippetOptions): TPromise<any> { throw ni(); }
$tryInsertSnippet(id: string, template: string, opts: IUndoStopOptions): TPromise<any> { throw ni(); }
}
export abstract class MainThreadTreeExplorersShape {
......
......@@ -596,11 +596,11 @@ class ExtHostTextEditor implements vscode.TextEditor {
// ---- editing
edit(callback: (edit: TextEditorEdit) => void, options: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>;
edit(snippet: SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; }): void;
edit(snippet: SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>;
edit(callbackOrSnippet: ((edit: TextEditorEdit) => void) | SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable<boolean> | void {
edit(callbackOrSnippet: ((edit: TextEditorEdit) => void) | SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable<boolean> {
if (SnippetString.isSnippetString(callbackOrSnippet)) {
this._proxy.$tryInsertSnippet(this._id, callbackOrSnippet.value, options);
return this._proxy.$tryInsertSnippet(this._id, callbackOrSnippet.value, options);
} else {
let edit = new TextEditorEdit(this._documentData.document, options);
callbackOrSnippet(edit);
......
......@@ -14,7 +14,7 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { Position as EditorPosition } from 'vs/platform/editor/common/editor';
import { IModelService } from 'vs/editor/common/services/modelService';
import { MainThreadEditorsTracker, TextEditorRevealType, MainThreadTextEditor, IApplyEditsOptions, IInsertSnippetOptions, ITextEditorConfigurationUpdate } from 'vs/workbench/api/node/mainThreadEditorsTracker';
import { MainThreadEditorsTracker, TextEditorRevealType, MainThreadTextEditor, IApplyEditsOptions, IUndoStopOptions, ITextEditorConfigurationUpdate } from 'vs/workbench/api/node/mainThreadEditorsTracker';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { equals as arrayEquals } from 'vs/base/common/arrays';
import { equals as objectEquals } from 'vs/base/common/objects';
......@@ -293,12 +293,11 @@ export class MainThreadEditors extends MainThreadEditorsShape {
return TPromise.as(this._textEditorsMap[id].applyEdits(modelVersionId, edits, opts));
}
$tryInsertSnippet(id: string, template: string, opts: IInsertSnippetOptions): TPromise<any> {
$tryInsertSnippet(id: string, template: string, opts: IUndoStopOptions): TPromise<boolean> {
if (!this._textEditorsMap[id]) {
return TPromise.wrapError('TextEditor disposed');
}
this._textEditorsMap[id].insertSnippet(template, opts);
return TPromise.as(null);
return TPromise.as(this._textEditorsMap[id].insertSnippet(template, opts));
}
$registerTextEditorDecorationType(key: string, options: IDecorationRenderOptions): void {
......
......@@ -68,10 +68,6 @@ export interface IApplyEditsOptions extends IUndoStopOptions {
setEndOfLine: EndOfLine;
}
export interface IInsertSnippetOptions extends IUndoStopOptions {
}
/**
* Text Editor that is permanently bound to the same model.
* It can be bound or not to a CodeEditor.
......@@ -392,9 +388,13 @@ export class MainThreadTextEditor {
return false;
}
insertSnippet(template: string, opts: IInsertSnippetOptions) {
insertSnippet(template: string, opts: IUndoStopOptions) {
const snippetController = SnippetController.get(this._codeEditor);
if (!this._codeEditor) {
return false;
}
this._codeEditor.focus();
if (opts.undoStopBefore) {
......@@ -406,6 +406,8 @@ export class MainThreadTextEditor {
if (opts.undoStopAfter) {
this._codeEditor.pushUndoStop();
}
return true;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册