Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions apps/server/src/process/externalLauncher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,48 @@ it.effect("launches the default browser through the platform command", () => {
);
});

it.effect("strips line and column positions from file manager targets", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-file-manager-" });
const commandPath = path.join(binDir, "open");
yield* fileSystem.writeFileString(commandPath, "#!/bin/sh\n");
yield* fileSystem.chmod(commandPath, 0o755);

const spawned: ChildProcess.StandardCommand[] = [];
yield* Effect.gen(function* () {
const launcher = yield* ExternalLauncher.ExternalLauncher;
for (const cwd of [
"/Users/tester/.claude/CLAUDE.md",
"/Users/tester/.claude/CLAUDE.md:4",
"/Users/tester/.claude/CLAUDE.md:12:4",
]) {
yield* launcher.launchEditor({ editor: "file-manager", cwd });
}
}).pipe(
Effect.provide(
testLayer({
platform: "darwin",
env: { PATH: binDir },
onSpawn: (command) => {
spawned.push(command);
},
}),
),
);

assert.deepEqual(
spawned.map(({ command, args }) => ({ command, args })),
[
{ command: "open", args: ["/Users/tester/.claude/CLAUDE.md"] },
{ command: "open", args: ["/Users/tester/.claude/CLAUDE.md"] },
{ command: "open", args: ["/Users/tester/.claude/CLAUDE.md"] },
],
);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);

it.effect("launches an installed editor with platform-safe arguments", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
Expand Down
8 changes: 6 additions & 2 deletions apps/server/src/process/externalLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,15 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
return yield* new ExternalLauncherUnsupportedEditorError({ editor: input.editor });
}

const target = Option.match(parseTargetPathAndPosition(input.cwd), {
onNone: () => input.cwd,
onSome: ({ path }) => path,
});
return {
editor: editorDef.id,
target: input.cwd,
target,
command: fileManagerCommandForPlatform(platform),
args: [input.cwd],
args: [target],
};
});

Expand Down
Loading