feat(remote): open WSL projects through a WSL transport (#989)

* perf(vfs): list directories off the main thread and reuse the repository lookup

Opening a folder on a network share (\\wsl.localhost\<distro>\...) is slow
because every listing ran on the main thread and walked up to the repository
root and ran a repository discovery again.

- fs_read_dir runs on the blocking pool.
- GitignoreStack::cached keeps the repository root and the repo-level rules
  for a few seconds. An edit of .git/info/exclude is still seen at once (its
  mtime and size are checked) and every .gitignore / .ignore is read fresh.

Refs #916

* feat(remote): open WSL projects through a WSL transport

A folder of a WSL distro (\\wsl.localhost\<distro>\... or \\wsl$\...) now opens
as a remote project whose openidea-server runs inside the distro, so the
terminal, SDK discovery, run, language servers and git are native Linux.

- RemoteTarget (ssh | wsl) replaces the SSH configuration id in the remote
  launch, connection, session and recents; old recents are read as SSH and a
  WSL target never inherits the legacy trust migration.
- remote_wsl: probe the distro, stream the server into ~/.openidea/server and
  start it with `wsl.exe -d <distro> --exec <bin> --stdio`. Distro names are
  validated and every command goes through --exec with positional arguments.
- wsl_distros / wsl_resolve commands; File > Open, the CLI and recents route
  WSL folders to the distro and focus the window that already has them.
- Remote Development dialog: SSH/WSL choice with the detected distros; the
  status bar shows `WSL: <distro>` / `SSH: <host>`.
- ide-jsonrpc: skip the NUL left at the start of a line by UTF-16 output of
  wsl.exe, which made the first message of the server disappear.

Not run on Windows yet: only a stand-in for wsl.exe is tested.

Refs #925, #327, #721

* fix(remote): satisfy clippy in WSL output decoding

* style(run): format run types

* fix: regenerate bindings and drop untranslated WSL catalog entry

* test(i18n): list WSL as an untranslated product name

* fix(run): pick build wrappers and shell quoting by the execution host

A remote window runs commands on its Linux or macOS server, so a Windows
desktop no longer selects gradlew.bat, mvnw.cmd or Windows quoting for it.

* fix(welcome): open legacy WSL UNC recents and sessions through the distro

Recents and the restored session called the local openProject for a
\\wsl.localhost folder saved before WSL projects, which fails with OS
error 123. They now resolve it like the other entry points.

* fix(windows): keep WSL files out of remote project launches

path_launch tested the WSL share before is_dir, so a first-instance CLI
launch with a WSL file opened a remote project instead of LightEdit.

* fix(remote): run-command OS comes from the remote host, not an assumption

The server's OS was dropped after connect, so a restored session had none and
isWindows() assumed every remote host is Unix. Keep it on the connection and
the session, and resolve it through hostOs().

---------

Co-authored-by: NguyenBang <[email protected]>
Co-authored-by: NguyenBang <[email protected]>
Co-authored-by: l0ng-ai <[email protected]>
Цей коміт міститься в:
authored and GitHub committed 2026-11-05 15:37:19 +08:00
1 джерело 9bf28dd451
коміт b0f65769c0
47 files changed
+1512 -220

No files matched your search

+19 -2
Переглянути файл
@@ -6,11 +6,13 @@ const projectCurrent = vi.fn();
const windowOpenProject = vi.fn();
const windowOpenFiles = vi.fn();
const windowTakeLaunch = vi.fn();
const wslResolve = vi.fn();
const cancelClose = vi.fn();
const notify = vi.fn();
vi.mock("@/platform/remote", async (original) => ({
...(await original<typeof import("@/platform/remote")>()),
isRemoteWindow: vi.fn(() => false),
connectRemote: vi.fn(async () => {}),
}));
// The backend answers with the global settings, here: whatever the test set up.
const lightEditOpen = vi.fn(async (_path: string) => ({ status: "ok", data: useProject.getState().settings ?? {} }));
@@ -34,6 +36,7 @@ vi.mock("@/platform/ipc", async (orig) => {
windowOpenProject: (...a: unknown[]) => windowOpenProject(...a),
windowOpenFiles: (...a: unknown[]) => windowOpenFiles(...a),
windowTakeLaunch: () => windowTakeLaunch(),
wslResolve: (p: string) => wslResolve(p),
lightEditOpen: (p: string) => lightEditOpen(p),
fsReadDir: (p: string) => fsReadDir(p),
},
@@ -55,7 +58,7 @@ const {
} = await import("../windows");
const { useProject } = await import("@/platform/project");
const { provideEditorService, provideNotificationService } = await import("@/workbench/contributions");
const { isRemoteWindow } = await import("@/platform/remote");
const { isRemoteWindow, connectRemote } = await import("@/platform/remote");
const { IpcError } = await import("@/platform/ipc");
provideNotificationService({ notify });
@@ -77,7 +80,9 @@ const ok = (data: unknown) => ({ status: "ok", data });
const projectState = (root: string) => ({ project: { root, name: root, trusted: true, isGit: false, settings: {} } });
beforeEach(() => {
for (const f of [windowOpenProject, windowOpenFiles, windowTakeLaunch]) f.mockReset();
for (const f of [windowOpenProject, windowOpenFiles, windowTakeLaunch, wslResolve]) f.mockReset();
wslResolve.mockResolvedValue(null);
vi.mocked(connectRemote).mockClear();
for (const f of [lightEditOpen, fsReadDir, openProject]) f.mockClear();
cancelClose.mockClear();
notify.mockClear();
@@ -95,6 +100,18 @@ describe("openProjectInWindow", () => {
expect(openProject).toHaveBeenCalledWith("/p/a");
});
it("connects to the distribution when the folder is on the WSL share", async () => {
const [distro, linuxPath] = ["Debian", "/srv/app"];
const share = `\\\\wsl.localhost\\${distro}${linuxPath.replaceAll("/", "\\")}`;
const target = { kind: "wsl", distro };
wslResolve.mockResolvedValue({ target, path: linuxPath });
windowOpenProject.mockResolvedValue(ok({ kind: "current" }));
await openProjectInWindow(share, false);
expect(wslResolve).toHaveBeenCalledWith(share);
expect(connectRemote).toHaveBeenCalledWith(target, linuxPath);
expect(openProject).not.toHaveBeenCalled();
});
it("asks for a new window when this one already has a project", async () => {
useProject.setState(projectState("/p/b") as never);
windowOpenProject.mockResolvedValue(ok({ kind: "opened", label: "project-1" }));
+6 -3
Переглянути файл
@@ -53,7 +53,10 @@ async function openHere(path: string): Promise<boolean> {
if (!isRemoteWindow() && useProject.getState().project?.root === path) return true;
if (!(await confirmLeaveProject())) return false;
try {
await openProject(path);
// A folder of a WSL distro runs there, not as a network folder.
const wsl = await commands.wslResolve(path).catch(() => null);
if (wsl) await connectRemote(wsl.target, wsl.path);
else await openProject(path);
return true;
} catch (e) {
maybeEditorService()?.cancelClose?.();
@@ -219,8 +222,8 @@ export async function consumeLaunch(): Promise<void> {
if (await openHere(launch.project)) await openInEditor(files, positions);
} else if (files.length) await openFilesHere(files, positions);
else if (launch?.remote) {
const { sshConfig, path } = launch.remote;
await connectRemote(sshConfig, path).catch((e) =>
const { target, path } = launch.remote;
await connectRemote(target, path).catch((e) =>
notifications().notify({
level: "error",
title: t("app.window.openFailed", { name: basename(path) }),
+7 -1
Переглянути файл
@@ -13,7 +13,13 @@ vi.mock("@/platform/tauriCore", async (original) => ({
beforeEach(() => {
useTasks.setState({ tasks: [] });
useRemote.setState({
session: { sshConfig: "s", root: "/remote", host: "host", commands: ["fs_copy", "cancel_request"] },
session: {
target: { kind: "ssh", config: "s" },
root: "/remote",
host: "host",
os: "linux",
commands: ["fs_copy", "cancel_request"],
},
});
});
afterEach(() => {
+44 -4
Переглянути файл
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { MEMBER_PREFIX, type ProjectNode } from "./model";
import {
canPaste,
checkEditingName,
copySelection,
importExternal,
paste,
@@ -13,6 +14,7 @@ import {
import { IpcError } from "@/platform/ipc";
import { closeFileRefactorDialog, pendingFileRefactorDialog } from "./FileRefactorDialogs";
import { useRemote } from "@/platform/remote";
import { usePlatform } from "@/platform/platformInfo";
import { provideNotificationService } from "@/workbench/contributions";
import { MemoryFs, setProjectFsForTests } from "./fs";
import { initProjectTree, loadDir, setClipboard, setSelection, useProjectTree } from "./store";
@@ -21,6 +23,30 @@ import { setOsClipboardForTests } from "./clipboard";
let fs: MemoryFs;
const notify = vi.fn();
describe("file names follow the execution host", () => {
const platform = usePlatform.getState();
afterEach(() => {
usePlatform.setState(platform);
useRemote.setState({ session: null });
setProjectFsForTests(null);
initProjectTree(null);
});
it.each(["linux", "windows", "macos"])("validates names on a %s host from a Windows desktop", async (os) => {
usePlatform.setState({ os: "windows" });
useRemote.setState({
session: { target: { kind: "ssh", config: "host" }, root: "/p", host: "host", os, commands: [] },
});
fs = new MemoryFs({ "/p/readme.txt": "" }, "/p");
setProjectFsForTests(fs, "/p");
initProjectTree("/p", "p");
await loadDir("/p");
useProjectTree.setState({ editing: { kind: "new", parent: "/p", nodeKind: "file" } });
expect(checkEditingName("con").error !== null).toBe(os === "windows");
expect(checkEditingName("README.txt").error !== null).toBe(os !== "linux");
});
});
const node = (path: string, dir = false): ProjectNode => ({
key: path,
path,
@@ -102,7 +128,9 @@ describe("OS file imports", () => {
setProjectFsForTests(fs, "/p");
initProjectTree("/p", "p");
await loadDir("/p");
useRemote.setState({ session: { sshConfig: "ssh", root: "/p", host: "host", commands: ["fs_copy"] } });
useRemote.setState({
session: { target: { kind: "ssh", config: "ssh" }, root: "/p", host: "host", os: "linux", commands: ["fs_copy"] },
});
provideNotificationService({ notify });
notify.mockClear();
});
@@ -292,7 +320,15 @@ describe("project clipboard ownership", () => {
it.each(remoteCases)(
"remote hand-off=$handedOff OS=$osList cut=$cut on $entry",
async ({ handedOff, osList, cut, entry }) => {
useRemote.setState({ session: { sshConfig: "ssh", root: "/p", host: "host", commands: ["fs_copy"] } });
useRemote.setState({
session: {
target: { kind: "ssh", config: "ssh" },
root: "/p",
host: "host",
os: "linux",
commands: ["fs_copy"],
},
});
const writeText = vi.fn(async () => {
if (!handedOff) throw new Error("unavailable");
});
@@ -338,7 +374,9 @@ describe("project clipboard ownership", () => {
);
it("writes multiple remote paths as newline-joined text", async () => {
useRemote.setState({ session: { sshConfig: "ssh", root: "/p", host: "host", commands: ["fs_copy"] } });
useRemote.setState({
session: { target: { kind: "ssh", config: "ssh" }, root: "/p", host: "host", os: "linux", commands: ["fs_copy"] },
});
await fs.createFile("/p/second.txt");
await loadDir("/p", true);
setSelection(new Set(["/p/source.txt", "/p/second.txt"]), "/p/source.txt");
@@ -350,7 +388,9 @@ describe("project clipboard ownership", () => {
});
it("waits for a pending remote text write before reading file URLs", async () => {
useRemote.setState({ session: { sshConfig: "ssh", root: "/p", host: "host", commands: ["fs_copy"] } });
useRemote.setState({
session: { target: { kind: "ssh", config: "ssh" }, root: "/p", host: "host", os: "linux", commands: ["fs_copy"] },
});
let finish!: () => void;
vi.stubGlobal("navigator", {
clipboard: {
+9 -6
Переглянути файл
@@ -39,17 +39,14 @@ import {
useProjectTree,
} from "./store";
import { tx } from "@/platform/i18n";
import { isRemoteWindow } from "@/platform/remote";
import { hostOs, isRemoteWindow } from "@/platform/remote";
import { usePlatform } from "@/platform/platformInfo";
/** Nodes that may be renamed, moved or deleted (not roots, groups or library sources). */
const mutable = (n: ProjectNode) => !n.root && !n.placeholder && !n.readOnly;
const get = () => useProjectTree.getState();
const ua = typeof navigator !== "undefined" ? navigator.userAgent : "";
const isWindows = /Win/i.test(ua);
/** macOS and Windows file systems are case-insensitive by default. */
const caseInsensitive = /Mac|Win/i.test(ua);
const caseInsensitiveOs = (os: string) => os === "windows" || os === "macos";
function errorMessage(e: unknown): string {
return e instanceof Error ? e.message : String(e);
@@ -236,6 +233,9 @@ export function cancelEditing() {
export function checkEditingName(name: string) {
const { editing } = get();
if (!editing) return { error: null };
const os = hostOs();
const isWindows = os === "windows";
const caseInsensitive = caseInsensitiveOs(os);
if (editing.kind === "new" && editing.pkg) {
const { segments, error } = packageSegments(name, editing.pkg);
if (!segments) return { error };
@@ -645,6 +645,7 @@ async function pasteFromOsClipboard(paths: string[], target: string) {
/** The same files, as the clipboard keeps them (`/`-separated, any order). */
function sameFiles(files: string[], paths: string[] | undefined): boolean {
if (!paths || files.length !== paths.length) return false;
const caseInsensitive = caseInsensitiveOs(usePlatform.getState().os);
const key = (list: string[]) =>
list
.map((p) => (caseInsensitive ? p.toLowerCase() : p))
@@ -687,6 +688,7 @@ export async function transfer(
if (!root) return false;
const fs = projectFs(root);
await loadDir(target);
const caseInsensitive = caseInsensitiveOs(hostOs());
const taken = new Set(siblingsOf(target).map((n) => (caseInsensitive ? n.toLowerCase() : n)));
const hasName = (n: string) => taken.has(caseInsensitive ? n.toLowerCase() : n);
const isTaken = (n: string) => hasName(n) || (isUnityAssetFolder(target) && hasName(`${n}.meta`));
@@ -744,6 +746,7 @@ export async function transfer(
async function moveInto(paths: string[], target: string): Promise<boolean> {
paths = assetPaths(paths);
await loadDir(target);
const caseInsensitive = caseInsensitiveOs(hostOs());
const taken = new Set(siblingsOf(target).map((n) => (caseInsensitive ? n.toLowerCase() : n)));
const errors: string[] = [];
const moves: { from: string; to: string }[] = [];
+31 -3
Переглянути файл
@@ -6,8 +6,9 @@ import { useRemoteProgress } from "@/platform/remote";
import { ConnectHost } from "./ConnectDialog";
import { closeConnectDialog, openConnectDialog, useConnectDialog } from "./model";
const { list, globalSettings, openRemote, executeAction } = vi.hoisted(() => ({
const { list, distros, globalSettings, openRemote, executeAction } = vi.hoisted(() => ({
list: vi.fn(),
distros: vi.fn(),
globalSettings: vi.fn(),
openRemote: vi.fn(),
executeAction: vi.fn(),
@@ -15,7 +16,10 @@ const { list, globalSettings, openRemote, executeAction } = vi.hoisted(() => ({
vi.mock("@/platform/ipc", async (importOriginal) => {
const real = await importOriginal<typeof import("@/platform/ipc")>();
return { ...real, commands: { ...real.commands, remoteBootstrapList: list, settingsGetGlobal: globalSettings } };
return {
...real,
commands: { ...real.commands, remoteBootstrapList: list, wslDistros: distros, settingsGetGlobal: globalSettings },
};
});
vi.mock("@/workbench/projectWindow", () => ({ openRemoteProject: openRemote }));
vi.mock("@/platform/actions", async (importOriginal) => ({
@@ -35,6 +39,7 @@ const entry = (path: string, isDir = true): RemoteEntry => ({
beforeEach(() => {
vi.resetAllMocks();
distros.mockResolvedValue({ status: "ok", data: [] });
// A remote project's window: its settings are the remote host's, without this machine's SSH configurations.
useProject.setState({ project: null, opening: false, settings: { ssh: { configs: [] } } as unknown as Settings });
globalSettings.mockResolvedValue({
@@ -87,7 +92,9 @@ it("browses the selected SSH host, navigates folders and opens one without a cur
await waitFor(() => expect(screen.getByLabelText("Project directory:")).toHaveValue("/home/dev/projects"));
expect(within(folders).getAllByRole("button")).toHaveLength(1);
fireEvent.click(screen.getByRole("button", { name: "Open" }));
await waitFor(() => expect(openRemote).toHaveBeenCalledWith("selected", "/home/dev/projects"));
await waitFor(() =>
expect(openRemote).toHaveBeenCalledWith({ kind: "ssh", config: "selected" }, "/home/dev/projects"),
);
expect(useConnectDialog.getState().open).toBe(false);
expect(useProject.getState().project).toBeNull();
});
@@ -125,3 +132,24 @@ it("offers SSH configuration and disables Browse until one exists, then lists th
await waitFor(() => expect(screen.getByRole("button", { name: "Browse" })).toBeEnabled());
expect(screen.getByRole("button", { name: "SSH configuration" })).toHaveTextContent("dev");
});
it("hides the WSL choice when no distribution is installed", async () => {
render(<ConnectHost />);
await waitFor(() => expect(distros).toHaveBeenCalled());
expect(screen.queryByRole("button", { name: "Connect through" })).toBeNull();
});
it("opens a folder of the chosen WSL distribution, without browsing over SFTP", async () => {
const installed = ["Ubuntu-24.04", "Debian"];
distros.mockResolvedValue({ status: "ok", data: installed });
openRemote.mockResolvedValue(true);
render(<ConnectHost />);
fireEvent.click(await screen.findByRole("button", { name: "Connect through" }));
fireEvent.click(screen.getByRole("option", { name: "WSL" }));
expect(screen.queryByRole("button", { name: "Browse" })).toBeNull();
fireEvent.click(screen.getByRole("button", { name: "WSL distribution" }));
fireEvent.click(screen.getByRole("option", { name: installed[1] }));
fireEvent.click(screen.getByRole("button", { name: "Open" }));
await waitFor(() => expect(openRemote).toHaveBeenCalledWith({ kind: "wsl", distro: installed[1] }, "~"));
expect(list).not.toHaveBeenCalled();
});
+78 -22
Переглянути файл
@@ -2,7 +2,7 @@
import { useEffect, useState } from "react";
import { executeAction } from "@/platform/actions";
import { useTx } from "@/platform/i18n";
import { call, commands, isCancelled, onIdeEvent, type RemoteEntry } from "@/platform/ipc";
import { call, commands, isCancelled, onIdeEvent, type RemoteEntry, type RemoteTarget } from "@/platform/ipc";
import { useRemoteProgress } from "@/platform/remote";
import { sshLabel, type SshConfigValid, validateRemote } from "@/platform/remoteSettings";
import { Button, Dialog, Icon, Input, ProgressBar, Select, Spinner } from "@/ui";
@@ -52,11 +52,34 @@ function ConnectDialog() {
const configs = useLocalSshConfigs();
const [picked, setSsh] = useState("");
const ssh = configs.some((c) => c.id === picked) ? picked : (configs[0]?.id ?? "");
const [kind, setKind] = useState<RemoteTarget["kind"]>("ssh");
// Installed WSL distributions; none (or no WSL at all) hides the WSL choice.
const [distros, setDistros] = useState<string[]>([]);
const [distro, setDistro] = useState("");
const [path, setPath] = useState("~");
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [browse, setBrowse] = useState<{ dir: string; folders: RemoteEntry[] } | null>(null);
useEffect(() => {
let live = true;
// Detection is a convenience: any failure just leaves SSH as the only choice.
void call(commands.wslDistros())
.then((found) => {
if (!live) return;
setDistros(found);
setDistro((d) => d || (found[0] ?? ""));
})
.catch(() => {});
return () => {
live = false;
};
}, []);
const wsl = kind === "wsl";
const name = wsl ? distro : ssh;
const target: RemoteTarget = wsl ? { kind: "wsl", distro } : { kind: "ssh", config: ssh };
const list = async (dir: string) => {
setError(null);
setBusy(true);
@@ -76,8 +99,7 @@ function ConnectDialog() {
setError(null);
setBusy(true);
try {
const target = path.trim() || "~";
if (await openRemoteProject(ssh, target)) closeConnectDialog();
if (await openRemoteProject(target, path.trim() || "~")) closeConnectDialog();
else setBusy(false);
} catch (e) {
if (!isCancelled(e)) setError(e instanceof Error ? e.message : String(e));
@@ -86,7 +108,7 @@ function ConnectDialog() {
};
const options = configs.map((c) => ({ value: c.id, label: c.name.trim() || sshLabel(c), detail: sshLabel(c) }));
const ready = !!ssh && !busy && !!path.trim();
const ready = !!name && !busy && !!path.trim();
const connecting = useRemoteProgress((s) => s.progress !== null);
return (
@@ -115,21 +137,52 @@ function ConnectDialog() {
<p className={styles.hint}>
{tx("The project runs on the remote host; the IDE backend is installed there on first use.")}
</p>
<label className={styles.label}>{tx("SSH configuration:")}</label>
<div className={styles.row}>
<Select
className={styles.grow}
value={ssh || null}
options={options}
placeholder={tx("No SSH configurations")}
onChange={(id) => {
setSsh(id);
setBrowse(null);
}}
aria-label={tx("SSH configuration")}
/>
<Button onClick={() => void executeAction("file.settings", SSH_SETTINGS_PAGE)}>{tx("Configure…")}</Button>
</div>
{distros.length > 0 && (
<>
<label className={styles.label}>{tx("Connect through:")}</label>
<Select
value={kind}
options={[
{ value: "ssh", label: "SSH" },
{ value: "wsl", label: "WSL" },
]}
onChange={(k) => {
setKind(k as RemoteTarget["kind"]);
setBrowse(null);
}}
aria-label={tx("Connect through")}
/>
</>
)}
{wsl ? (
<>
<label className={styles.label}>{tx("WSL distribution:")}</label>
<Select
value={distro || null}
options={distros.map((d) => ({ value: d, label: d }))}
onChange={setDistro}
aria-label={tx("WSL distribution")}
/>
</>
) : (
<>
<label className={styles.label}>{tx("SSH configuration:")}</label>
<div className={styles.row}>
<Select
className={styles.grow}
value={ssh || null}
options={options}
placeholder={tx("No SSH configurations")}
onChange={(id) => {
setSsh(id);
setBrowse(null);
}}
aria-label={tx("SSH configuration")}
/>
<Button onClick={() => void executeAction("file.settings", SSH_SETTINGS_PAGE)}>{tx("Configure…")}</Button>
</div>
</>
)}
<label className={styles.label} htmlFor="remote-dev-path">
{tx("Project directory:")}
</label>
@@ -142,9 +195,12 @@ function ConnectDialog() {
spellCheck={false}
onChange={(e) => setPath(e.target.value)}
/>
<Button disabled={!ssh || busy} onClick={() => void list(path.trim() || "~")}>
{tx("Browse")}
</Button>
{/* Browsing lists over SFTP; a WSL distribution has no such session before connecting. */}
{!wsl && (
<Button disabled={!ssh || busy} onClick={() => void list(path.trim() || "~")}>
{tx("Browse")}
</Button>
)}
</div>
{browse && (
<ul className={styles.folders} aria-label={tx("Remote folders")}>
+25
Переглянути файл
@@ -0,0 +1,25 @@
import { executeAction } from "@/platform/actions";
import { tx } from "@/platform/i18n";
import type { RemoteSession } from "@/platform/ipc";
import { useRemote } from "@/platform/remote";
import { BarButton } from "@/ui";
/** Status bar label of a remote window: where its project runs. */
export function remoteBadge(session: Pick<RemoteSession, "target" | "host">): string {
return `${session.target.kind === "wsl" ? "WSL" : "SSH"}: ${session.host}`;
}
export function RemoteStatus() {
const session = useRemote((s) => s.session);
if (!session) return null;
const label = remoteBadge(session);
return (
<BarButton
tooltip={tx`Project runs on ${label}`}
aria-label={label}
onClick={() => void executeAction("remote.connect")}
>
{label}
</BarButton>
);
}
+13 -5
Переглянути файл
@@ -1,19 +1,20 @@
/**
* Remote development: a window whose project lives on an SSH host. The backend
* Remote development: a window whose project lives on an SSH host or in a WSL distribution. The backend
* (`openidea-server`) runs there and this window routes its commands to it
* (platform/remote.ts).
*/
import { registerActions } from "@/platform/actions";
import { disconnectRemote, useRemote } from "@/platform/remote";
import { lazyComponent } from "@/ui";
import { maybeEditorService, registerOverlay, registerToolWindow } from "@/workbench/contributions";
import { maybeEditorService, registerOverlay, registerStatusItem, registerToolWindow } from "@/workbench/contributions";
import { confirmLeaveProject } from "@/platform/project";
import { ConnectHost } from "./ConnectDialog";
import { reloadEnvironment } from "./environment";
import { RemoteStatus } from "./RemoteStatus";
import { closeConnectDialog, openConnectDialog } from "./model";
import { restorePorts, usePorts } from "./ports";
/** The Ports tool window, while this window is connected to a remote host. */
/** SSH tunnels are available while this window is connected to an SSH host. */
function trackPortsWindow(): () => void {
let off: (() => void) | null = null;
const sync = (connected: boolean) => {
@@ -34,8 +35,8 @@ function trackPortsWindow(): () => void {
usePorts.setState({ ports: [] });
}
};
sync(useRemote.getState().session !== null);
const unsubscribe = useRemote.subscribe((s) => sync(s.session !== null));
sync(useRemote.getState().session?.target.kind === "ssh");
const unsubscribe = useRemote.subscribe((s) => sync(s.session?.target.kind === "ssh"));
return () => {
unsubscribe();
off?.();
@@ -46,6 +47,13 @@ export function activate(): () => void {
const disposers = [
trackPortsWindow(),
registerOverlay({ id: "remote.connect", component: ConnectHost }),
registerStatusItem({
id: "remote.location",
title: "Remote Host",
align: "left",
priority: 100,
component: RemoteStatus,
}),
registerActions([
{
id: "remote.connect",
+10 -2
Переглянути файл
@@ -63,7 +63,9 @@ describe("restoring forwarded ports", () => {
it("forwards the ports of this host and folder again after reconnecting", async () => {
const { useRemote } = await import("@/platform/remote");
const { forwardPort, restorePorts, savedPorts } = await import("./ports");
useRemote.setState({ session: { sshConfig: "lh", root: "/srv/app", host: "h", commands: [] } });
useRemote.setState({
session: { target: { kind: "ssh", config: "lh" }, root: "/srv/app", host: "h", os: "linux", commands: [] },
});
await forwardPort(8080);
expect(savedPorts()).toEqual([8080]);
// Reconnected: the new connection forwards nothing yet.
@@ -73,7 +75,13 @@ describe("restoring forwarded ports", () => {
expect(ipc.remoteForwardPort).toHaveBeenCalledWith(8080);
expect(usePorts.getState().ports).toEqual([{ remotePort: 8080, localPort: 8080 }]);
// Another folder on the same host has its own list.
useRemote.setState({ session: { sshConfig: "lh", root: "/srv/other", host: "h", commands: [] } });
useRemote.setState({
session: { target: { kind: "ssh", config: "lh" }, root: "/srv/other", host: "h", os: "linux", commands: [] },
});
expect(savedPorts()).toEqual([]);
useRemote.setState({
session: { target: { kind: "wsl", distro: "lh" }, root: "/srv/app", host: "lh", os: "linux", commands: [] },
});
expect(savedPorts()).toEqual([]);
useRemote.setState({ session: null });
});
+9 -1
Переглянути файл
@@ -10,7 +10,7 @@ const SAVED_KEY = "openidea.remote.ports:";
function savedKey(): string | null {
const session = useRemote.getState().session;
return session ? `${SAVED_KEY}${session.sshConfig}:${session.root}` : null;
return session?.target.kind === "ssh" ? `${SAVED_KEY}${session.target.config}:${session.root}` : null;
}
export function savedPorts(): number[] {
@@ -53,6 +53,14 @@ export function parsePort(text: string): number | null {
}
export async function forwardPort(port: number): Promise<ForwardedPort | null> {
if (useRemote.getState().session?.target.kind === "wsl") {
notifications().notify({
group: "remote",
level: "error",
title: tx("Forwarding ports is not supported in a WSL project yet"),
});
return null;
}
try {
const forwarded = await call(commands.remoteForwardPort(port));
await refreshPorts(true);
+59 -12
Переглянути файл
@@ -10,6 +10,7 @@ import {
remoteLocation,
} from "@/platform/remote";
import { browsableFolders, listedDirectory, remoteParent } from "./model";
import { remoteBadge } from "./RemoteStatus";
const entry = (path: string, isDir = true): RemoteEntry => ({
name: path.slice(path.lastIndexOf("/") + 1),
@@ -47,33 +48,79 @@ describe("remote folder browser", () => {
});
});
const ssh = (config: string) => ({ kind: "ssh", config }) as const;
const wsl = (distro: string) => ({ kind: "wsl", distro }) as const;
describe("remote project locations", () => {
it("round-trip the configuration id and the path", () => {
const loc = remoteLocation("mac mini/1", "/Users/me/repo");
const loc = remoteLocation(ssh("mac mini/1"), "/Users/me/repo");
expect(loc).toBe("ssh://mac%20mini%2F1/Users/me/repo");
expect(parseRemoteLocation(loc)).toEqual({ sshConfig: "mac mini/1", path: "/Users/me/repo" });
expect(parseRemoteLocation(loc)).toEqual({ target: ssh("mac mini/1"), path: "/Users/me/repo" });
expect(parseRemoteLocation("/Users/me/repo")).toBeNull();
});
it("round-trip a WSL distribution and the path", () => {
const loc = remoteLocation(wsl("Ubuntu-24.04"), "/home/me/app");
expect(loc).toBe("wsl://Ubuntu-24.04/home/me/app");
expect(parseRemoteLocation(loc)).toEqual({ target: wsl("Ubuntu-24.04"), path: "/home/me/app" });
expect(parseRemoteLocation("wsl://Ubuntu")).toBeNull();
});
it("remembers recent remote projects most recent first, once each", () => {
localStorage.clear();
rememberRemote({ sshConfig: "a", path: "/p", name: "p", host: "me@a", openedAtMs: 1 });
rememberRemote({ sshConfig: "b", path: "/q", name: "q", host: "me@b", openedAtMs: 2 });
rememberRemote({ sshConfig: "a", path: "/p", name: "p", host: "me@a", openedAtMs: 3 });
rememberRemote({ target: ssh("a"), path: "/p", name: "p", host: "me@a", openedAtMs: 1 });
rememberRemote({ target: ssh("b"), path: "/q", name: "q", host: "me@b", openedAtMs: 2 });
rememberRemote({ target: ssh("a"), path: "/p", name: "p", host: "me@a", openedAtMs: 3 });
expect(recentRemotes().map((r) => r.path)).toEqual(["/p", "/q"]);
forgetRemote("a", "/p");
forgetRemote(ssh("a"), "/p");
expect(recentRemotes().map((r) => r.path)).toEqual(["/q"]);
});
it("keeps an SSH host and a WSL distribution of the same name apart", () => {
localStorage.clear();
rememberRemote({ target: ssh("dev"), path: "/p", name: "p", host: "me@dev", openedAtMs: 1 });
rememberRemote({ target: wsl("dev"), path: "/p", name: "p", host: "dev", openedAtMs: 2 });
expect(recentRemotes()).toHaveLength(2);
forgetRemote(wsl("dev"), "/p");
expect(recentRemotes().map((r) => r.target)).toEqual([ssh("dev")]);
});
it("reads recents saved before WSL support, which carried `sshConfig`", () => {
localStorage.clear();
localStorage.setItem(
"openidea.remote.recent",
JSON.stringify([
{ sshConfig: "old", path: "/p", name: "p", host: "me@old", openedAtMs: 1 },
{ path: "/no-target" },
]),
);
expect(recentRemotes().map((r) => r.target)).toEqual([ssh("old")]);
});
});
it("migrates only the original remote recents once, scoped to the saved host", () => {
localStorage.clear();
rememberRemote({ sshConfig: "a", path: "/old", host: "me@old", name: "old", openedAtMs: 1 });
rememberRemote({ target: ssh("a"), path: "/old", host: "me@old", name: "old", openedAtMs: 1 });
initializeRemoteTrustMigration();
rememberRemote({ sshConfig: "a", path: "/new", host: "me@old", name: "new", openedAtMs: 2 });
rememberRemote({ target: ssh("a"), path: "/new", host: "me@old", name: "new", openedAtMs: 2 });
initializeRemoteTrustMigration();
expect(takeLegacyRemoteTrust("a", "/new", "me@old")).toBe(false);
expect(takeLegacyRemoteTrust("a", "/old", "me@other")).toBe(false);
expect(takeLegacyRemoteTrust("a", "/old", "me@old")).toBe(true);
expect(takeLegacyRemoteTrust("a", "/old", "me@old")).toBe(false);
expect(takeLegacyRemoteTrust(ssh("a"), "/new", "me@old")).toBe(false);
expect(takeLegacyRemoteTrust(ssh("a"), "/old", "me@other")).toBe(false);
expect(takeLegacyRemoteTrust(ssh("a"), "/old", "me@old")).toBe(true);
expect(takeLegacyRemoteTrust(ssh("a"), "/old", "me@old")).toBe(false);
});
it("migrates a snapshot taken before WSL support, and never trusts a WSL distribution", () => {
localStorage.clear();
localStorage.setItem(
"openidea.remote.trustMigration",
JSON.stringify([{ sshConfig: "a", path: "/old", host: "me@old", name: "old", openedAtMs: 1 }]),
);
expect(takeLegacyRemoteTrust(wsl("a"), "/old", "me@old")).toBe(false);
expect(takeLegacyRemoteTrust(ssh("a"), "/old", "me@old")).toBe(true);
});
it("labels the status bar with the transport and where the project runs", () => {
expect(remoteBadge({ target: wsl("Ubuntu"), host: "Ubuntu" })).toBe("WSL: Ubuntu");
expect(remoteBadge({ target: ssh("a"), host: "me@a:22" })).toBe("SSH: me@a:22");
});
+32
Переглянути файл
@@ -16,6 +16,7 @@ vi.mock("@/platform/ipc", async (orig) => {
};
});
const { usePlatform } = await import("@/platform/platformInfo");
const { parseJavaArgs, joinJavaArgs } = await import("@/platform/javaLaunch");
const { parseArgs } = await import("./configs");
const { jdwpLaunch } = await import("./javaDebug");
@@ -247,3 +248,34 @@ describe("Maven / Gradle: VM options of the forked JVM", () => {
await expect(gradle().prepareLaunch!(remote)).rejects.toThrow(/run targets/);
});
});
describe("build wrapper per execution host", () => {
const wrapperCommands = () =>
(["gradle", "maven"] as const).map((t) => typeFor(t)!.commandLine({ wrapper: "true", tasks: "test" })!.command);
const WINDOWS = ["gradlew.bat", "mvnw.cmd"];
const UNIX = ["./gradlew", "./mvnw"];
beforeEach(() => registerBuiltinTypes());
afterEach(async () => {
(await import("@/platform/remote")).disableRemote();
usePlatform.setState({ os: "macos" });
});
it("follows the desktop OS in a local window", () => {
usePlatform.setState({ os: "windows" });
expect(wrapperCommands()).toEqual(WINDOWS);
usePlatform.setState({ os: "linux" });
expect(wrapperCommands()).toEqual(UNIX);
});
it.each([
{ desktop: "windows", host: "linux", target: { kind: "wsl", distro: "Ubuntu" }, expected: UNIX },
{ desktop: "windows", host: "macos", target: { kind: "ssh", config: "box" }, expected: UNIX },
{ desktop: "macos", host: "windows", target: { kind: "ssh", config: "win" }, expected: WINDOWS },
] as const)("follows the $host server of a remote window opened from $desktop", async (c) => {
usePlatform.setState({ os: c.desktop });
const { enableRemote } = await import("@/platform/remote");
enableRemote({ target: c.target, root: "/app", host: "h", os: c.host, commands: [] });
expect(wrapperCommands()).toEqual(c.expected);
});
});
+3 -1
Переглянути файл
@@ -6,6 +6,7 @@
*/
import { call, commands, type RunConfig } from "@/platform/ipc";
import { CLASSPATH, parseJavaArgs, TEST_CLASSPATH } from "@/platform/javaLaunch";
import { hostOs } from "@/platform/remote";
import { basename, useProject } from "@/platform/project";
import { useBuildPresentation } from "@/platform/projectPresentation";
import type { RunConfigTypeContribution, RunConfigTypeField } from "@/workbench/contributions";
@@ -13,7 +14,8 @@ import { formatArgs, parseArgs } from "./configs";
import { commandName } from "./commandName";
import { updatePolicyDefaults, updatePolicyFields } from "./updatePolicies";
export const isWindows = () => typeof navigator !== "undefined" && /win/i.test(navigator.platform);
/** Whether this window's commands run on Windows: the remote server's OS in a remote window, else the desktop's. */
export const isWindows = () => hostOs() === "windows";
/** VM options / program arguments as typed; on Windows a backslash is a path separator. */
export const splitJvmArgs = (text: string | undefined, windows = isWindows()) => parseArgs(text ?? "", windows);
+2 -2
Переглянути файл
@@ -5,6 +5,7 @@
* Rust come from SDK discovery and everything else resolves at launch.
*/
import { call, commands, isTauri } from "@/platform/ipc";
import { isWindows } from "./jvmTypes";
import type { LocatedTool, ToolEnv } from "./producers";
const TTL = 60_000;
@@ -15,7 +16,6 @@ interface Entry {
}
const cache = new Map<string, Entry>();
const isWindows = typeof navigator !== "undefined" && /Win/i.test(navigator.platform || navigator.userAgent);
let compileDir: string | null = null;
let locateUnavailable = false;
@@ -115,7 +115,7 @@ export async function toolEnv(
return {
tool: (n) => tools.get(n),
compileDir: compileDir ?? "/tmp/openidea-run",
windows: isWindows,
windows: isWindows(),
python: py,
...markers,
};
+11 -1
Переглянути файл
@@ -138,7 +138,17 @@ describe("service reordering integration", () => {
render(<ServicesTreeView />);
select("Portal");
fireEvent.click(screen.getByRole("button", { name: "Move Up" }));
act(() => useRemote.setState({ session: { root: "/services", sshConfig: "host", host: "host", commands: [] } }));
act(() =>
useRemote.setState({
session: {
root: "/services",
target: { kind: "ssh", config: "host" },
host: "host",
os: "linux",
commands: [],
},
}),
);
expect(names()).toEqual(["Spring Boot", "Gateway", "Portal", "npm", "Web", "Worker", "Docker"]);
act(() => useRemote.setState({ session: null }));
expect(names()).toEqual(["Spring Boot", "Portal", "Gateway", "npm", "Web", "Worker", "Docker"]);
+2 -1
Переглянути файл
@@ -9,6 +9,7 @@
import { splitCommandLine } from "@/platform/commandLine";
import { call, commands, type RunConfig } from "@/platform/ipc";
import { registerRunConfigType, type RunConfigTypeContribution } from "@/workbench/contributions";
import { hostOs } from "@/platform/remote";
import { imageTag, targetTitle, type DockerTarget } from "./compose";
import { connections, endpointOf, loadSettings, useServices } from "./store";
import { tx } from "@/platform/i18n";
@@ -19,7 +20,7 @@ export const DOCKER_COMPOSE = "docker-compose";
const GROUP = "Docker";
const on = (v: string | undefined) => v === "true";
const isWindows = () => typeof navigator !== "undefined" && /win/i.test(navigator.platform);
const isWindows = () => hostOs() === "windows";
/** One word for the platform shell the run executes the line with (`/bin/sh -c` or `cmd /C`). */
export function shellQuote(word: string, windows = isWindows()): string {
+1 -1
Переглянути файл
@@ -124,7 +124,7 @@ export function recentMenu(project: RecentProject, onOpened?: () => void): MenuI
label: "Open in New Window",
icon: "folder-open",
run: () =>
void call(commands.windowOpenRemote(remote.sshConfig, remote.path, true))
void call(commands.windowOpenRemote(remote.target, remote.path, true))
.then(() => onOpened?.())
.catch(() => undefined),
}
+52
Переглянути файл
@@ -0,0 +1,52 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
const openProject = vi.fn();
const openRemoteProject = vi.fn();
const UNC = String.raw`\\wsl.localhost\Ubuntu\home\me\app`;
vi.mock("@/platform/ipc", async (orig) => {
const real = await orig<typeof import("@/platform/ipc")>();
return {
...real,
isTauri: () => true,
commands: {
...real.commands,
wslResolve: async (p: string) =>
p === UNC ? { target: { kind: "wsl", distro: "Ubuntu" }, path: "/home/me/app" } : null,
},
};
});
vi.mock("@/platform/project", async (orig) => {
const real = await orig<typeof import("@/platform/project")>();
return { ...real, openProject: (p: string) => openProject(p) };
});
vi.mock("@/workbench/projectWindow", () => ({
openRemoteProject: (...a: unknown[]) => openRemoteProject(...a),
}));
const { openRecent } = await import("./recent");
const { useProject } = await import("@/platform/project");
beforeEach(() => {
openProject.mockReset();
openRemoteProject.mockReset().mockResolvedValue(true);
useProject.setState({ project: null, lightEdit: false });
});
describe("openRecent", () => {
it("opens a legacy WSL UNC recent through the distro, not as a local folder", async () => {
expect(await openRecent({ path: UNC, name: "app" })).toBe(true);
expect(openRemoteProject).toHaveBeenCalledWith(
{ kind: "wsl", distro: "Ubuntu" },
"/home/me/app",
expect.any(Function),
);
expect(openProject).not.toHaveBeenCalled();
});
it("still opens a plain local recent locally", async () => {
await openRecent({ path: "/p/local", name: "local" });
expect(openProject).toHaveBeenCalledWith("/p/local");
expect(openRemoteProject).not.toHaveBeenCalled();
});
});
+27 -9
Переглянути файл
@@ -1,9 +1,26 @@
/** Recent projects: loading, filtering, opening and removal. */
import { create } from "zustand";
import { executeAction, getAction } from "@/platform/actions";
import { commands, IpcError, isCancelled, isTauri, type RecentProject, type RecentProjectGroup } from "@/platform/ipc";
import {
commands,
IpcError,
isCancelled,
isTauri,
type RecentProject,
type RecentProjectGroup,
type RemoteTarget,
} from "@/platform/ipc";
import { openProject, useProject } from "@/platform/project";
import { connectRemote, forgetRemote, parseRemoteLocation, recentRemotes, remoteLocation } from "@/platform/remote";
import {
connectRemote,
forgetRemote,
parseRemoteLocation,
recentRemotes,
remoteLocation,
resolveRemoteLocation,
sameTarget,
targetName,
} from "@/platform/remote";
import { tx } from "@/platform/i18n";
import { fuzzyMatch } from "@/ui";
import { notifications } from "@/workbench/contributions";
@@ -64,7 +81,7 @@ export async function loadRecent() {
/** The recent remote projects (Remote Development) among the local ones, most recent first. */
function withRemotes(local: RecentProject[]): RecentProject[] {
const remote: RecentProject[] = recentRemotes().map((r) => ({
path: remoteLocation(r.sshConfig, r.path),
path: remoteLocation(r.target, r.path),
name: r.name,
openedAtMs: r.openedAtMs,
branch: null,
@@ -77,7 +94,8 @@ function withRemotes(local: RecentProject[]): RecentProject[] {
export function remoteDisplay(location: string): string | null {
const r = parseRemoteLocation(location);
if (!r) return null;
const host = recentRemotes().find((x) => x.sshConfig === r.sshConfig && x.path === r.path)?.host || r.sshConfig;
const host =
recentRemotes().find((x) => sameTarget(x.target, r.target) && x.path === r.path)?.host || targetName(r.target);
return `${host}:${r.path}`;
}
@@ -88,7 +106,7 @@ export async function removeRecent(path: string) {
}));
const remote = parseRemoteLocation(path);
if (remote) {
forgetRemote(remote.sshConfig, remote.path);
forgetRemote(remote.target, remote.path);
return;
}
if (!isTauri()) return;
@@ -107,7 +125,7 @@ export async function openRecent(project: Pick<RecentProject, "path" | "name">):
});
return false;
}
const remote = parseRemoteLocation(project.path);
const remote = await resolveRemoteLocation(project.path);
if (remote) return openRemote(project, remote);
const current = useProject.getState().project;
if (current?.root === project.path) return true;
@@ -139,12 +157,12 @@ export async function openRecent(project: Pick<RecentProject, "path" | "name">):
async function openRemote(
project: Pick<RecentProject, "path" | "name">,
remote: { sshConfig: string; path: string },
remote: { target: RemoteTarget; path: string },
): Promise<boolean> {
try {
return await openRemoteProject(remote.sshConfig, remote.path, async () => {
return await openRemoteProject(remote.target, remote.path, async () => {
useRecent.setState({ opening: project.path });
await connectRemote(remote.sshConfig, remote.path);
await connectRemote(remote.target, remote.path);
});
} catch (e) {
if (isCancelled(e)) return false;
+21 -1
Переглянути файл
@@ -1,15 +1,26 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
const openProject = vi.fn();
const connectRemote = vi.fn();
const UNC = String.raw`\\wsl.localhost\Ubuntu\home\me\app`;
vi.mock("@/platform/ipc", async (orig) => {
const real = await orig<typeof import("@/platform/ipc")>();
return {
...real,
isTauri: () => true,
commands: { ...real.commands, settingsGet: async () => ({ general: { reopenLastProject: true } }) },
commands: {
...real.commands,
settingsGet: async () => ({ general: { reopenLastProject: true } }),
wslResolve: async (p: string) =>
p === UNC ? { target: { kind: "wsl", distro: "Ubuntu" }, path: "/home/me/app" } : null,
},
};
});
vi.mock("@/platform/remote", async (orig) => {
const real = await orig<typeof import("@/platform/remote")>();
return { ...real, connectRemote: (t: unknown, p: string) => connectRemote(t, p) };
});
vi.mock("@tauri-apps/api/window", () => ({ getCurrentWindow: () => ({ label: "main" }) }));
vi.mock("@/platform/project", async (orig) => {
const real = await orig<typeof import("@/platform/project")>();
@@ -21,6 +32,7 @@ const { provideStartupLaunch, useProject } = await import("@/platform/project");
beforeEach(() => {
openProject.mockReset();
connectRemote.mockReset();
useProject.setState({ project: null, lightEdit: false });
sessionStorage.clear();
localStorage.setItem("openidea.session.openProject", "/p/last");
@@ -67,4 +79,12 @@ describe("reopenLastProject", () => {
await reopenLastProject();
expect(openProject).toHaveBeenCalledWith("/p/last");
});
it("restores a session saved as a WSL UNC folder through the distro", async () => {
localStorage.setItem("openidea.session.openProject", UNC);
provideStartupLaunch(Promise.resolve());
await reopenLastProject();
expect(connectRemote).toHaveBeenCalledWith({ kind: "wsl", distro: "Ubuntu" }, "/home/me/app");
expect(openProject).not.toHaveBeenCalled();
});
});
+3 -3
Переглянути файл
@@ -7,7 +7,7 @@ import { getCurrentWindow } from "@tauri-apps/api/window";
import { create } from "zustand";
import { commands, isCancelled, isTauri, type Settings } from "@/platform/ipc";
import { openProject, startupLaunchHandled, useProject } from "@/platform/project";
import { connectRemote, parseRemoteLocation, projectLocation } from "@/platform/remote";
import { connectRemote, projectLocation, resolveRemoteLocation } from "@/platform/remote";
import { notifications } from "@/workbench/contributions";
const SESSION_KEY = "openidea.session.openProject";
@@ -117,8 +117,8 @@ async function reopen(path: string) {
const name = path.slice(path.lastIndexOf("/") + 1) || path;
useSession.setState({ reopening: path });
try {
const remote = parseRemoteLocation(path);
if (remote) await connectRemote(remote.sshConfig, remote.path);
const remote = await resolveRemoteLocation(path);
if (remote) await connectRemote(remote.target, remote.path);
else await openProject(path);
} catch (e) {
write(SESSION_KEY, null);