mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Diagnostics too
This commit is contained in:
@ -1,15 +1,15 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { testCompletion, getDocUri } from './helper';
|
||||
import * as vscode from 'vscode'
|
||||
import { testCompletion, getDocUri } from './helper'
|
||||
|
||||
describe('Should do completion', () => {
|
||||
const docUri = getDocUri('completion.txt')
|
||||
|
||||
it('Completes JS/TS', async () => {
|
||||
it('Completes JS/TS in txt file', async () => {
|
||||
await testCompletion(docUri, new vscode.Position(0, 0), {
|
||||
items: [
|
||||
{ label: 'JavaScript', kind: vscode.CompletionItemKind.Text },
|
||||
{ label: 'TypeScript', kind: vscode.CompletionItemKind.Text }
|
||||
]
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
20
lsp-sample/client/src/test/diagnostics.test.ts
Normal file
20
lsp-sample/client/src/test/diagnostics.test.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import * as vscode from 'vscode'
|
||||
import { testDiagnostics, getDocUri } from './helper'
|
||||
|
||||
describe('Should get diagnostics', () => {
|
||||
const docUri = getDocUri('diagnostics.txt')
|
||||
|
||||
it('Diagnoses uppercase texts', async () => {
|
||||
await testDiagnostics(docUri, [
|
||||
{ message: 'ANY is all uppercase.', range: toRange(0, 0, 0, 3), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' },
|
||||
{ message: 'ANY is all uppercase.', range: toRange(0, 14, 0, 17), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' },
|
||||
{ message: 'OS is all uppercase.', range: toRange(0, 18, 0, 20), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' }
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
function toRange(sLine: number, sChar: number, eLine: number, eChar: number) {
|
||||
const start = new vscode.Position(sLine, sChar)
|
||||
const end = new vscode.Position(eLine, eChar)
|
||||
return new vscode.Range(start, end)
|
||||
}
|
||||
@ -38,16 +38,31 @@ export async function setTestContent(content: string): Promise<boolean> {
|
||||
export async function testCompletion(docUri: vscode.Uri, position: vscode.Position, expectedCompletionList: vscode.CompletionList) {
|
||||
await activate(docUri)
|
||||
|
||||
const result = (await vscode.commands.executeCommand(
|
||||
const actualCompletionList = (await vscode.commands.executeCommand(
|
||||
'vscode.executeCompletionItemProvider',
|
||||
docUri,
|
||||
position
|
||||
)) as vscode.CompletionList
|
||||
|
||||
assert.equal(result.items.length, expectedCompletionList.items.length);
|
||||
assert.equal(actualCompletionList.items.length, expectedCompletionList.items.length);
|
||||
expectedCompletionList.items.forEach((expectedItem, i) => {
|
||||
const resulItem = result.items[i]
|
||||
assert.equal(resulItem.label, expectedItem.label)
|
||||
assert.equal(resulItem.kind, expectedItem.kind)
|
||||
const actualItem = actualCompletionList.items[i]
|
||||
assert.equal(actualItem.label, expectedItem.label)
|
||||
assert.equal(actualItem.kind, expectedItem.kind)
|
||||
})
|
||||
}
|
||||
|
||||
export async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]) {
|
||||
await activate(docUri)
|
||||
|
||||
const actualDiagnostics = vscode.languages.getDiagnostics(docUri);
|
||||
|
||||
assert.equal(actualDiagnostics.length, expectedDiagnostics.length);
|
||||
|
||||
expectedDiagnostics.forEach((expectedDiagnostic, i) => {
|
||||
const actualDiagnostic = actualDiagnostics[i]
|
||||
assert.equal(actualDiagnostic.message, expectedDiagnostic.message)
|
||||
assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range)
|
||||
assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity)
|
||||
})
|
||||
}
|
||||
1
lsp-sample/client/testFixture/diagnostics.txt
Normal file
1
lsp-sample/client/testFixture/diagnostics.txt
Normal file
@ -0,0 +1 @@
|
||||
ANY browsers, ANY OS.
|
||||
Reference in New Issue
Block a user