Skip to content

Commit 7681105

Browse files
only21milclaude
andcommitted
fix(editors): JetBrains IDEs open file links in the thread's project
A positioned file link was launched as `idea --line N --column C <file>`, so the IDE attached the file to whichever project window was open. With two checkouts of one repo open, it could land in the wrong one. The launch request now carries an optional project root. Chat and terminal file links pass the thread's workspace, and positioned JetBrains launches put it first: `idea <root> --line N --column C <file>`. Unpositioned targets keep the old shape, since a folder target would open as a second project. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e85e009 commit 7681105

6 files changed

Lines changed: 16 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,11 @@ it.effect.each([
531531
yield* Effect.gen(function* () {
532532
const launcher = yield* ExternalLauncher.ExternalLauncher;
533533
assert.include(yield* launcher.resolveAvailableEditors(), editor);
534-
yield* launcher.launchEditor({ editor, cwd: "/workspace with spaces/file.ts:12:4" });
534+
yield* launcher.launchEditor({
535+
editor,
536+
cwd: "/workspace with spaces/file.ts:12:4",
537+
projectRoot: "/workspace with spaces",
538+
});
535539
}).pipe(
536540
Effect.provide(
537541
layerTest({
@@ -547,6 +551,7 @@ it.effect.each([
547551
assert.ok(spawned);
548552
assert.equal(spawned.command, executable);
549553
assert.deepEqual(spawned.args, [
554+
"/workspace with spaces",
550555
"--line",
551556
"12",
552557
"--column",

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ function parseTargetPathAndPosition(target: string): Option.Option<TargetPathAnd
138138
function resolveCommandEditorArgs(
139139
editor: (typeof EDITORS)[number],
140140
target: string,
141+
projectRoot: string | undefined,
141142
): ReadonlyArray<string> {
142143
const parsedTarget = parseTargetPathAndPosition(target);
143144

@@ -150,6 +151,8 @@ function resolveCommandEditorArgs(
150151
return Option.match(parsedTarget, {
151152
onNone: () => [target],
152153
onSome: ({ path, line, column }) => [
154+
// Only positioned targets get the root: a folder target would open as a second project.
155+
...(projectRoot === undefined ? [] : [projectRoot]),
153156
"--line",
154157
line,
155158
// JetBrains IDEs count `--column` from 0; targets count columns from 1.
@@ -487,7 +490,7 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
487490
editor: editorDef.id,
488491
target: input.cwd,
489492
command,
490-
args: [...baseArgs, ...resolveCommandEditorArgs(editorDef, input.cwd)],
493+
args: [...baseArgs, ...resolveCommandEditorArgs(editorDef, input.cwd, input.projectRoot)],
491494
};
492495
}
493496

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ function useChatMarkdownState({
627627
const projects = useProjects();
628628
const [preferredEditor] = usePreferredEditor(availableEditors);
629629
const preferredEditorMenuLabel = openInEditorMenuLabel(preferredEditor);
630-
const openInPreferredEditor = useOpenInPreferredEditor(environmentId, availableEditors);
630+
const openInPreferredEditor = useOpenInPreferredEditor(environmentId, availableEditors, cwd);
631631
const openInEditor = useAtomCommand(shellEnvironment.openInEditor, {
632632
reportFailure: false,
633633
});

‎apps/web/src/components/ThreadTerminalDrawer.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ function TerminalSessionViewport({
574574
const openInPreferredEditor = useOpenInPreferredEditor(
575575
environmentId,
576576
serverConfig?.availableEditors ?? [],
577+
worktreePath ?? cwd,
577578
);
578579
const openTerminalPath = useEffectEvent((target: string) => openInPreferredEditor(target));
579580
const openPreview = useAtomCommand(previewEnvironment.open, {

‎apps/web/src/editorPreferences.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function resolveAndPersistPreferredEditor(availableEditors: readonly EditorId[])
6767
export function useOpenInPreferredEditor(
6868
environmentId: EnvironmentId | null,
6969
availableEditors: readonly EditorId[],
70+
projectRoot?: string,
7071
) {
7172
const openInEditor = useAtomCommand(shellEnvironment.openInEditor, {
7273
reportFailure: false,
@@ -120,6 +121,7 @@ export function useOpenInPreferredEditor(
120121
input: {
121122
cwd: targetPath,
122123
editor,
124+
...(projectRoot ? { projectRoot } : {}),
123125
},
124126
});
125127
return mapAtomCommandResult(result, () => editor);

‎packages/contracts/src/editor.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ export type FileManagerRevealKind = typeof FileManagerRevealKind.Type;
157157
export const LaunchEditorInput = Schema.Struct({
158158
cwd: TrimmedNonEmptyString,
159159
editor: EditorId,
160+
/** Workspace the target belongs to; JetBrains IDEs open positioned files in this project. */
161+
projectRoot: Schema.optional(TrimmedNonEmptyString),
160162
/** Only for file-manager; requires the server's shellRevealInFileManager capability. */
161163
reveal: Schema.optional(Schema.Boolean),
162164
});

0 commit comments

Comments
 (0)