Skip to content

Commit 20ef250

Browse files
maria-rcksclaude
andauthored
fix(editors): accept root paths and Windows servers in Zed remote links (pingdotgg#11044)
Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 5735693 commit 20ef250

4 files changed

Lines changed: 31 additions & 9 deletions

File tree

‎apps/desktop/src/electron/ElectronShell.test.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,16 @@ describe("ElectronShell", () => {
9393
openExternalMock.mockResolvedValue(undefined);
9494

9595
const electronShell = yield* ElectronShell.ElectronShell;
96-
const result = yield* electronShell.openExternal("zed://ssh/example.com/home/user/project");
96+
const results = yield* Effect.all([
97+
electronShell.openExternal("zed://ssh/example.com/home/user/project"),
98+
electronShell.openExternal("zed://ssh/example.com/"),
99+
]);
97100

98-
assert.equal(result, true);
99-
assert.deepEqual(openExternalMock.mock.calls, [["zed://ssh/example.com/home/user/project"]]);
101+
assert.deepEqual(results, [true, true]);
102+
assert.deepEqual(openExternalMock.mock.calls, [
103+
["zed://ssh/example.com/home/user/project"],
104+
["zed://ssh/example.com/"],
105+
]);
100106
}).pipe(Effect.provide(ElectronShell.layer)),
101107
);
102108

‎apps/desktop/src/electron/ElectronShell.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const REMOTE_EDITOR_PROTOCOLS = new Set(
3636
);
3737

3838
// Zed's host sits in the first path segment, so it needs its own userinfo ban.
39-
const ZED_SSH_PATHNAME = /^\/[^/@:]+\/.+$/;
39+
const ZED_SSH_PATHNAME = /^\/[^/@:]+\/.*$/;
4040

4141
const isRemoteEditorUrl = (url: URL) =>
4242
REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&

‎apps/web/src/remoteOpen.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ describe("buildRemoteOpenUrl", () => {
151151
).toBe("zed://ssh/sol.tail1234.ts.net/home/theo/code/my%20repo");
152152
});
153153

154+
it("drops the Windows drive letter for Zed", () => {
155+
expect(
156+
buildRemoteOpenUrl({ editor: "zed", host: "sol", absolutePath: "C:\\Users\\theo" }),
157+
).toBe("zed://ssh/sol/Users/theo");
158+
expect(buildRemoteOpenUrl({ editor: "zed", host: "sol", absolutePath: "/C:/project" })).toBe(
159+
"zed://ssh/sol/C%3A/project",
160+
);
161+
});
162+
154163
it("returns undefined for editors without remote support", () => {
155164
expect(buildRemoteOpenUrl({ editor: "idea", host: "sol", absolutePath: "/tmp/x" })).toBe(
156165
undefined,

‎packages/contracts/src/editor.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export type LaunchEditorInput = typeof LaunchEditorInput.Type;
9191

9292
const remoteSchemeOf = (editor: EditorDefinition): string | undefined => editor.remoteScheme;
9393

94-
/** Editors that can open a remote workspace via `vscode-remote` deep links. */
94+
/** Editors that can open a remote workspace via an SSH deep link. */
9595
export const REMOTE_CAPABLE_EDITOR_IDS: ReadonlyArray<EditorId> = EDITORS.flatMap((editor) =>
9696
remoteSchemeOf(editor) !== undefined ? [editor.id] : [],
9797
);
@@ -119,11 +119,18 @@ export const buildRemoteOpenUrl = (input: {
119119
// Windows server paths (`C:\...`) appear as `/C:/...` in vscode-remote URIs.
120120
const posixPath = input.absolutePath.replaceAll("\\", "/");
121121
const rootedPath = posixPath.startsWith("/") ? posixPath : `/${posixPath}`;
122-
const encodedPath = rootedPath.split("/").map(encodeURIComponent).join("/");
123122
const encodedHost = encodeURIComponent(input.host);
124-
return input.editor === "zed"
125-
? `${scheme}://ssh/${encodedHost}${encodedPath}`
126-
: `${scheme}://vscode-remote/ssh-remote+${encodedHost}${encodedPath}`;
123+
if (input.editor === "zed") {
124+
// Zed's remote server resolves a rooted path on the system drive, so a
125+
// Windows `C:\Users\x` must become `/Users/x` (verified in #8938). Other
126+
// drives are untested and kept as is rather than silently remapped, and a
127+
// POSIX path that happens to start with `/C:` is left alone.
128+
const zedPath = /^[Cc]:[\\/]/.test(input.absolutePath) ? rootedPath.slice(3) : rootedPath;
129+
const encodedZedPath = zedPath.split("/").map(encodeURIComponent).join("/");
130+
return `${scheme}://ssh/${encodedHost}${encodedZedPath}`;
131+
}
132+
const encodedPath = rootedPath.split("/").map(encodeURIComponent).join("/");
133+
return `${scheme}://vscode-remote/ssh-remote+${encodedHost}${encodedPath}`;
127134
};
128135

129136
/**

0 commit comments

Comments
 (0)