Add getSyntacticDiagnostics unit test

This commit is contained in:
Jason Ramsay 2016-10-18 12:35:50 -07:00
parent 883e19e5b3
commit 58a0e751f0
2 changed files with 55 additions and 2 deletions

View File

@ -397,11 +397,41 @@ namespace ts.server {
}
getSyntacticDiagnostics(fileName: string): Diagnostic[] {
throw new Error("Not Implemented Yet.");
const args: protocol.SyntacticDiagnosticsSyncRequestArgs = { file: fileName, includeLinePosition: true };
const request = this.processRequest<protocol.SyntacticDiagnosticsSyncRequest>(CommandNames.SyntacticDiagnosticsSync, args);
const response = this.processResponse<protocol.SyntacticDiagnosticsSyncResponse>(request);
return (<protocol.DiagnosticWithLinePosition[]>response.body).map(entry => this.convertDiagnostic(entry, fileName));
}
getSemanticDiagnostics(fileName: string): Diagnostic[] {
throw new Error("Not Implemented Yet.");
const args: protocol.SemanticDiagnosticsSyncRequestArgs = { file: fileName, includeLinePosition: true };
const request = this.processRequest<protocol.SemanticDiagnosticsSyncRequest>(CommandNames.SemanticDiagnosticsSync, args);
const response = this.processResponse<protocol.SemanticDiagnosticsSyncResponse>(request);
return (<protocol.DiagnosticWithLinePosition[]>response.body).map(entry => this.convertDiagnostic(entry, fileName));
}
convertDiagnostic(entry: protocol.DiagnosticWithLinePosition, fileName: string): Diagnostic {
let category: DiagnosticCategory;
for (const id in DiagnosticCategory) {
if (typeof id === "string" && entry.category === id.toLowerCase()) {
category = (<any>DiagnosticCategory)[id];
}
}
Debug.assert(category !== undefined, "convertDiagnostic: category should not be undefined");
return {
file: undefined,
start: entry.start,
length: entry.length,
messageText: entry.message,
category: category,
code: entry.code
};
}
getCompilerOptionsDiagnostics(): Diagnostic[] {

View File

@ -0,0 +1,23 @@
/// <reference path="../fourslash.ts" />
// @allowJs: true
// @Filename: a.js
//// var ===;
verify.getSyntacticDiagnostics(`[
{
"message": "Variable declaration expected.",
"start": 4,
"length": 3,
"category": "error",
"code": 1134
},
{
"message": "Expression expected.",
"start": 7,
"length": 1,
"category": "error",
"code": 1109
}
]`);
verify.getSemanticDiagnostics(`[]`);