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>
This commit is contained in:
Rob Lourens
2026-04-20 23:30:49 +00:00
committed by GitHub
parent e0c3dafcdb
commit 4e3f7dcbe2

View File

@@ -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];
}
};
}