Skip to content

Commit 48002d4

Browse files
author
Yui T
committed
Fix language service; doesn't capture declaration emit errors
1 parent b1f243d commit 48002d4

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/services/services.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,9 +1599,9 @@ module ts {
15991599
}
16001600

16011601
// Only perform incremental parsing on open files that are being edited. If a file was
1602-
// open, but is now closed, we want to reparse entirely so we don't have any tokens that
1602+
// open, but is now closed, we want to re-parse entirely so we don't have any tokens that
16031603
// are holding onto expensive script snapshot instances on the host. Similarly, if a
1604-
// file was closed, then we always want to reparse. This is so our tree doesn't keep
1604+
// file was closed, then we always want to re-parse. This is so our tree doesn't keep
16051605
// the old buffer alive that represented the file on disk (as the host has moved to a
16061606
// new text buffer).
16071607
var textChangeRange: TypeScript.TextChangeRange = null;
@@ -1651,12 +1651,28 @@ module ts {
16511651
return program.getDiagnostics(getSourceFile(filename).getSourceFile());
16521652
}
16531653

1654+
// In a case when '-d' is not enabled, only report semantic errors
1655+
// If '-d' enabled, report both semantic and emitter errors
16541656
function getSemanticDiagnostics(filename: string) {
16551657
synchronizeHostData();
16561658

16571659
filename = TypeScript.switchToForwardSlashes(filename)
1658-
1659-
return getFullTypeCheckChecker().getDiagnostics(getSourceFile(filename));
1660+
var compilerOptions = program.getCompilerOptions();
1661+
var checker = getFullTypeCheckChecker();
1662+
var targetSourceFile = getSourceFile(filename);
1663+
1664+
// Only perform the action per file regardless off '-out' flag
1665+
// As an errors message in Visual Studio will maintain an error message life-time per file
1666+
1667+
var allDiagnostics = checker.getDiagnostics(targetSourceFile);
1668+
if (compilerOptions.declaration) {
1669+
// If '-d' is enabled, check for emitter error which requires calling to TypeChecker.emitFiles
1670+
// Define CompilerHost.writer which does nothing as this is a side effect of emitFiles
1671+
writer = (filename: string, data: string, writeByteOrderMark: boolean) => { };
1672+
allDiagnostics = allDiagnostics.concat(checker.emitFiles(targetSourceFile).errors);
1673+
writer = undefined;
1674+
}
1675+
return allDiagnostics
16601676
}
16611677

16621678
function getCompilerOptionsDiagnostics() {

0 commit comments

Comments
 (0)