@@ -132,13 +132,13 @@ export function parseLocalFileData(text: string) {
132
132
}
133
133
134
134
export interface ICodeBlockActionContext {
135
- code : string ;
136
- codemapperUri ?: URI ;
137
- languageId ?: string ;
138
- codeBlockIndex : number ;
139
- element : unknown ;
135
+ readonly code : string ;
136
+ readonly codemapperUri ?: URI ;
137
+ readonly languageId ?: string ;
138
+ readonly codeBlockIndex : number ;
139
+ readonly element : unknown ;
140
140
141
- chatSessionId : string | undefined ;
141
+ readonly chatSessionId : string | undefined ;
142
142
}
143
143
144
144
export interface ICodeBlockRenderOptions {
@@ -287,6 +287,14 @@ export class CodeBlockPart extends Disposable {
287
287
this . element . classList . add ( 'focused' ) ;
288
288
WordHighlighterContribution . get ( this . editor ) ?. restoreViewState ( true ) ;
289
289
} ) ) ;
290
+ this . _register ( Event . any (
291
+ this . editor . onDidChangeModel ,
292
+ this . editor . onDidChangeModelContent
293
+ ) ( ( ) => {
294
+ if ( this . currentCodeBlockData ) {
295
+ this . updateContexts ( this . currentCodeBlockData ) ;
296
+ }
297
+ } ) ) ;
290
298
291
299
// Parent list scrolled
292
300
if ( delegate . onDidScroll ) {
@@ -455,15 +463,7 @@ export class CodeBlockPart extends Disposable {
455
463
this . editor . revealRangeInCenter ( data . range , ScrollType . Immediate ) ;
456
464
}
457
465
458
- this . toolbar . context = {
459
- code : textModel . getTextBuffer ( ) . getValueInRange ( data . range ?? textModel . getFullModelRange ( ) , EndOfLinePreference . TextDefined ) ,
460
- codeBlockIndex : data . codeBlockIndex ,
461
- element : data . element ,
462
- languageId : textModel . getLanguageId ( ) ,
463
- codemapperUri : data . codemapperUri ,
464
- chatSessionId : data . chatSessionId
465
- } satisfies ICodeBlockActionContext ;
466
- this . resourceContextKey . set ( textModel . uri ) ;
466
+ this . updateContexts ( data ) ;
467
467
}
468
468
469
469
private getVulnerabilitiesLabel ( ) : string {
@@ -477,6 +477,23 @@ export class CodeBlockPart extends Disposable {
477
477
const icon = ( element : IChatResponseViewModel ) => element . vulnerabilitiesListExpanded ? Codicon . chevronDown : Codicon . chevronRight ;
478
478
return `${ referencesLabel } $(${ icon ( this . currentCodeBlockData . element as IChatResponseViewModel ) . id } )` ;
479
479
}
480
+
481
+ private updateContexts ( data : ICodeBlockData ) {
482
+ const textModel = this . editor . getModel ( ) ;
483
+ if ( ! textModel ) {
484
+ return ;
485
+ }
486
+
487
+ this . toolbar . context = {
488
+ code : textModel . getTextBuffer ( ) . getValueInRange ( data . range ?? textModel . getFullModelRange ( ) , EndOfLinePreference . TextDefined ) ,
489
+ codeBlockIndex : data . codeBlockIndex ,
490
+ element : data . element ,
491
+ languageId : textModel . getLanguageId ( ) ,
492
+ codemapperUri : data . codemapperUri ,
493
+ chatSessionId : data . chatSessionId
494
+ } satisfies ICodeBlockActionContext ;
495
+ this . resourceContextKey . set ( textModel . uri ) ;
496
+ }
480
497
}
481
498
482
499
export class ChatCodeBlockContentProvider extends Disposable implements ITextModelContentProvider {
0 commit comments