Skip to content

Commit 3d5177d

Browse files
committed
Update tsserver-plugin and cli for new rewriteDiagnostic signature
1 parent 8ca175b commit 3d5177d

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

packages/cli/src/transform-manager.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ export default class TransformManager {
1919
}
2020

2121
public formatDiagnostic(diagnostic: ts.Diagnostic): string {
22-
let file = diagnostic.file;
23-
let transformedModule = file && this.transformedModules.get(file.fileName);
24-
if (diagnostic.code && file && transformedModule) {
25-
diagnostic = rewriteDiagnostic(this.ts, diagnostic, transformedModule);
26-
}
22+
let transformedDiagnostic = rewriteDiagnostic(this.ts, diagnostic, (fileName) =>
23+
this.transformedModules.get(fileName)
24+
);
2725

28-
return this.ts.formatDiagnosticsWithColorAndContext([diagnostic], this.formatDiagnosticHost);
26+
return this.ts.formatDiagnosticsWithColorAndContext(
27+
[transformedDiagnostic],
28+
this.formatDiagnosticHost
29+
);
2930
}
3031

3132
public readFile(filename: string, encoding?: string): string | undefined {

packages/tsserver-plugin/src/language-service.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ export default class GlintLanguageService implements Partial<ts.LanguageService>
4545
}
4646
}
4747

48+
private getTransformInfoForPath(path: string): TransformInfo | undefined {
49+
let originalPath = isTransformablePath(path) ? path : getOriginalPath(path as TransformedPath);
50+
let transformedPath = isTransformedPath(path)
51+
? path
52+
: getTransformedPath(path as TransformablePath);
53+
54+
return this.getTransformInfo(originalPath, transformedPath);
55+
}
56+
4857
private getTransformInfo(
4958
originalPath: TransformablePath,
5059
transformedPath: TransformedPath
@@ -80,7 +89,7 @@ export default class GlintLanguageService implements Partial<ts.LanguageService>
8089
if (info) {
8190
return this.ls
8291
.getSemanticDiagnostics(info.transformedPath)
83-
.map((diagnostic) => rewriteDiagnostic(this.ts, diagnostic, info.transformedModule));
92+
.map((diagnostic) => this.rewriteDiagnostic(diagnostic));
8493
}
8594

8695
return this.ls.getSemanticDiagnostics(fileName);
@@ -91,12 +100,20 @@ export default class GlintLanguageService implements Partial<ts.LanguageService>
91100
if (info) {
92101
return this.ls
93102
.getSuggestionDiagnostics(info.transformedPath)
94-
.map((diagnostic) => rewriteDiagnostic(this.ts, diagnostic, info.transformedModule));
103+
.map((diagnostic) => this.rewriteDiagnostic(diagnostic));
95104
}
96105

97106
return this.ls.getSuggestionDiagnostics(fileName);
98107
}
99108

109+
private rewriteDiagnostic<T extends ts.Diagnostic>(diagnostic: T): T {
110+
return rewriteDiagnostic(
111+
this.ts,
112+
diagnostic,
113+
(fileName) => this.getTransformInfoForPath(fileName)?.transformedModule
114+
);
115+
}
116+
100117
public getEncodedSyntacticClassifications(
101118
fileName: string,
102119
span: ts.TextSpan

0 commit comments

Comments
 (0)