@@ -176,6 +176,7 @@ export class Response implements IResponse {
176
176
*/
177
177
private _markdownContent = '' ;
178
178
179
+ private _citations : IChatCodeCitation [ ] = [ ] ;
179
180
180
181
get value ( ) : IChatProgressResponseContent [ ] {
181
182
return this . _responseParts ;
@@ -260,6 +261,11 @@ export class Response implements IResponse {
260
261
}
261
262
}
262
263
264
+ public addCitation ( citation : IChatCodeCitation ) {
265
+ this . _citations . push ( citation ) ;
266
+ this . _updateRepr ( ) ;
267
+ }
268
+
263
269
private _updateRepr ( quiet ?: boolean ) {
264
270
this . _responseRepr = this . _responseParts . map ( part => {
265
271
if ( part . kind === 'treeData' ) {
@@ -281,6 +287,8 @@ export class Response implements IResponse {
281
287
. filter ( s => s . length > 0 )
282
288
. join ( '\n\n' ) ;
283
289
290
+ this . _responseRepr += this . _citations . length ? '\n\n' + getCodeCitationsMessage ( this . _citations ) : '' ;
291
+
284
292
this . _markdownContent = this . _responseParts . map ( part => {
285
293
if ( part . kind === 'inlineReference' ) {
286
294
return basename ( 'uri' in part . inlineReference ? part . inlineReference . uri : part . inlineReference ) ;
@@ -428,6 +436,7 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel
428
436
429
437
applyCodeCitation ( progress : IChatCodeCitation ) {
430
438
this . _codeCitations . push ( progress ) ;
439
+ this . _response . addCitation ( progress ) ;
431
440
this . _onDidChange . fire ( ) ;
432
441
}
433
442
@@ -1140,3 +1149,15 @@ export function appendMarkdownString(md1: IMarkdownString, md2: IMarkdownString
1140
1149
baseUri : md1 . baseUri
1141
1150
} ;
1142
1151
}
1152
+
1153
+ export function getCodeCitationsMessage ( citations : ReadonlyArray < IChatCodeCitation > ) : string {
1154
+ if ( citations . length === 0 ) {
1155
+ return '' ;
1156
+ }
1157
+
1158
+ const licenseTypes = citations . reduce ( ( set , c ) => set . add ( c . license ) , new Set < string > ( ) ) ;
1159
+ const label = licenseTypes . size === 1 ?
1160
+ localize ( 'codeCitation' , "Similar code found with 1 license type" , licenseTypes . size ) :
1161
+ localize ( 'codeCitations' , "Similar code found with {0} license types" , licenseTypes . size ) ;
1162
+ return label ;
1163
+ }
0 commit comments