Skip to content

Commit 46e3d1c

Browse files
committed
Refactoring so that instead of just using from tsc --watch the new api is accessible all the time
1 parent bb91b32 commit 46e3d1c

5 files changed

Lines changed: 795 additions & 737 deletions

File tree

src/compiler/program.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,25 @@ namespace ts {
228228
let output = "";
229229

230230
for (const diagnostic of diagnostics) {
231-
if (diagnostic.file) {
232-
const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
233-
const fileName = diagnostic.file.fileName;
234-
const relativeFileName = convertToRelativePath(fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName));
235-
output += `${relativeFileName}(${line + 1},${character + 1}): `;
236-
}
237-
238-
const category = DiagnosticCategory[diagnostic.category].toLowerCase();
239-
output += `${category} TS${diagnostic.code}: ${flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine())}${host.getNewLine()}`;
231+
output += formatDiagnostic(diagnostic, host);
240232
}
241233
return output;
242234
}
243235

236+
export function formatDiagnostic(diagnostic: Diagnostic, host: FormatDiagnosticsHost): string {
237+
const category = DiagnosticCategory[diagnostic.category].toLowerCase();
238+
const errorMessage = `${category} TS${diagnostic.code}: ${flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine())}${host.getNewLine()}`;
239+
240+
if (diagnostic.file) {
241+
const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
242+
const fileName = diagnostic.file.fileName;
243+
const relativeFileName = convertToRelativePath(fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName));
244+
return `${relativeFileName}(${line + 1},${character + 1}): ` + errorMessage;
245+
}
246+
247+
return errorMessage;
248+
}
249+
244250
const redForegroundEscapeSequence = "\u001b[91m";
245251
const yellowForegroundEscapeSequence = "\u001b[93m";
246252
const blueForegroundEscapeSequence = "\u001b[93m";

0 commit comments

Comments
 (0)