mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-23 08:02:51 +00:00
* 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 <nguyenbang@NTBANG.local> Co-authored-by: NguyenBang <nguyenbang@Mac.lan> Co-authored-by: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com>
253 lines
8.2 KiB
TypeScript
253 lines
8.2 KiB
TypeScript
/** Picks an SSH configuration and a folder on that host, then opens it in this or a new window. */
|
|
import { useEffect, useState } from "react";
|
|
import { executeAction } from "@/platform/actions";
|
|
import { useTx } from "@/platform/i18n";
|
|
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";
|
|
import { openRemoteProject } from "@/workbench/projectWindow";
|
|
import {
|
|
browsableFolders,
|
|
closeConnectDialog,
|
|
listedDirectory,
|
|
remoteParent,
|
|
stageLabel,
|
|
useConnectDialog,
|
|
} from "./model";
|
|
import styles from "./RemoteDev.module.css";
|
|
|
|
export function ConnectHost() {
|
|
const open = useConnectDialog((s) => s.open);
|
|
return open ? <ConnectDialog /> : null;
|
|
}
|
|
|
|
const SSH_SETTINGS_PAGE = "tools.sshConfigurations";
|
|
|
|
/**
|
|
* This machine's SSH configurations: the connection is made from here. A remote project's
|
|
* window has the remote host's settings, which don't list them.
|
|
*/
|
|
function useLocalSshConfigs(): SshConfigValid[] {
|
|
const [configs, setConfigs] = useState<SshConfigValid[]>([]);
|
|
useEffect(() => {
|
|
let live = true;
|
|
const load = () =>
|
|
void commands.settingsGetGlobal().then(
|
|
(s) => live && setConfigs(validateRemote(s).ssh.configs),
|
|
() => {},
|
|
);
|
|
load();
|
|
const off = onIdeEvent("settingsChanged", load);
|
|
return () => {
|
|
live = false;
|
|
off();
|
|
};
|
|
}, []);
|
|
return configs;
|
|
}
|
|
|
|
function ConnectDialog() {
|
|
const tx = useTx();
|
|
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);
|
|
try {
|
|
const entries = await call(commands.remoteBootstrapList(ssh, dir));
|
|
const shown = listedDirectory(dir, entries);
|
|
setBrowse({ dir: shown, folders: browsableFolders(entries) });
|
|
setPath(shown);
|
|
} catch (e) {
|
|
setError(e instanceof Error ? e.message : String(e));
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
};
|
|
|
|
const connect = async () => {
|
|
setError(null);
|
|
setBusy(true);
|
|
try {
|
|
if (await openRemoteProject(target, path.trim() || "~")) closeConnectDialog();
|
|
else setBusy(false);
|
|
} catch (e) {
|
|
if (!isCancelled(e)) setError(e instanceof Error ? e.message : String(e));
|
|
setBusy(false);
|
|
}
|
|
};
|
|
|
|
const options = configs.map((c) => ({ value: c.id, label: c.name.trim() || sshLabel(c), detail: sshLabel(c) }));
|
|
const ready = !!name && !busy && !!path.trim();
|
|
const connecting = useRemoteProgress((s) => s.progress !== null);
|
|
|
|
return (
|
|
<Dialog
|
|
open
|
|
title={tx("Remote Development")}
|
|
onClose={closeConnectDialog}
|
|
width={560}
|
|
buttons={[
|
|
{
|
|
label: connecting ? "Connecting…" : "Open",
|
|
role: "default",
|
|
disabled: !ready,
|
|
onClick: () => void connect(),
|
|
},
|
|
{ label: "Cancel", role: "cancel" },
|
|
]}
|
|
>
|
|
<form
|
|
className={styles.form}
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
if (ready) void connect();
|
|
}}
|
|
>
|
|
<p className={styles.hint}>
|
|
{tx("The project runs on the remote host; the IDE backend is installed there on first use.")}
|
|
</p>
|
|
{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>
|
|
<div className={styles.row}>
|
|
<Input
|
|
id="remote-dev-path"
|
|
className={styles.grow}
|
|
data-autofocus
|
|
value={path}
|
|
spellCheck={false}
|
|
onChange={(e) => setPath(e.target.value)}
|
|
/>
|
|
{/* 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")}>
|
|
{browse.dir !== "/" && (
|
|
<li>
|
|
<button type="button" className={styles.folder} onClick={() => void list(remoteParent(browse.dir))}>
|
|
<Icon name="folder" />
|
|
..
|
|
</button>
|
|
</li>
|
|
)}
|
|
{browse.folders.map((f) => (
|
|
<li key={f.path}>
|
|
<button type="button" className={styles.folder} onClick={() => void list(f.path)}>
|
|
<Icon name="folder" />
|
|
{f.name}
|
|
</button>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
<ConnectProgress />
|
|
{error && (
|
|
<div className={styles.error} role="alert">
|
|
{error}
|
|
</div>
|
|
)}
|
|
</form>
|
|
</Dialog>
|
|
);
|
|
}
|
|
|
|
/** The stage of the connection in progress (and how far a download / upload is). */
|
|
function ConnectProgress() {
|
|
const tx = useTx();
|
|
const progress = useRemoteProgress((s) => s.progress);
|
|
if (!progress) return null;
|
|
const percent = progress.fraction == null ? null : Math.round(progress.fraction * 100);
|
|
return (
|
|
<div className={styles.progress} role="status">
|
|
<div className={styles.progressLine}>
|
|
<Spinner size={12} />
|
|
<span>{tx(stageLabel(progress.stage))}</span>
|
|
{percent != null && <span className={styles.percent}>{percent}%</span>}
|
|
</div>
|
|
<ProgressBar value={progress.fraction} aria-label={tx(stageLabel(progress.stage))} />
|
|
</div>
|
|
);
|
|
}
|