Skip to content

Commit 22744df

Browse files
fix(server): open projects in a new VS Code window
Opening a project in a VS Code-family editor ran `code <dir>` with no window flag, so with window.openFoldersInNewWindow set to off VS Code replaced the user's last active window. Directory targets now pass --new-window; file and file:line opens keep their current behaviour. Fixes #34449 AI-assisted; verified with the tests and tools listed above.
1 parent b517c58 commit 22744df

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎apps/server/src/process/externalLauncher.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,17 @@ function parseTargetPathAndPosition(target: string): Option.Option<TargetPathAnd
139139
function resolveCommandEditorArgs(
140140
editor: (typeof EDITORS)[number],
141141
target: string,
142+
isDirectory: boolean,
142143
): ReadonlyArray<string> {
143144
const parsedTarget = parseTargetPathAndPosition(target);
144145

145146
switch (editor.launchStyle) {
146147
case "direct-path":
147148
return [target];
148149
case "goto":
149-
return Option.isSome(parsedTarget) ? ["--goto", target] : [target];
150+
if (Option.isSome(parsedTarget)) return ["--goto", target];
151+
// Without a window flag, VS Code's window settings may replace the user's last active window.
152+
return isDirectory ? ["--new-window", target] : [target];
150153
case "line-column":
151154
return Option.match(parsedTarget, {
152155
onNone: () => [target],
@@ -485,11 +488,17 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
485488
});
486489
}
487490
const { command, baseArgs } = resolved.value;
491+
const isDirectory =
492+
editorDef.launchStyle === "goto" &&
493+
(yield* (yield* FileSystem.FileSystem).stat(input.cwd).pipe(
494+
Effect.map((info) => info.type === "Directory"),
495+
Effect.orElseSucceed(() => false),
496+
));
488497
return {
489498
editor: editorDef.id,
490499
target: input.cwd,
491500
command,
492-
args: [...baseArgs, ...resolveCommandEditorArgs(editorDef, input.cwd)],
501+
args: [...baseArgs, ...resolveCommandEditorArgs(editorDef, input.cwd, isDirectory)],
493502
};
494503
}
495504

0 commit comments

Comments
 (0)