LSP-client-example
41 строка · 1.8 Кб
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 get diagnostics', () => {11const docUri = getDocUri('diagnostics.txt');12
13test('Diagnoses uppercase texts', async () => {14await testDiagnostics(docUri, [15{ message: 'ANY is all uppercase.', range: toRange(0, 0, 0, 3), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' },16{ message: 'ANY is all uppercase.', range: toRange(0, 14, 0, 17), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' },17{ message: 'OS is all uppercase.', range: toRange(0, 18, 0, 20), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' }18]);19});20});21
22function toRange(sLine: number, sChar: number, eLine: number, eChar: number) {23const start = new vscode.Position(sLine, sChar);24const end = new vscode.Position(eLine, eChar);25return new vscode.Range(start, end);26}
27
28async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]) {29await activate(docUri);30
31const actualDiagnostics = vscode.languages.getDiagnostics(docUri);32
33assert.equal(actualDiagnostics.length, expectedDiagnostics.length);34
35expectedDiagnostics.forEach((expectedDiagnostic, i) => {36const actualDiagnostic = actualDiagnostics[i];37assert.equal(actualDiagnostic.message, expectedDiagnostic.message);38assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range);39assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity);40});41}