fix(editors): accept root paths and Windows servers in Zed remote links (#11044)

Co-authored-by: Claude Fable 5.1 <[email protected]>
This commit is contained in:
mariaandClaude Fable 5.1 authored and GitHub committed 2026-09-10 23:39:41 -03:00
1 parent 5735693d4a
commit 20ef25037f
4 files changed
+31 -9

No files matched your search

@@ -93,10 +93,16 @@ describe("ElectronShell", () => {
openExternalMock.mockResolvedValue(undefined);
const electronShell = yield* ElectronShell.ElectronShell;
const result = yield* electronShell.openExternal("zed://ssh/example.com/home/user/project");
const results = yield* Effect.all([
electronShell.openExternal("zed://ssh/example.com/home/user/project"),
electronShell.openExternal("zed://ssh/example.com/"),
]);
assert.equal(result, true);
assert.deepEqual(openExternalMock.mock.calls, [["zed://ssh/example.com/home/user/project"]]);
assert.deepEqual(results, [true, true]);
assert.deepEqual(openExternalMock.mock.calls, [
["zed://ssh/example.com/home/user/project"],
["zed://ssh/example.com/"],
]);
}).pipe(Effect.provide(ElectronShell.layer)),
);
+1 -1
View File
@@ -36,7 +36,7 @@ const REMOTE_EDITOR_PROTOCOLS = new Set(
);
// Zed's host sits in the first path segment, so it needs its own userinfo ban.
const ZED_SSH_PATHNAME = /^\/[^/@:]+\/.+$/;
const ZED_SSH_PATHNAME = /^\/[^/@:]+\/.*$/;
const isRemoteEditorUrl = (url: URL) =>
REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&
+9
View File
@@ -151,6 +151,15 @@ describe("buildRemoteOpenUrl", () => {
).toBe("zed://ssh/sol.tail1234.ts.net/home/theo/code/my%20repo");
});
it("drops the Windows drive letter for Zed", () => {
expect(
buildRemoteOpenUrl({ editor: "zed", host: "sol", absolutePath: "C:\\Users\\theo" }),
).toBe("zed://ssh/sol/Users/theo");
expect(buildRemoteOpenUrl({ editor: "zed", host: "sol", absolutePath: "/C:/project" })).toBe(
"zed://ssh/sol/C%3A/project",
);
});
it("returns undefined for editors without remote support", () => {
expect(buildRemoteOpenUrl({ editor: "idea", host: "sol", absolutePath: "/tmp/x" })).toBe(
undefined,
+12 -5
View File
@@ -91,7 +91,7 @@ export type LaunchEditorInput = typeof LaunchEditorInput.Type;
const remoteSchemeOf = (editor: EditorDefinition): string | undefined => editor.remoteScheme;
/** Editors that can open a remote workspace via `vscode-remote` deep links. */
/** Editors that can open a remote workspace via an SSH deep link. */
export const REMOTE_CAPABLE_EDITOR_IDS: ReadonlyArray<EditorId> = EDITORS.flatMap((editor) =>
remoteSchemeOf(editor) !== undefined ? [editor.id] : [],
);
@@ -119,11 +119,18 @@ export const buildRemoteOpenUrl = (input: {
// Windows server paths (`C:\...`) appear as `/C:/...` in vscode-remote URIs.
const posixPath = input.absolutePath.replaceAll("\\", "/");
const rootedPath = posixPath.startsWith("/") ? posixPath : `/${posixPath}`;
const encodedPath = rootedPath.split("/").map(encodeURIComponent).join("/");
const encodedHost = encodeURIComponent(input.host);
return input.editor === "zed"
? `${scheme}://ssh/${encodedHost}${encodedPath}`
: `${scheme}://vscode-remote/ssh-remote+${encodedHost}${encodedPath}`;
if (input.editor === "zed") {
// Zed's remote server resolves a rooted path on the system drive, so a
// Windows `C:\Users\x` must become `/Users/x` (verified in #8938). Other
// drives are untested and kept as is rather than silently remapped, and a
// POSIX path that happens to start with `/C:` is left alone.
const zedPath = /^[Cc]:[\\/]/.test(input.absolutePath) ? rootedPath.slice(3) : rootedPath;
const encodedZedPath = zedPath.split("/").map(encodeURIComponent).join("/");
return `${scheme}://ssh/${encodedHost}${encodedZedPath}`;
}
const encodedPath = rootedPath.split("/").map(encodeURIComponent).join("/");
return `${scheme}://vscode-remote/ssh-remote+${encodedHost}${encodedPath}`;
};
/**