Fix legacy workspace compatibility
This commit is contained in:
@@ -68,6 +68,7 @@ export interface TerminalSessionControllerOptions {
|
||||
hasBinaryChannel: () => boolean;
|
||||
isPathWithinRoot: (rootPath: string, candidatePath: string) => boolean;
|
||||
sessionLogger: pino.Logger;
|
||||
listTerminalWorkspaceRefs?: () => Promise<readonly TerminalWorkspaceRef[]>;
|
||||
listTerminalWorkspaceRoots?: () => Promise<readonly string[]>;
|
||||
// Whether the connected client can reflow restored snapshots. When true the
|
||||
// daemon attaches per-row soft-wrap flags to snapshots; otherwise it omits them
|
||||
@@ -83,6 +84,11 @@ export interface TerminalSessionControllerOptions {
|
||||
getClientBufferedAmount?: () => number | null;
|
||||
}
|
||||
|
||||
interface TerminalWorkspaceRef {
|
||||
workspaceId: string;
|
||||
cwd: string;
|
||||
}
|
||||
|
||||
export interface TerminalSessionControllerMetrics {
|
||||
directorySubscriptionCount: number;
|
||||
streamSubscriptionCount: number;
|
||||
@@ -120,6 +126,7 @@ export class TerminalSessionController {
|
||||
private readonly hasBinaryChannel: () => boolean;
|
||||
private readonly isPathWithinRoot: (rootPath: string, candidatePath: string) => boolean;
|
||||
private readonly sessionLogger: pino.Logger;
|
||||
private readonly listTerminalWorkspaceRefs: () => Promise<readonly TerminalWorkspaceRef[]>;
|
||||
private readonly listTerminalWorkspaceRoots: () => Promise<readonly string[]>;
|
||||
private readonly clientSupportsWrapReflow: () => boolean;
|
||||
private readonly getClientBufferedAmount: () => number | null;
|
||||
@@ -145,7 +152,10 @@ export class TerminalSessionController {
|
||||
this.hasBinaryChannel = options.hasBinaryChannel;
|
||||
this.isPathWithinRoot = options.isPathWithinRoot;
|
||||
this.sessionLogger = options.sessionLogger;
|
||||
this.listTerminalWorkspaceRoots = options.listTerminalWorkspaceRoots ?? (async () => []);
|
||||
this.listTerminalWorkspaceRefs = options.listTerminalWorkspaceRefs ?? (async () => []);
|
||||
this.listTerminalWorkspaceRoots =
|
||||
options.listTerminalWorkspaceRoots ??
|
||||
(async () => (await this.listTerminalWorkspaceRefs()).map((workspace) => workspace.cwd));
|
||||
this.clientSupportsWrapReflow = options.clientSupportsWrapReflow ?? (() => false);
|
||||
this.getClientBufferedAmount = options.getClientBufferedAmount ?? (() => 0);
|
||||
}
|
||||
@@ -520,7 +530,8 @@ export class TerminalSessionController {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!msg.workspaceId) {
|
||||
const workspaceId = msg.workspaceId ?? (await this.resolveLegacyTerminalWorkspaceId(msg.cwd));
|
||||
if (!workspaceId) {
|
||||
this.emit({
|
||||
type: "create_terminal_response",
|
||||
payload: {
|
||||
@@ -534,7 +545,7 @@ export class TerminalSessionController {
|
||||
|
||||
const session = await this.terminalManager.createTerminal({
|
||||
cwd: msg.cwd,
|
||||
workspaceId: msg.workspaceId,
|
||||
workspaceId,
|
||||
name: msg.name,
|
||||
command: msg.command,
|
||||
args: msg.args,
|
||||
@@ -568,6 +579,31 @@ export class TerminalSessionController {
|
||||
}
|
||||
}
|
||||
|
||||
private async resolveLegacyTerminalWorkspaceId(cwd: string): Promise<string | null> {
|
||||
const workspaceRefs = await this.listTerminalWorkspaceRefs();
|
||||
if (workspaceRefs.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const exactMatch = workspaceRefs.find((workspace) => this.isSamePath(workspace.cwd, cwd));
|
||||
if (exactMatch) {
|
||||
return exactMatch.workspaceId;
|
||||
}
|
||||
|
||||
const ownerRoot = this.resolveTerminalOwnerRoot(
|
||||
cwd,
|
||||
workspaceRefs.map((workspace) => workspace.cwd),
|
||||
);
|
||||
if (!ownerRoot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
workspaceRefs.find((workspace) => this.isSamePath(workspace.cwd, ownerRoot))?.workspaceId ??
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
private async handleRenameTerminalRequest(msg: RenameTerminalRequest): Promise<void> {
|
||||
const respond = (success: boolean, error: string | null): void => {
|
||||
this.emit({
|
||||
|
||||
Reference in New Issue
Block a user