MCPcopy Create free account
hub / github.com/Snapchat/Valdi / transformDiagnostic

Method transformDiagnostic

compiler/companion/src/Workspace.ts:285–323  ·  view source on GitHub ↗
(project: Project, original: ts.DiagnosticWithLocation | ts.Diagnostic)

Source from the content-addressed store, hash-verified

283 async emitFile(fileName: string): Promise<EmitResult> {
284 return this.doEmitFile(fileName, undefined, undefined);
285 }
286
287 transformDiagnostic(project: Project, original: ts.DiagnosticWithLocation | ts.Diagnostic): Diagnostic {
288 const text = project.formatDiagnostic(original);
289
290 let category: string;
291 switch (original.category) {
292 case ts.DiagnosticCategory.Warning:
293 category = 'warning';
294 break;
295 case ts.DiagnosticCategory.Error:
296 category = 'error';
297 break;
298 case ts.DiagnosticCategory.Suggestion:
299 category = 'suggestion';
300 break;
301 case ts.DiagnosticCategory.Message:
302 category = 'message';
303 break;
304 }
305
306 let file = original.file ?? (original.source && project.getOpenedSourceFile(original.source));
307
308 let start: Location;
309 let end: Location;
310 if (file && original.start) {
311 start = this.getLocationOfPositionInFile(file, original.start);
312 end = this.getLocationOfPositionInFile(file, original.start + (original.length ?? 0));
313 } else {
314 start = { line: 0, offset: 0 };
315 end = { line: 0, offset: 0 };
316 }
317
318 const transformed = {
319 start,
320 end,
321 text,
322 category,
323 };
324 return transformed;
325 }
326

Callers 1

doGetDiagnosticsMethod · 0.95

Calls 3

formatDiagnosticMethod · 0.80
getOpenedSourceFileMethod · 0.80

Tested by

no test coverage detected