fix(editors): open remote projects in Zed (#11022)

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
mariaandClaude Opus 5 authored and GitHub committed 2026-09-09 23:26:51 -03:00
1 parent d1eeb16247
commit 0f602b3372
4 files changed
+68 -13

No files matched your search

@@ -88,6 +88,33 @@ describe("ElectronShell", () => {
}).pipe(Effect.provide(ElectronShell.layer)),
);
it.effect("opens Zed's ssh deep link", () =>
Effect.gen(function* () {
openExternalMock.mockResolvedValue(undefined);
const electronShell = yield* ElectronShell.ElectronShell;
const result = yield* electronShell.openExternal("zed://ssh/example.com/home/user/project");
assert.equal(result, true);
assert.deepEqual(openExternalMock.mock.calls, [["zed://ssh/example.com/home/user/project"]]);
}).pipe(Effect.provide(ElectronShell.layer)),
);
it.effect("does not open editor URLs that mix up link shapes", () =>
Effect.gen(function* () {
openExternalMock.mockResolvedValue(undefined);
const electronShell = yield* ElectronShell.ElectronShell;
const results = yield* Effect.all([
electronShell.openExternal("zed://extension/attacker"),
electronShell.openExternal("vscode://ssh/example.com/home/user/project"),
]);
assert.deepEqual(results, [false, false]);
assert.equal(openExternalMock.mock.calls.length, 0);
}).pipe(Effect.provide(ElectronShell.layer)),
);
it.effect("does not open remote editor URLs with userinfo", () =>
Effect.gen(function* () {
openExternalMock.mockResolvedValue(undefined);
@@ -100,9 +127,10 @@ describe("ElectronShell", () => {
electronShell.openExternal(
"vscode://:secret@vscode-remote/ssh-remote+example.com/home/user/project",
),
electronShell.openExternal("zed://ssh/[email protected]/home/user/project"),
]);
assert.deepEqual(results, [false, false]);
assert.deepEqual(results, [false, false, false]);
assert.equal(openExternalMock.mock.calls.length, 0);
}).pipe(Effect.provide(ElectronShell.layer)),
);
+11 -5
View File
@@ -24,8 +24,9 @@ const SYSTEM_SETTINGS_URLS: Record<SystemSettingsPane, string> = {
"x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_AllFiles",
};
// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…`)
// must reach the OS handler; every other non-web scheme stays blocked.
// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…`,
// `zed://ssh/<host>/<path>`) must reach the OS handler; every other non-web
// scheme stays blocked.
const SAFE_WEB_PROTOCOLS = new Set(["http:", "https:"]);
const REMOTE_EDITOR_PROTOCOLS = new Set(
REMOTE_CAPABLE_EDITOR_IDS.flatMap((id) => {
@@ -34,13 +35,18 @@ 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 isRemoteEditorUrl = (url: URL) =>
REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&
url.username.length === 0 &&
url.password.length === 0 &&
url.host === "vscode-remote" &&
url.pathname.startsWith("/ssh-remote+") &&
url.pathname.length > "/ssh-remote+".length;
(url.protocol === "zed:"
? url.host === "ssh" && ZED_SSH_PATHNAME.test(url.pathname)
: url.host === "vscode-remote" &&
url.pathname.startsWith("/ssh-remote+") &&
url.pathname.length > "/ssh-remote+".length);
export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
if (typeof rawUrl !== "string") {
+11 -1
View File
@@ -141,8 +141,18 @@ describe("buildRemoteOpenUrl", () => {
).toBe("vscode://vscode-remote/ssh-remote+sol/C%3A/Users/theo");
});
it("builds Zed's ssh deep link", () => {
expect(
buildRemoteOpenUrl({
editor: "zed",
host: "sol.tail1234.ts.net",
absolutePath: "/home/theo/code/my repo",
}),
).toBe("zed://ssh/sol.tail1234.ts.net/home/theo/code/my%20repo");
});
it("returns undefined for editors without remote support", () => {
expect(buildRemoteOpenUrl({ editor: "zed", host: "sol", absolutePath: "/tmp/x" })).toBe(
expect(buildRemoteOpenUrl({ editor: "idea", host: "sol", absolutePath: "/tmp/x" })).toBe(
undefined,
);
});
+17 -6
View File
@@ -13,7 +13,8 @@ type EditorDefinition = {
/**
* URL scheme for editors that support VS Code's remote deep links
* (`<scheme>://vscode-remote/ssh-remote+<host><path>`). Only set for VS Code
* and forks that ship the Remote-SSH machinery.
* and forks that ship the Remote-SSH machinery, plus Zed, which uses its own
* `zed://ssh/<host><path>` shape.
*/
readonly remoteScheme?: string;
};
@@ -49,7 +50,13 @@ export const EDITORS = [
launchStyle: "goto",
remoteScheme: "vscodium",
},
{ id: "zed", label: "Zed", commands: ["zed", "zeditor"], launchStyle: "direct-path" },
{
id: "zed",
label: "Zed",
commands: ["zed", "zeditor"],
launchStyle: "direct-path",
remoteScheme: "zed",
},
{ id: "antigravity", label: "Antigravity", commands: ["agy"], launchStyle: "goto" },
{ id: "idea", label: "IntelliJ IDEA", commands: ["idea"], launchStyle: "line-column" },
{ id: "aqua", label: "Aqua", commands: ["aqua"], launchStyle: "line-column" },
@@ -95,9 +102,10 @@ export const remoteSchemeForEditor = (id: EditorId): string | undefined => {
};
/**
* Builds a `<scheme>://vscode-remote/ssh-remote+<host><path>` deep link that
* opens `absolutePath` on `host` in the local editor over SSH. Returns
* undefined for editors without remote deep-link support.
* Builds a `<scheme>://vscode-remote/ssh-remote+<host><path>` deep link (Zed
* takes `zed://ssh/<host><path>`) that opens `absolutePath` on `host` in the
* local editor over SSH. Returns undefined for editors without remote
* deep-link support.
*/
export const buildRemoteOpenUrl = (input: {
readonly editor: EditorId;
@@ -112,7 +120,10 @@ export const buildRemoteOpenUrl = (input: {
const posixPath = input.absolutePath.replaceAll("\\", "/");
const rootedPath = posixPath.startsWith("/") ? posixPath : `/${posixPath}`;
const encodedPath = rootedPath.split("/").map(encodeURIComponent).join("/");
return `${scheme}://vscode-remote/ssh-remote+${encodeURIComponent(input.host)}${encodedPath}`;
const encodedHost = encodeURIComponent(input.host);
return input.editor === "zed"
? `${scheme}://ssh/${encodedHost}${encodedPath}`
: `${scheme}://vscode-remote/ssh-remote+${encodedHost}${encodedPath}`;
};
/**