mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 01:58:53 +01:00
completion and language selector test
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import {languages, workspace, commands, Uri, Diagnostic, Range, Command, Disposable} from 'vscode';
|
||||
import {join} from 'path';
|
||||
import {languages, workspace, commands, Uri, Diagnostic, Range, Command, Disposable, CancellationToken,
|
||||
CompletionList, CompletionItem, CompletionItemKind, TextDocument, Position} from 'vscode';
|
||||
|
||||
suite('languages namespace tests', () => {
|
||||
|
||||
@@ -77,7 +79,7 @@ suite('languages namespace tests', () => {
|
||||
collection.dispose();
|
||||
});
|
||||
|
||||
test('diagnostics & CodeActionProvider', function () {
|
||||
test('diagnostics & CodeActionProvider', function (done) {
|
||||
|
||||
class D2 extends Diagnostic {
|
||||
customProp = { complex() { } };
|
||||
@@ -120,8 +122,42 @@ suite('languages namespace tests', () => {
|
||||
workspace.openTextDocument(uri).then(doc => {
|
||||
return commands.executeCommand('vscode.executeCodeActionProvider', uri, new Range(0, 0, 0, 10));
|
||||
}).then(commands => {
|
||||
assert.ok(ran);
|
||||
Disposable.from(r1, r2, r3, r4).dispose();
|
||||
try {
|
||||
assert.ok(ran);
|
||||
Disposable.from(r1, r2, r3, r4).dispose();
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
}, done);
|
||||
});
|
||||
|
||||
test('completions with document filters', function (done) {
|
||||
let ran = false;
|
||||
let uri = Uri.file(join(workspace.rootPath, './bower.json'));
|
||||
|
||||
let jsonDocumentFilter = [{ language: 'json', pattern: '**/package.json' }, { language: 'json', pattern: '**/bower.json' }, { language: 'json', pattern: '**/.bower.json' }];
|
||||
|
||||
let r1 = languages.registerCompletionItemProvider(jsonDocumentFilter, {
|
||||
provideCompletionItems: (document: TextDocument, position: Position, token: CancellationToken): CompletionItem[] => {
|
||||
let proposal = new CompletionItem('foo');
|
||||
proposal.kind = CompletionItemKind.Property;
|
||||
ran = true;
|
||||
return [ proposal ];
|
||||
}
|
||||
});
|
||||
|
||||
workspace.openTextDocument(uri).then(doc => {
|
||||
return commands.executeCommand('vscode.executeCompletionItemProvider', uri, new Position(1, 0));
|
||||
}).then((result: CompletionList) => {
|
||||
try {
|
||||
assert.equal(result.items[0].label, 'foo');
|
||||
assert.ok(ran);
|
||||
Disposable.from(r1).dispose();
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user