@@ -1598,9 +1598,9 @@ module ts {
1598
1598
}
1599
1599
1600
1600
// Only perform incremental parsing on open files that are being edited. If a file was
1601
- // open, but is now closed, we want to reparse entirely so we don't have any tokens that
1601
+ // open, but is now closed, we want to re-parse entirely so we don't have any tokens that
1602
1602
// are holding onto expensive script snapshot instances on the host. Similarly, if a
1603
- // file was closed, then we always want to reparse . This is so our tree doesn't keep
1603
+ // file was closed, then we always want to re-parse . This is so our tree doesn't keep
1604
1604
// the old buffer alive that represented the file on disk (as the host has moved to a
1605
1605
// new text buffer).
1606
1606
var textChangeRange : TypeScript . TextChangeRange = null ;
@@ -1650,12 +1650,29 @@ module ts {
1650
1650
return program . getDiagnostics ( getSourceFile ( filename ) . getSourceFile ( ) ) ;
1651
1651
}
1652
1652
1653
+ // getSemanticDiagnostiscs return array of Diagnostics. If '-d' is not enabled, only report semantic errors
1654
+ // If '-d' enabled, report both semantic and emitter errors
1653
1655
function getSemanticDiagnostics ( filename : string ) {
1654
1656
synchronizeHostData ( ) ;
1655
1657
1656
1658
filename = TypeScript . switchToForwardSlashes ( filename )
1657
-
1658
- return getFullTypeCheckChecker ( ) . getDiagnostics ( getSourceFile ( filename ) ) ;
1659
+ var compilerOptions = program . getCompilerOptions ( ) ;
1660
+ var checker = getFullTypeCheckChecker ( ) ;
1661
+ var targetSourceFile = getSourceFile ( filename ) ;
1662
+
1663
+ // Only perform the action per file regardless of '-out' flag as LanguageServiceHost is expected to call this function per file.
1664
+ // Therefore only get diagnostics for given file.
1665
+
1666
+ var allDiagnostics = checker . getDiagnostics ( targetSourceFile ) ;
1667
+ if ( compilerOptions . declaration ) {
1668
+ // If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface
1669
+ // Get emitter-diagnostics requires calling TypeChecker.emitFiles so we have to define CompilerHost.writer which does nothing because emitFiles function has side effects defined by CompilerHost.writer
1670
+ var savedWriter = writer ;
1671
+ writer = ( filename : string , data : string , writeByteOrderMark : boolean ) => { } ;
1672
+ allDiagnostics = allDiagnostics . concat ( checker . emitFiles ( targetSourceFile ) . errors ) ;
1673
+ writer = savedWriter ;
1674
+ }
1675
+ return allDiagnostics
1659
1676
}
1660
1677
1661
1678
function getCompilerOptionsDiagnostics ( ) {
0 commit comments