本文整理汇总了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)
})
}