@@ -865,8 +865,8 @@ namespace ts {
865
865
code : messageChain . code ,
866
866
category : messageChain . category ,
867
867
messageText : messageChain . next ? messageChain : messageChain . messageText ,
868
- markdownText : messageChain . next ? messageChain : messageChain . markdownText ,
869
- relatedInformation
868
+ relatedInformation ,
869
+ ... ( ! messageChain . next && messageChain . annotations ? { annotations : messageChain . annotations } : { } )
870
870
} ;
871
871
}
872
872
@@ -7108,21 +7108,27 @@ namespace ts {
7108
7108
getSourceMapSourceConstructor : ( ) => < any > SourceMapSource ,
7109
7109
} ;
7110
7110
7111
- function renderForOutput ( arg : string | number | Type | Symbol , renderContext : DiagnosticRenderContext | undefined ) {
7111
+ function renderForOutput ( arg : string | number | Type | Symbol , renderContext : DiagnosticRenderContext | undefined , offset : number ) {
7112
+ Debug . assertDefined ( arg ) ;
7112
7113
if ( typeof arg === "string" || typeof arg === "number" ) {
7113
7114
return arg ;
7114
7115
}
7115
7116
if ( ! renderContext ) {
7116
7117
return Debug . fail ( "Type or symbol passed into diagnostic rendering pipeline with no renderer provided." ) ;
7117
7118
}
7118
7119
if ( arg . checker ) {
7119
- return renderContext . typeToString ( arg ) ;
7120
+ return renderContext . typeToString ( arg , offset ) ;
7120
7121
}
7121
- return renderContext . symbolToString ( arg ) ;
7122
+ return renderContext . symbolToString ( arg , offset ) ;
7122
7123
}
7123
7124
7124
7125
export function formatStringFromArgs ( text : string , args : ArrayLike < string | number | Type | Symbol > , baseIndex = 0 , renderContext ?: DiagnosticRenderContext ) : string {
7125
- return text . replace ( / { ( \d + ) } / g, ( _match , index : string ) => "" + Debug . assertDefined ( renderForOutput ( args [ + index + baseIndex ] , renderContext ) ) ) ;
7126
+ let offsetAdjustmentFromReplacement = 0 ;
7127
+ return text . replace ( / { ( \d + ) } / g, ( match : string , index : string , offset : number ) => {
7128
+ const text = "" + renderForOutput ( args [ + index + baseIndex ] , renderContext , offset + offsetAdjustmentFromReplacement ) ;
7129
+ offsetAdjustmentFromReplacement += text . length - match . length ;
7130
+ return text ;
7131
+ } ) ;
7126
7132
}
7127
7133
7128
7134
export let localizedDiagnosticMessages : MapLike < string > | undefined ;
@@ -7193,15 +7199,12 @@ namespace ts {
7193
7199
export function createRenderedCompilerDiagnostic ( checker : TypeChecker , flags : DiagnosticRendererFlags , message : DiagnosticMessage , ...args : ( string | number | Type | Symbol | undefined ) [ ] ) : Diagnostic ;
7194
7200
export function createRenderedCompilerDiagnostic ( checker : TypeChecker , flags : DiagnosticRendererFlags , message : DiagnosticMessage ) : Diagnostic {
7195
7201
let text = getLocaleSpecificMessage ( message ) ;
7196
- let markdown : string | undefined ;
7202
+ let spans : SymbolSpan [ ] | undefined ;
7197
7203
7198
7204
if ( arguments . length > 3 ) {
7199
- const unformatted = text ;
7200
- text = formatStringFromArgs ( unformatted , arguments , 3 , checker . getPlainDiagnosticRenderingContext ( flags ) ) ;
7201
- const candidateMarkdown = formatStringFromArgs ( unformatted , arguments , 3 , checker . getMarkdownDiagnosticRenderingContext ( flags ) ) ;
7202
- if ( candidateMarkdown !== text ) {
7203
- markdown = candidateMarkdown ;
7204
- }
7205
+ const ctx = checker . getDiagnosticRenderingContext ( flags ) ;
7206
+ text = formatStringFromArgs ( text , arguments , 3 , ctx ) ;
7207
+ spans = ctx . getPendingAnnotationSpans ( ) ;
7205
7208
}
7206
7209
7207
7210
return {
@@ -7213,7 +7216,7 @@ namespace ts {
7213
7216
category : message . category ,
7214
7217
code : message . code ,
7215
7218
reportsUnnecessary : message . reportsUnnecessary ,
7216
- ...( typeof markdown === "string " ? { markdownText : markdown } : { } )
7219
+ ...( typeof spans === "undefined " ? { } : { annotations : spans } )
7217
7220
} ;
7218
7221
}
7219
7222
@@ -7249,15 +7252,12 @@ namespace ts {
7249
7252
export function chainRenderedDiagnosticMessages ( checker : TypeChecker , flags : DiagnosticRendererFlags , details : DiagnosticMessageChain | undefined , message : DiagnosticMessage , ...args : ( string | number | Type | Symbol | undefined ) [ ] ) : DiagnosticMessageChain ;
7250
7253
export function chainRenderedDiagnosticMessages ( checker : TypeChecker , flags : DiagnosticRendererFlags , details : DiagnosticMessageChain | undefined , message : DiagnosticMessage ) : DiagnosticMessageChain {
7251
7254
let text = getLocaleSpecificMessage ( message ) ;
7252
- let markdown : string | undefined ;
7255
+ let spans : SymbolSpan [ ] | undefined ;
7253
7256
7254
7257
if ( arguments . length > 4 ) {
7255
- const unformatted = text ;
7256
- text = formatStringFromArgs ( unformatted , arguments , 4 , checker . getPlainDiagnosticRenderingContext ( flags ) ) ;
7257
- const candidateMarkdown = formatStringFromArgs ( unformatted , arguments , 4 , checker . getMarkdownDiagnosticRenderingContext ( flags ) ) ;
7258
- if ( candidateMarkdown !== text ) {
7259
- markdown = candidateMarkdown ;
7260
- }
7258
+ const ctx = checker . getDiagnosticRenderingContext ( flags ) ;
7259
+ text = formatStringFromArgs ( text , arguments , 4 , ctx ) ;
7260
+ spans = ctx . getPendingAnnotationSpans ( ) ;
7261
7261
}
7262
7262
7263
7263
return {
@@ -7266,7 +7266,7 @@ namespace ts {
7266
7266
code : message . code ,
7267
7267
7268
7268
next : details ,
7269
- ...( typeof markdown === "string " ? { markdownText : markdown } : { } )
7269
+ ...( typeof spans === "undefined " ? { } : { annotations : spans } )
7270
7270
} ;
7271
7271
}
7272
7272
0 commit comments