本文整理匯總了TypeScript中vscode.languages.getDiagnostics方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript languages.getDiagnostics方法的具體用法?TypeScript languages.getDiagnostics怎麽用?TypeScript languages.getDiagnostics使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vscode.languages
的用法示例。
在下文中一共展示了languages.getDiagnostics方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it("reported no errors when analysis completed", async () => {
await activate();
function warningOrError(d: vs.Diagnostic) {
return d.severity <= vs.DiagnosticSeverity.Warning;
}
const filesWithErrors = vs.languages
.getDiagnostics()
.filter((file) => file[1].find(warningOrError));
if (filesWithErrors.length !== 0) {
assert.equal(
filesWithErrors.length,
0,
`Expected no errors, but got some:\n`
+ filesWithErrors
.slice(0, Math.min(10, filesWithErrors.length))
.map((file) => {
return " "
+ path.basename(fsPath(file[0]))
+ ": "
+ file[1].find(warningOrError)!.message;
})
.join("\n"),
);
}
}).timeout(tenMinutesInMs);
示例2: it
it("returns no errors for a valid file", async () => {
await setTestContent(`
main() {
print("Hello, world!");
}
`);
const errors = vs.languages.getDiagnostics(emptyFile);
assert.equal(0, errors.length);
});
示例3: testDiagnostics
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)
})
}