Skip to content

Commit 68c485d

Browse files
authored
Merge pull request microsoft#11686 from Microsoft/AddIsSemanticToGetDiagnosticsWorker
TSServer: Add isSemantic check to getDiagnosticsWorker
2 parents 9cedb6a + deb3449 commit 68c485d

3 files changed

Lines changed: 44 additions & 15 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
}

src/server/session.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ namespace ts.server {
389389
});
390390
}
391391

392-
private getDiagnosticsWorker(args: protocol.FileRequestArgs, selector: (project: Project, file: string) => Diagnostic[], includeLinePosition: boolean) {
392+
private getDiagnosticsWorker(args: protocol.FileRequestArgs, isSemantic: boolean, selector: (project: Project, file: string) => Diagnostic[], includeLinePosition: boolean) {
393393
const { project, file } = this.getFileAndProject(args);
394-
if (shouldSkipSematicCheck(project)) {
394+
if (isSemantic && shouldSkipSematicCheck(project)) {
395395
return [];
396396
}
397397
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
@@ -492,11 +492,11 @@ namespace ts.server {
492492
}
493493

494494
private getSyntacticDiagnosticsSync(args: protocol.SyntacticDiagnosticsSyncRequestArgs): protocol.Diagnostic[] | protocol.DiagnosticWithLinePosition[] {
495-
return this.getDiagnosticsWorker(args, (project, file) => project.getLanguageService().getSyntacticDiagnostics(file), args.includeLinePosition);
495+
return this.getDiagnosticsWorker(args, /*isSemantic*/ false, (project, file) => project.getLanguageService().getSyntacticDiagnostics(file), args.includeLinePosition);
496496
}
497497

498498
private getSemanticDiagnosticsSync(args: protocol.SemanticDiagnosticsSyncRequestArgs): protocol.Diagnostic[] | protocol.DiagnosticWithLinePosition[] {
499-
return this.getDiagnosticsWorker(args, (project, file) => project.getLanguageService().getSemanticDiagnostics(file), args.includeLinePosition);
499+
return this.getDiagnosticsWorker(args, /*isSemantic*/ true, (project, file) => project.getLanguageService().getSemanticDiagnostics(file), args.includeLinePosition);
500500
}
501501

502502
private getDocumentHighlights(args: protocol.DocumentHighlightsRequestArgs, simplifiedResult: boolean): protocol.DocumentHighlightsItem[] | DocumentHighlights[] {
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)