LSP-client-example
43 строки · 1.5 Кб
1/* --------------------------------------------------------------------------------------------
2* Copyright (c) Microsoft Corporation. All rights reserved.
3* Licensed under the MIT License. See License.txt in the project root for license information.
4* ------------------------------------------------------------------------------------------ */
5
6import * as vscode from 'vscode';
7import * as assert from 'assert';
8import { getDocUri, activate } from './helper';
9
10suite('Should do completion', () => {
11const docUri = getDocUri('completion.txt');
12
13test('Completes JS/TS in txt file', async () => {
14await testCompletion(docUri, new vscode.Position(0, 0), {
15items: [
16{ label: 'JavaScript', kind: vscode.CompletionItemKind.Text },
17{ label: 'TypeScript', kind: vscode.CompletionItemKind.Text }
18]
19});
20});
21});
22
23async function testCompletion(
24docUri: vscode.Uri,
25position: vscode.Position,
26expectedCompletionList: vscode.CompletionList
27) {
28await activate(docUri);
29
30// Executing the command `vscode.executeCompletionItemProvider` to simulate triggering completion
31const actualCompletionList = (await vscode.commands.executeCommand(
32'vscode.executeCompletionItemProvider',
33docUri,
34position
35)) as vscode.CompletionList;
36
37assert.ok(actualCompletionList.items.length >= 2);
38expectedCompletionList.items.forEach((expectedItem, i) => {
39const actualItem = actualCompletionList.items[i];
40assert.equal(actualItem.label, expectedItem.label);
41assert.equal(actualItem.kind, expectedItem.kind);
42});
43}
44