@@ -1598,9 +1598,9 @@ module ts {
15981598 }
15991599
16001600 // 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
16021602 // 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
16041604 // the old buffer alive that represented the file on disk (as the host has moved to a
16051605 // new text buffer).
16061606 var textChangeRange : TypeScript . TextChangeRange = null ;
@@ -1650,12 +1650,29 @@ module ts {
16501650 return program . getDiagnostics ( getSourceFile ( filename ) . getSourceFile ( ) ) ;
16511651 }
16521652
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
16531655 function getSemanticDiagnostics ( filename : string ) {
16541656 synchronizeHostData ( ) ;
16551657
16561658 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
16591676 }
16601677
16611678 function getCompilerOptionsDiagnostics ( ) {
0 commit comments