diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolInvocationPart.ts b/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolInvocationPart.ts index 1fa9051e6d4..3447d7b8cfe 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolInvocationPart.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolInvocationPart.ts @@ -165,7 +165,7 @@ export class ChatToolInvocationPart extends Disposable implements IChatContentPa } if (isToolResultOutputDetails(resultDetails)) { - return this.instantiationService.createInstance(ChatToolOutputSubPart, this.toolInvocation, this.context); + return this.instantiationService.createInstance(ChatToolOutputSubPart, this.toolInvocation, this.context, this._onDidRemount.event); } if (isToolResultInputOutputDetails(resultDetails)) { diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolOutputPart.ts b/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolOutputPart.ts index 6d903ad98fb..ef45b79f8bf 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolOutputPart.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolOutputPart.ts @@ -8,6 +8,7 @@ import { renderMarkdown } from '../../../../../../../base/browser/markdownRender import { decodeBase64 } from '../../../../../../../base/common/buffer.js'; import { CancellationTokenSource } from '../../../../../../../base/common/cancellation.js'; import { Codicon } from '../../../../../../../base/common/codicons.js'; +import { Event } from '../../../../../../../base/common/event.js'; import { ThemeIcon } from '../../../../../../../base/common/themables.js'; import { generateUuid } from '../../../../../../../base/common/uuid.js'; import { localize } from '../../../../../../../nls.js'; @@ -41,6 +42,7 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart { constructor( toolInvocation: IChatToolInvocation | IChatToolInvocationSerialized, private readonly context: IChatContentPartRenderContext, + private readonly onDidRemount: Event, @IChatOutputRendererService private readonly chatOutputItemRendererService: IChatOutputRendererService, @IChatWidgetService private readonly chatWidgetService: IChatWidgetService, @IInstantiationService private readonly instantiationService: IInstantiationService, @@ -59,13 +61,15 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart { this.domNode = dom.$('div.tool-output-part'); - const titleEl = dom.$('.output-title'); - this.domNode.appendChild(titleEl); - if (typeof toolInvocation.invocationMessage === 'string') { - titleEl.textContent = toolInvocation.invocationMessage; - } else { - const md = this._register(renderMarkdown(toolInvocation.invocationMessage)); - titleEl.appendChild(md.element); + if (toolInvocation.invocationMessage) { + const titleEl = dom.$('.output-title'); + this.domNode.appendChild(titleEl); + if (typeof toolInvocation.invocationMessage === 'string') { + titleEl.textContent = toolInvocation.invocationMessage; + } else { + const md = this._register(renderMarkdown(toolInvocation.invocationMessage)); + titleEl.appendChild(md.element); + } } this.domNode.appendChild(this.createOutputPart(toolInvocation, details)); @@ -130,12 +134,15 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart { })); // When the webview is disconnected from the DOM due to being hidden, we need to reload it when it is shown again. - const widget = this.chatWidgetService.getWidgetBySessionResource(this.context.element.sessionResource); - if (widget) { - this._register(widget?.onDidShow(() => { + this._register(this.context.onDidChangeVisibility(visible => { + if (visible) { renderedItem.reinitialize(); - })); - } + } + })); + + this._register(this.onDidRemount(() => { + renderedItem.reinitialize(); + })); }, (error) => { console.error('Error rendering tool output:', error);