Skip to content

Commit 9ccc0f8

Browse files
fix(editors): JetBrains IDEs open file links in the thread's project (#33558)
Co-authored-by: Julius Marminge <[email protected]>
1 parent c60aa1a commit 9ccc0f8

6 files changed

Lines changed: 19 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
@@ -687,7 +687,11 @@ it.effect.each([
687687
yield* Effect.gen(function* () {
688688
const launcher = yield* ExternalLauncher.ExternalLauncher;
689689
assert.include(yield* launcher.resolveAvailableEditors(), editor);
690-
yield* launcher.launchEditor({ editor, cwd: "/workspace with spaces/file.ts:12:4" });
690+
yield* launcher.launchEditor({
691+
editor,
692+
cwd: "/workspace with spaces/file.ts:12:4",
693+
projectRoot: "/workspace with spaces",
694+
});
691695
}).pipe(
692696
Effect.provide(
693697
layerTest({
@@ -703,6 +707,7 @@ it.effect.each([
703707
assert.ok(spawned);
704708
assert.equal(spawned.command, executable);
705709
assert.deepEqual(spawned.args, [
710+
"/workspace with spaces",
706711
"--line",
707712
"12",
708713
"--column",

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ function resolveCommandEditorArgs(
140140
editor: (typeof EDITORS)[number],
141141
target: string,
142142
isDirectory: boolean,
143+
projectRoot: string | undefined,
143144
): ReadonlyArray<string> {
144145
const parsedTarget = parseTargetPathAndPosition(target);
145146

@@ -154,6 +155,8 @@ function resolveCommandEditorArgs(
154155
return Option.match(parsedTarget, {
155156
onNone: () => [target],
156157
onSome: ({ path, line, column }) => [
158+
// Only positioned targets get the root: a folder target would open as a second project.
159+
...(projectRoot === undefined ? [] : [projectRoot]),
157160
"--line",
158161
line,
159162
// JetBrains IDEs count `--column` from 0; targets count columns from 1.
@@ -498,7 +501,10 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
498501
editor: editorDef.id,
499502
target: input.cwd,
500503
command,
501-
args: [...baseArgs, ...resolveCommandEditorArgs(editorDef, input.cwd, isDirectory)],
504+
args: [
505+
...baseArgs,
506+
...resolveCommandEditorArgs(editorDef, input.cwd, isDirectory, input.projectRoot),
507+
],
502508
};
503509
}
504510

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ function useChatMarkdownState({
647647
const projects = useProjects();
648648
const [preferredEditor] = usePreferredEditor(availableEditors);
649649
const preferredEditorMenuLabel = openInEditorMenuLabel(preferredEditor);
650-
const openInPreferredEditor = useOpenInPreferredEditor(environmentId, availableEditors);
650+
const openInPreferredEditor = useOpenInPreferredEditor(environmentId, availableEditors, cwd);
651651
const openInEditor = useAtomCommand(shellEnvironment.openInEditor, {
652652
reportFailure: false,
653653
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ function TerminalSessionViewport({
560560
const openInPreferredEditor = useOpenInPreferredEditor(
561561
environmentId,
562562
serverConfig?.availableEditors ?? [],
563+
worktreePath ?? cwd,
563564
);
564565
const openTerminalPath = useEffectEvent((target: string) => openInPreferredEditor(target));
565566
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)