TS: Print TypeScript semantic errors in log

This commit is contained in:
Asger Feldthaus
2020-01-17 10:51:39 +00:00
parent dde0f868b3
commit 71b540755d

View File

@@ -262,6 +262,23 @@ function handleOpenProjectCommand(command: OpenProjectCommand) {
let program = project.program;
let typeChecker = program.getTypeChecker();
let diagnostics = program.getSemanticDiagnostics()
.filter(d => d.category === ts.DiagnosticCategory.Error);
console.warn('TypeScript: reported ' + diagnostics.length + ' semantic errors.');
for (let diagnostic of diagnostics) {
let text = diagnostic.messageText;
if (typeof text !== 'string') {
text = text.messageText;
}
let locationStr = '';
let { file } = diagnostic;
if (file != null) {
let { line, character } = file.getLineAndCharacterOfPosition(diagnostic.start);
locationStr = `${file.fileName}:${line}:${character}`;
}
console.warn(`TypeScript: ${locationStr} ${text}`);
}
// Associate external module names with the corresponding file symbols.
// We need these mappings to identify which module a given external type comes from.
// The TypeScript API lets us resolve a module name to a source file, but there is no