Skip to content

Commit deb3449

Browse files
committed
Add getSyntacticDiagnostics unit test
1 parent b71e8a2 commit deb3449

2 files changed

Lines changed: 40 additions & 11 deletions

File tree

src/server/client.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,33 +424,39 @@ namespace ts.server {
424424
}
425425

426426
getSyntacticDiagnostics(fileName: string): Diagnostic[] {
427-
const args: protocol.SyntacticDiagnosticsSyncRequestArgs = { file: fileName };
427+
const args: protocol.SyntacticDiagnosticsSyncRequestArgs = { file: fileName, includeLinePosition: true };
428428

429429
const request = this.processRequest<protocol.SyntacticDiagnosticsSyncRequest>(CommandNames.SyntacticDiagnosticsSync, args);
430430
const response = this.processResponse<protocol.SyntacticDiagnosticsSyncResponse>(request);
431431

432-
return (<protocol.Diagnostic[]>response.body).map(entry => this.convertDiagnostic(entry, fileName));
432+
return (<protocol.DiagnosticWithLinePosition[]>response.body).map(entry => this.convertDiagnostic(entry, fileName));
433433
}
434434

435435
getSemanticDiagnostics(fileName: string): Diagnostic[] {
436-
const args: protocol.SemanticDiagnosticsSyncRequestArgs = { file: fileName };
436+
const args: protocol.SemanticDiagnosticsSyncRequestArgs = { file: fileName, includeLinePosition: true };
437437

438438
const request = this.processRequest<protocol.SemanticDiagnosticsSyncRequest>(CommandNames.SemanticDiagnosticsSync, args);
439439
const response = this.processResponse<protocol.SemanticDiagnosticsSyncResponse>(request);
440440

441-
return (<protocol.Diagnostic[]>response.body).map(entry => this.convertDiagnostic(entry, fileName));
441+
return (<protocol.DiagnosticWithLinePosition[]>response.body).map(entry => this.convertDiagnostic(entry, fileName));
442442
}
443443

444-
convertDiagnostic(entry: protocol.Diagnostic, fileName: string): Diagnostic {
445-
const start = this.lineOffsetToPosition(fileName, entry.start);
446-
const end = this.lineOffsetToPosition(fileName, entry.end);
444+
convertDiagnostic(entry: protocol.DiagnosticWithLinePosition, fileName: string): Diagnostic {
445+
let category: DiagnosticCategory;
446+
for (const id in DiagnosticCategory) {
447+
if (typeof id === "string" && entry.category === id.toLowerCase()) {
448+
category = (<any>DiagnosticCategory)[id];
449+
}
450+
}
451+
452+
Debug.assert(category !== undefined, "convertDiagnostic: category should not be undefined");
447453

448454
return {
449455
file: undefined,
450-
start: start,
451-
length: end - start,
452-
messageText: entry.text,
453-
category: undefined,
456+
start: entry.start,
457+
length: entry.length,
458+
messageText: entry.message,
459+
category: category,
454460
code: entry.code
455461
};
456462
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path="../fourslash.ts" />
2+
3+
// @allowJs: true
4+
// @Filename: a.js
5+
//// var ===;
6+
7+
verify.getSyntacticDiagnostics(`[
8+
{
9+
"message": "Variable declaration expected.",
10+
"start": 4,
11+
"length": 3,
12+
"category": "error",
13+
"code": 1134
14+
},
15+
{
16+
"message": "Expression expected.",
17+
"start": 7,
18+
"length": 1,
19+
"category": "error",
20+
"code": 1109
21+
}
22+
]`);
23+
verify.getSemanticDiagnostics(`[]`);

0 commit comments

Comments
 (0)