@@ -132,13 +132,13 @@ export function parseLocalFileData(text: string) {
132132}
133133
134134export 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 ;
140140
141- chatSessionId : string | undefined ;
141+ readonly chatSessionId : string | undefined ;
142142}
143143
144144export interface ICodeBlockRenderOptions {
@@ -287,6 +287,14 @@ export class CodeBlockPart extends Disposable {
287287 this . element . classList . add ( 'focused' ) ;
288288 WordHighlighterContribution . get ( this . editor ) ?. restoreViewState ( true ) ;
289289 } ) ) ;
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+ } ) ) ;
290298
291299 // Parent list scrolled
292300 if ( delegate . onDidScroll ) {
@@ -455,15 +463,7 @@ export class CodeBlockPart extends Disposable {
455463 this . editor . revealRangeInCenter ( data . range , ScrollType . Immediate ) ;
456464 }
457465
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 ) ;
467467 }
468468
469469 private getVulnerabilitiesLabel ( ) : string {
@@ -477,6 +477,23 @@ export class CodeBlockPart extends Disposable {
477477 const icon = ( element : IChatResponseViewModel ) => element . vulnerabilitiesListExpanded ? Codicon . chevronDown : Codicon . chevronRight ;
478478 return `${ referencesLabel } $(${ icon ( this . currentCodeBlockData . element as IChatResponseViewModel ) . id } )` ;
479479 }
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+ }
480497}
481498
482499export class ChatCodeBlockContentProvider extends Disposable implements ITextModelContentProvider {
0 commit comments