mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
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:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user