diff --git a/src/vs/workbench/contrib/chat/browser/attachments/promptInstructions/promptInstructionsCollectionWidget.ts b/src/vs/workbench/contrib/chat/browser/attachments/promptInstructions/promptInstructionsCollectionWidget.ts index a6cbf93700a8a..7c0fb3d96d212 100644 --- a/src/vs/workbench/contrib/chat/browser/attachments/promptInstructions/promptInstructionsCollectionWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/attachments/promptInstructions/promptInstructionsCollectionWidget.ts @@ -93,7 +93,7 @@ export class PromptInstructionsAttachmentsCollectionWidget extends Disposable { this.render = this.render.bind(this); // when a new attachment model is added, create a new child widget for it - this.model.onAdd((attachment) => { + this._register(this.model.onAdd((attachment) => { const widget = this.initService.createInstance( InstructionsAttachmentWidget, attachment, @@ -114,7 +114,7 @@ export class PromptInstructionsAttachmentsCollectionWidget extends Disposable { // fire the event to notify about the change in the number of attachments this._onAttachmentsCountChange.fire(); - }); + })); } /** diff --git a/src/vs/workbench/contrib/chat/browser/chatAttachmentModel.ts b/src/vs/workbench/contrib/chat/browser/chatAttachmentModel.ts index ac4e1c5ab33bb..223c4d5b4ddab 100644 --- a/src/vs/workbench/contrib/chat/browser/chatAttachmentModel.ts +++ b/src/vs/workbench/contrib/chat/browser/chatAttachmentModel.ts @@ -42,9 +42,19 @@ export class ChatAttachmentModel extends Disposable { this.promptInstructions = this._register( this.initService.createInstance(ChatPromptAttachmentsCollection), - ).onUpdate(() => { - this._onDidChange.fire({ added: [], deleted: [], updated: [] }); - }); + ); + + this._register( + this.promptInstructions.onAdd(() => { + this._onDidChange.fire({ added: [], deleted: [], updated: [] }); + }), + ); + + this._register( + this.promptInstructions.onRemove(() => { + this._onDidChange.fire({ added: [], deleted: [], updated: [] }); + }), + ); } private _attachments = new Map(); diff --git a/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatPromptAttachmentsCollection.ts b/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatPromptAttachmentsCollection.ts index a1817f40e41ef..f88086c5f0e87 100644 --- a/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatPromptAttachmentsCollection.ts +++ b/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatPromptAttachmentsCollection.ts @@ -86,6 +86,37 @@ export const toChatVariable = ( * See {@linkcode ChatPromptAttachmentModel} for individual attachment. */ export class ChatPromptAttachmentsCollection extends Disposable { + /** + * Event that fires then this model is updated. + * + * See {@linkcode onUpdate}. + */ + protected _onUpdate = this._register(new Emitter()); + /** + * Subscribe to the `onUpdate` event. + */ + public onUpdate = this._onUpdate.event; + + /** + * Event that fires when a new prompt instruction attachment is added. + * See {@linkcode onAdd}. + */ + protected _onAdd = this._register(new Emitter()); + /** + * The `onAdd` event fires when a new prompt instruction attachment is added. + */ + public onAdd = this._onAdd.event; + + /** + * Event that fires when a new prompt instruction attachment is removed. + * See {@linkcode onRemove}. + */ + protected _onRemove = this._register(new Emitter()); + /** + * The `onRemove` event fires when a new prompt instruction attachment is removed. + */ + public onRemove = this._onRemove.event; + /** * List of all prompt instruction attachments. */ @@ -154,38 +185,6 @@ export class ChatPromptAttachmentsCollection extends Disposable { ); } - /** - * Event that fires then this model is updated. - * - * See {@linkcode onUpdate}. - */ - protected _onUpdate = this._register(new Emitter()); - /** - * Subscribe to the `onUpdate` event. - * @param callback Function to invoke on update. - */ - public onUpdate(callback: () => unknown): this { - this._register(this._onUpdate.event(callback)); - - return this; - } - - /** - * Event that fires when a new prompt instruction attachment is added. - * See {@linkcode onAdd}. - */ - protected _onAdd = this._register(new Emitter()); - /** - * The `onAdd` event fires when a new prompt instruction attachment is added. - * - * @param callback Function to invoke on add. - */ - public onAdd(callback: (attachment: ChatPromptAttachmentModel) => unknown): this { - this._register(this._onAdd.event(callback)); - - return this; - } - constructor( @IInstantiationService private readonly initService: IInstantiationService, @IConfigurationService private readonly configService: IConfigurationService, @@ -214,6 +213,7 @@ export class ChatPromptAttachmentsCollection extends Disposable { // alternative results in an infinite loop of calling this callback this.attachments.deleteAndLeak(uri.path); this._onUpdate.fire(); + this._onRemove.fire(instruction); }); this.attachments.set(uri.path, instruction);