TypeScript
fix(editors): accept root paths and Windows servers in Zed remote links (#11044)
maria20ef25037f45
diff --git a/apps/desktop/src/electron/ElectronShell.test.ts b/apps/desktop/src/electron/ElectronShell.test.tsindex 75eea216df2..8ba8082f0e5 100644--- a/apps/desktop/src/electron/ElectronShell.test.ts+++ b/apps/desktop/src/electron/ElectronShell.test.ts@@ -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)),);diff --git a/apps/desktop/src/electron/ElectronShell.ts b/apps/desktop/src/electron/ElectronShell.tsindex 2089be58c0d..aa97c018bd2 100644--- a/apps/desktop/src/electron/ElectronShell.ts+++ b/apps/desktop/src/electron/ElectronShell.ts@@ -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) &&diff --git a/apps/web/src/remoteOpen.test.ts b/apps/web/src/remoteOpen.test.tsindex 6f7c17d8177..0f636a526ce 100644--- a/apps/web/src/remoteOpen.test.ts+++ b/apps/web/src/remoteOpen.test.ts@@ -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,diff --git a/packages/contracts/src/editor.ts b/packages/contracts/src/editor.tsindex 6331a544d34..0680a398879 100644--- a/packages/contracts/src/editor.ts+++ b/packages/contracts/src/editor.ts@@ -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}`;};/**