-
Notifications
You must be signed in to change notification settings - Fork 71
/
print-diagnostics.ts
46 lines (42 loc) · 1.16 KB
/
print-diagnostics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { red, white, yellow } from "colors/safe";
import { tsModule } from "./tsproxy";
import { IContext } from "./context";
import { IDiagnostics } from "./tscache";
export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty: boolean): void
{
diagnostics.forEach((diagnostic) =>
{
let print;
let color;
let category;
switch (diagnostic.category)
{
case tsModule.DiagnosticCategory.Message:
print = context.info;
color = white;
category = "";
break;
case tsModule.DiagnosticCategory.Error:
print = context.error;
color = red;
category = "error";
break;
case tsModule.DiagnosticCategory.Warning:
default:
print = context.warn;
color = yellow;
category = "warning";
break;
}
const type = diagnostic.type + " ";
if (pretty)
print.call(context, `${diagnostic.formatted}`);
else
{
if (diagnostic.fileLine !== undefined)
print.call(context, `${diagnostic.fileLine}: ${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`);
else
print.call(context, `${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`);
}
});
}