From 4e3f7dcbe235bc192dd1d12be070eb547af08732 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Mon, 20 Apr 2026 23:30:49 +0000 Subject: [PATCH] Hide 'View Extension' hover action for core chat agents (#311526) * Hide 'View Extension' hover action for core chat agents Core agents (e.g. the agent host) register with a placeholder extension id and have no real extension to view. Skip adding the 'View Extension' hover action when the agent has isCore: true. Fixes #311510 (Written by Copilot) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix TDZ in getChatAgentHoverOptions, defer agent lookup Some callers construct the hover options before the surrounding template variable is initialized, so resolving the agent eagerly hits a TDZ. Make 'actions' a lazy getter so the agent is only read when the hover is actually shown. (Written by Copilot) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../chat/browser/widget/chatAgentHover.ts | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatAgentHover.ts b/src/vs/workbench/contrib/chat/browser/widget/chatAgentHover.ts index a9d7948cf98..0a282d4d840 100644 --- a/src/vs/workbench/contrib/chat/browser/widget/chatAgentHover.ts +++ b/src/vs/workbench/contrib/chat/browser/widget/chatAgentHover.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as dom from '../../../../../base/browser/dom.js'; -import { IManagedHoverOptions } from '../../../../../base/browser/ui/hover/hover.js'; +import { IHoverAction, IManagedHoverOptions } from '../../../../../base/browser/ui/hover/hover.js'; import { renderIcon } from '../../../../../base/browser/ui/iconLabel/iconLabels.js'; import { CancellationTokenSource } from '../../../../../base/common/cancellation.js'; import { Codicon } from '../../../../../base/common/codicons.js'; @@ -121,18 +121,26 @@ export class ChatAgentHover extends Disposable { } export function getChatAgentHoverOptions(getAgent: () => IChatAgentData | undefined, commandService: ICommandService): IManagedHoverOptions { - return { - actions: [ - { - commandId: showExtensionsWithIdsCommandId, - label: localize('viewExtensionLabel', "View Extension"), - run: () => { - const agent = getAgent(); - if (agent) { - commandService.executeCommand(showExtensionsWithIdsCommandId, [agent.extensionId.value]); - } - }, + const viewExtensionAction: IHoverAction = { + commandId: showExtensionsWithIdsCommandId, + label: localize('viewExtensionLabel', "View Extension"), + run: () => { + const agent = getAgent(); + if (agent) { + commandService.executeCommand(showExtensionsWithIdsCommandId, [agent.extensionId.value]); } - ] + }, + }; + + // `actions` is a getter so the agent is only resolved at hover-show time. + // Some callers (e.g. chatListRenderer) construct these options before the + // surrounding template is initialized, so calling `getAgent()` eagerly here + // would hit a TDZ on the captured `template` variable. + // Core agents (e.g. agent host) have a placeholder extension id and no real + // extension to view, so we omit the action for them. + return { + get actions() { + return getAgent()?.isCore ? [] : [viewExtensionAction]; + } }; }