feat(plugins): open workbench in tabs from dock surfaces
This commit is contained in:
1 parent
bba60bfa86
commit
0212231421
6 files changed
+31
-11
No files matched your search
@@ -297,11 +297,26 @@ function rerunActiveCommand() {
|
||||
|
||||
// A dock-hosted webview asking for another panel via the bridge openWorkbench: the host rebuilds the authoritative
|
||||
// context (dropping plugin-supplied reserved fields) and adds one generic panel entry.
|
||||
function onPanelOpenWorkbench(entry: (typeof entries.value)[number], _contributionId: string, childContext?: Record<string, unknown>) {
|
||||
// `options.target === "tab"` (bridge extension) routes to the main-workbench tab
|
||||
// path instead — same reuse/session-numbering semantics as tab-surface callers
|
||||
// (queryStore.openPluginWorkbench). Without the option the dock-entry behavior
|
||||
// is unchanged, so older plugins keep working.
|
||||
function onPanelOpenWorkbench(entry: (typeof entries.value)[number], _contributionId: string, childContext?: Record<string, unknown>, options?: { forceNew?: boolean; target?: "tab" }) {
|
||||
const payload = childContext && typeof childContext === "object" && !Array.isArray(childContext) ? { ...childContext } : {};
|
||||
delete payload.workbenchId;
|
||||
delete payload.restored;
|
||||
delete payload.surface;
|
||||
if (options?.target === "tab") {
|
||||
// Title derivation mirrors the tab-surface caller (PluginWorkbenchTab
|
||||
// openWorkbench): per-connection sessions are titled after the connection
|
||||
// display name, falling back to the localized workbench label and the
|
||||
// dock entry's title — never the raw contribution id.
|
||||
const contextConnectionId = typeof payload.connectionId === "string" ? payload.connectionId : "";
|
||||
const connectionName = contextConnectionId ? connectionStore.getConfig(contextConnectionId)?.name : undefined;
|
||||
const label = createFrontendPluginRegistry(plugins.value, locale.value).findWorkbench(entry.pluginId, entry.workbenchContributionId)?.contribution.label;
|
||||
queryStore.openPluginWorkbench(entry.pluginId, entry.workbenchContributionId, { title: connectionName || label || entry.title, context: payload, forceNew: options.forceNew === true });
|
||||
return;
|
||||
}
|
||||
const id = addPluginDockEntry({
|
||||
pluginId: entry.pluginId,
|
||||
workbenchContributionId: entry.workbenchContributionId,
|
||||
@@ -624,7 +639,7 @@ onScopeDispose(() => window.removeEventListener("blur", onPlusMenuWindowBlur));
|
||||
:contribution="workbenchContributionFor(entry)!"
|
||||
:context="entry.context"
|
||||
@close-tab="closeEntry(entry.id)"
|
||||
@open-workbench="(_pluginId, contributionId, context) => onPanelOpenWorkbench(entry, contributionId, context)"
|
||||
@open-workbench="(_pluginId, contributionId, context, options) => onPanelOpenWorkbench(entry, contributionId, context, options)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -27,7 +27,8 @@ export interface PluginDockEntry {
|
||||
instanceKey?: string;
|
||||
title: string;
|
||||
icon?: string;
|
||||
/** Host-authored context: workbenchId=id, restored=false, surface="panel". */
|
||||
/** Host-authored context: workbenchId=id, restored=false, surface="dock". */
|
||||
/** Surface vocabulary (open set, unknown falls back): "tab" (main multi-tab workbench) / "dock" (bottom dock, was "panel" — renamed 2026-09-30) / "sidebar-left" / "sidebar-right" / "window" (reserved). */
|
||||
context: Record<string, unknown>;
|
||||
}
|
||||
|
||||
@@ -78,7 +79,7 @@ export function addPluginDockEntry(payload: AddPluginDockEntryPayload): string {
|
||||
...(payload.commandContext ?? {}),
|
||||
workbenchId: id,
|
||||
restored: false,
|
||||
surface: "panel",
|
||||
surface: "dock",
|
||||
},
|
||||
});
|
||||
activeEntryId.value = id;
|
||||
|
||||
@@ -108,7 +108,7 @@ describe("plugin command registry (PR-A4)", () => {
|
||||
expect(firstEntry.context.workbenchId).toBe(firstEntry.id);
|
||||
expect(firstEntry.context.workbenchId).not.toBe("plugin-forged");
|
||||
expect(firstEntry.context.restored).toBe(false);
|
||||
expect(firstEntry.context.surface).toBe("panel");
|
||||
expect(firstEntry.context.surface).toBe("dock");
|
||||
expect(activeEntryId.value).toBe(firstEntry.id);
|
||||
// §4.1 reuse key = pluginId + commandId + presentation + instance_key.
|
||||
expect(firstEntry.instanceKey).toBe("local-terminal");
|
||||
@@ -270,6 +270,6 @@ describe("plugin command registry (PR-A4)", () => {
|
||||
// §11: reserved identity fields are host-authored — forged values never pass.
|
||||
expect(entry.context.workbenchId).toBe(entry.id);
|
||||
expect(entry.context.restored).toBe(false);
|
||||
expect(entry.context.surface).toBe("panel");
|
||||
expect(entry.context.surface).toBe("dock");
|
||||
});
|
||||
});
|
||||
@@ -41,7 +41,7 @@ export function executePluginCommand(registry: FrontendPluginRegistry, queryStor
|
||||
if (!workbench) return { error: `Command '${pluginId}.${commandId}' references missing workbench '${action.workbench}'` };
|
||||
// §5.4 re-validate enablement right before execution (against the current context snapshot; the surface key follows
|
||||
// presentation).
|
||||
const commandContextKeys: PluginConditionContextKeys = { surface: action.presentation === "panel" ? "panel" : "tab", "connection.state": "none", readOnly: false };
|
||||
const commandContextKeys: PluginConditionContextKeys = { surface: action.presentation === "panel" ? "dock" : "tab", "connection.state": "none", readOnly: false };
|
||||
if (!evaluatePluginCommandConditions(command.enablement?.all, commandContextKeys)) {
|
||||
return { error: `Command '${pluginId}.${commandId}' is disabled by enablement` };
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ export interface PluginHostBridgeApi {
|
||||
generateAiText?(pluginName: string, input: PluginAiGenerateRequest): Promise<string>;
|
||||
openAiConversation?(request: AiPluginConversationRequest): Promise<void>;
|
||||
setAiRecommendations?(update: PluginAiRecommendationHostUpdate): void;
|
||||
openWorkbench?(pluginId: string, contributionId: string, context?: PluginWorkbenchContext, options?: { forceNew?: boolean }): Promise<void> | void;
|
||||
openWorkbench?(pluginId: string, contributionId: string, context?: PluginWorkbenchContext, options?: { forceNew?: boolean; target?: "tab" }): Promise<void> | void;
|
||||
/**
|
||||
* §4/§5 command execution asked from a plugin webview: the same registry
|
||||
* path as menu execution — enablement (§5.4), §4.1 singleton reuse,
|
||||
@@ -685,7 +685,11 @@ export class PluginHostBridge {
|
||||
this.requirePermission("host.workbench");
|
||||
if (!this.api.openWorkbench) throw new Error("Host workbench navigation is unavailable");
|
||||
const input = requireRecord(params, "host.openWorkbench params");
|
||||
await this.api.openWorkbench(this.plugin.manifest.id, requireProtocolName(input.contributionId, "workbench contribution"), isRecord(input.context) ? input.context : undefined, { forceNew: input.forceNew === true });
|
||||
// `target: "tab"` lets a dock-hosted webview ask for a main-workbench
|
||||
// tab instead of another dock entry (e.g. the SSH dock's "open session
|
||||
// in tab" button). Surfaces that ignore it keep the old behavior, so
|
||||
// older handlers stay compatible.
|
||||
await this.api.openWorkbench(this.plugin.manifest.id, requireProtocolName(input.contributionId, "workbench contribution"), isRecord(input.context) ? input.context : undefined, { forceNew: input.forceNew === true, target: input.target === "tab" ? "tab" : undefined });
|
||||
return null;
|
||||
}
|
||||
if (method === "host.executeCommand") {
|
||||
@@ -1239,7 +1243,7 @@ export function pluginSdkSource(initialTheme?: PluginBridgeTheme): string {
|
||||
const asset = await request('ui.readAsset', { path });
|
||||
return URL.createObjectURL(new Blob([decode(asset.dataBase64)], { type: asset.contentType }));
|
||||
},
|
||||
openWorkbench: (contributionId, childContext, options) => request('host.openWorkbench', { contributionId, context: childContext, forceNew: !!(options && options.forceNew) }),
|
||||
openWorkbench: (contributionId, childContext, options) => request('host.openWorkbench', { contributionId, context: childContext, forceNew: !!(options && options.forceNew), target: options && options.target === "tab" ? "tab" : undefined }),
|
||||
// §4/§5 command execution from a webview — the same registry path a menu
|
||||
// placement takes (enablement, §4.1 reuse, host-authored context),
|
||||
// scoped to the plugin's own declared commands. The optional context
|
||||
|
||||
@@ -80,7 +80,7 @@ export function collectPluginShortcuts(registry: FrontendPluginRegistry): Plugin
|
||||
rootUri,
|
||||
disabled: command
|
||||
? !evaluatePluginCommandConditions(command.enablement?.all, {
|
||||
surface: command.action.presentation === "panel" ? "panel" : "tab",
|
||||
surface: command.action.presentation === "panel" ? "dock" : "tab",
|
||||
"connection.state": "none",
|
||||
readOnly: false,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user