@@ -85,9 +85,9 @@ namespace ts.server {
8585 return { line : lineAndCharacter . line + 1 , offset : lineAndCharacter . character + 1 } ;
8686 }
8787
88- function formatConfigFileDiag ( diag : Diagnostic , includeFileName : true ) : protocol . DiagnosticWithFileName ;
89- function formatConfigFileDiag ( diag : Diagnostic , includeFileName : false ) : protocol . Diagnostic ;
90- function formatConfigFileDiag ( diag : Diagnostic , includeFileName : boolean ) : protocol . Diagnostic | protocol . DiagnosticWithFileName {
88+ function formatDiagnosticToProtocol ( diag : Diagnostic , includeFileName : true ) : protocol . DiagnosticWithFileName ;
89+ function formatDiagnosticToProtocol ( diag : Diagnostic , includeFileName : false ) : protocol . Diagnostic ;
90+ function formatDiagnosticToProtocol ( diag : Diagnostic , includeFileName : boolean ) : protocol . Diagnostic | protocol . DiagnosticWithFileName {
9191 const start = ( diag . file && convertToLocation ( getLineAndCharacterOfPosition ( diag . file , diag . start ! ) ) ) ! ; // TODO: GH#18217
9292 const end = ( diag . file && convertToLocation ( getLineAndCharacterOfPosition ( diag . file , diag . start ! + diag . length ! ) ) ) ! ; // TODO: GH#18217
9393 const text = flattenDiagnosticMessageText ( diag . messageText , "\n" ) ;
@@ -699,7 +699,7 @@ namespace ts.server {
699699 break ;
700700 case ConfigFileDiagEvent :
701701 const { triggerFile, configFileName : configFile , diagnostics } = event . data ;
702- const bakedDiags = map ( diagnostics , diagnostic => formatConfigFileDiag ( diagnostic , /*includeFileName*/ true ) ) ;
702+ const bakedDiags = map ( diagnostics , diagnostic => formatDiagnosticToProtocol ( diagnostic , /*includeFileName*/ true ) ) ;
703703 this . event < protocol . ConfigFileDiagnosticEventBody > ( {
704704 triggerFile,
705705 configFile,
@@ -998,7 +998,7 @@ namespace ts.server {
998998 this . convertToDiagnosticsWithLinePositionFromDiagnosticFile ( diagnosticsForConfigFile ) :
999999 map (
10001000 diagnosticsForConfigFile ,
1001- diagnostic => formatConfigFileDiag ( diagnostic , /*includeFileName*/ false )
1001+ diagnostic => formatDiagnosticToProtocol ( diagnostic , /*includeFileName*/ false )
10021002 ) ;
10031003 }
10041004
@@ -1009,8 +1009,10 @@ namespace ts.server {
10091009 length : d . length ! , // TODO: GH#18217
10101010 category : diagnosticCategoryName ( d ) ,
10111011 code : d . code ,
1012+ source : d . source ,
10121013 startLocation : ( d . file && convertToLocation ( getLineAndCharacterOfPosition ( d . file , d . start ! ) ) ) ! , // TODO: GH#18217
10131014 endLocation : ( d . file && convertToLocation ( getLineAndCharacterOfPosition ( d . file , d . start ! + d . length ! ) ) ) ! , // TODO: GH#18217
1015+ reportsUnnecessary : d . reportsUnnecessary ,
10141016 relatedInformation : map ( d . relatedInformation , formatRelatedInformation )
10151017 } ) ) ;
10161018 }
@@ -1108,11 +1110,20 @@ namespace ts.server {
11081110 } ;
11091111 }
11101112
1111- private getEmitOutput ( args : protocol . FileRequestArgs ) : EmitOutput {
1113+ private getEmitOutput ( args : protocol . EmitOutputRequestArgs ) : EmitOutput | protocol . EmitOutput {
11121114 const { file, project } = this . getFileAndProject ( args ) ;
1113- return project . shouldEmitFile ( project . getScriptInfo ( file ) ) ?
1114- project . getLanguageService ( ) . getEmitOutput ( file ) :
1115- { emitSkipped : true , outputFiles : [ ] } ;
1115+ if ( ! project . shouldEmitFile ( project . getScriptInfo ( file ) ) ) {
1116+ return { emitSkipped : true , outputFiles : [ ] , diagnostics : [ ] } ;
1117+ }
1118+ const result = project . getLanguageService ( ) . getEmitOutput ( file ) ;
1119+ return args . richResponse ?
1120+ {
1121+ ...result ,
1122+ diagnostics : args . includeLinePosition ?
1123+ this . convertToDiagnosticsWithLinePositionFromDiagnosticFile ( result . diagnostics ) :
1124+ result . diagnostics . map ( d => formatDiagnosticToProtocol ( d , /*includeFileName*/ true ) )
1125+ } :
1126+ result ;
11161127 }
11171128
11181129 private mapDefinitionInfo ( definitions : readonly DefinitionInfo [ ] , project : Project ) : readonly protocol . FileSpanWithContext [ ] {
@@ -1708,16 +1719,24 @@ namespace ts.server {
17081719 ) ;
17091720 }
17101721
1711- private emitFile ( args : protocol . CompileOnSaveEmitFileRequestArgs ) {
1722+ private emitFile ( args : protocol . CompileOnSaveEmitFileRequestArgs ) : boolean | protocol . EmitResult | EmitResult {
17121723 const { file, project } = this . getFileAndProject ( args ) ;
17131724 if ( ! project ) {
17141725 Errors . ThrowNoProject ( ) ;
17151726 }
17161727 if ( ! project . languageServiceEnabled ) {
1717- return false ;
1728+ return args . richResponse ? { emitSkipped : true , diagnostics : [ ] } : false ;
17181729 }
17191730 const scriptInfo = project . getScriptInfo ( file ) ! ;
1720- return project . emitFile ( scriptInfo , ( path , data , writeByteOrderMark ) => this . host . writeFile ( path , data , writeByteOrderMark ) ) ;
1731+ const { emitSkipped, diagnostics } = project . emitFile ( scriptInfo , ( path , data , writeByteOrderMark ) => this . host . writeFile ( path , data , writeByteOrderMark ) ) ;
1732+ return args . richResponse ?
1733+ {
1734+ emitSkipped,
1735+ diagnostics : args . includeLinePosition ?
1736+ this . convertToDiagnosticsWithLinePositionFromDiagnosticFile ( diagnostics ) :
1737+ diagnostics . map ( d => formatDiagnosticToProtocol ( d , /*includeFileName*/ true ) )
1738+ } :
1739+ ! emitSkipped ;
17211740 }
17221741
17231742 private getSignatureHelpItems ( args : protocol . SignatureHelpRequestArgs , simplifiedResult : boolean ) : protocol . SignatureHelpItems | SignatureHelpItems | undefined {
0 commit comments