TextEditor.insertSnippet extension API.

More robust type validation on ext side of insertSnippet.
Position/range check for snippet insertion was inverted.
Adding insertSnippet to vscode.d.ts. (Should it be in vscode.proposed.d.ts?)
Adding extension API tests for insertSnippet.
This commit is contained in:
Joel Day
2016-12-20 14:33:37 -08:00
parent 75840d1f74
commit 40522e28f8
4 changed files with 55 additions and 6 deletions

View File

@@ -6,7 +6,7 @@
'use strict';
import * as assert from 'assert';
import { workspace, window, Position, Range, commands, TextEditor, TextDocument, TextEditorCursorStyle, TextEditorLineNumbersStyle } from 'vscode';
import { workspace, window, Position, Range, commands, TextEditor, TextDocument, TextEditorCursorStyle, TextEditorLineNumbersStyle, SnippetString } from 'vscode';
import { createRandomFile, deleteFile, cleanUp } from './utils';
suite('editor tests', () => {
@@ -33,6 +33,35 @@ suite('editor tests', () => {
});
}
test('insert snippet', () => {
const snippetString = new SnippetString()
.appendText('This is a ')
.appendTabstop()
.appendPlaceholder('placeholder')
.appendText(' snippet');
return withRandomFileEditor('', (editor, doc) => {
return editor.insertSnippet(snippetString.value, new Position(0, 0)).then(inserted => {
assert.ok(inserted);
assert.equal(doc.getText(), 'This is a placeholder snippet');
assert.ok(doc.isDirty);
});
});
});
test('insert snippet with replacement', () => {
const snippetString = new SnippetString()
.appendText('has been');
return withRandomFileEditor('This will be replaced', (editor, doc) => {
return editor.insertSnippet(snippetString.value, new Range(0, 5, 0, 12)).then(inserted => {
assert.ok(inserted);
assert.equal(doc.getText(), 'This has been replaced');
assert.ok(doc.isDirty);
});
});
});
test('make edit', () => {
return withRandomFileEditor('', (editor, doc) => {
return editor.edit((builder) => {