mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-18 16:08:55 +00:00
fix(welcome): list remote windows under Open Projects in the project widget (#3824)
Connecting a window to a remote host (WSL, SSH, Dev Container) closes its local project, and window_open_projects only looked up local projects, so remote windows never appeared under Open Projects. It now reports remote windows from their connection, with OpenProject.remote; the project widget keys them like their recent entry (remoteLocation) so they leave Recent Projects, and picking one focuses the connected window through openRecent. Co-authored-by: brunobelloni <14021404+brunobelloni@users.noreply.github.com>
This commit is contained in:
@@ -199,6 +199,8 @@ pub struct OpenProject {
|
||||
pub root: PathBuf,
|
||||
/// Open in the calling window.
|
||||
pub current: bool,
|
||||
/// Where the project lives when the window is connected to a remote host (`root` is then a path there).
|
||||
pub remote: Option<crate::remote_dev::RemoteTarget>,
|
||||
}
|
||||
|
||||
/// Projects open in project windows, in window order (title bar project widget).
|
||||
@@ -212,11 +214,19 @@ pub fn window_open_projects(
|
||||
Ok(windows::project_window_labels(&app)
|
||||
.into_iter()
|
||||
.filter_map(|label| {
|
||||
let current = label == window.label();
|
||||
// A remote window's project lives on the server: it has no local project here.
|
||||
if let Some(c) = state.remote_dev.get(&label) {
|
||||
let root = PathBuf::from(&c.root);
|
||||
let name = c.root.trim_end_matches('/').rsplit('/').next().unwrap_or_default().to_owned();
|
||||
return Some(OpenProject { name, root, current, remote: Some(c.target.clone()) });
|
||||
}
|
||||
let project = state.project(&label).ok().filter(|p| !p.light)?;
|
||||
Some(OpenProject {
|
||||
name: project.root.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default(),
|
||||
root: project.root.clone(),
|
||||
current: label == window.label(),
|
||||
current,
|
||||
remote: None,
|
||||
})
|
||||
})
|
||||
.collect())
|
||||
|
||||
@@ -8426,6 +8426,8 @@ export type OpenProject = {
|
||||
root: string,
|
||||
/** Open in the calling window. */
|
||||
current: boolean,
|
||||
/** Where the project lives when the window is connected to a remote host (`root` is then a path there). */
|
||||
remote: RemoteTarget | null,
|
||||
};
|
||||
|
||||
/** A node of a document outline (Structure tool window, breadcrumbs). */
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createRef } from "react";
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
import type { OpenProject, RecentProject } from "@/platform/ipc";
|
||||
import { remoteLocation } from "@/platform/remote";
|
||||
|
||||
const wsl = { kind: "wsl", distro: "Ubuntu-24.04" } as const;
|
||||
let open: OpenProject[] = [];
|
||||
let recent: RecentProject[] = [];
|
||||
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
||||
return {
|
||||
...real,
|
||||
isTauri: () => true,
|
||||
commands: {
|
||||
...real.commands,
|
||||
recentProjects: async () => recent,
|
||||
recentProjectGroups: async () => [],
|
||||
windowOpenProjects: async () => ({ status: "ok", data: open }),
|
||||
},
|
||||
};
|
||||
});
|
||||
vi.mock("@tauri-apps/api/path", () => ({ homeDir: async () => "/Users/me" }));
|
||||
|
||||
import { ProjectPopup } from "./ProjectPopup";
|
||||
|
||||
describe("ProjectPopup", () => {
|
||||
it("lists remote windows under Open Projects, not again under Recent Projects", async () => {
|
||||
open = [
|
||||
{ name: "FastAPIProject", root: "/root/projetos/FastAPIProject", current: true, remote: wsl },
|
||||
{ name: "datahub-front", root: "/root/projetos/datahub-front", current: false, remote: wsl },
|
||||
];
|
||||
recent = [
|
||||
{
|
||||
path: remoteLocation(wsl, "/root/projetos/FastAPIProject"),
|
||||
name: "FastAPIProject",
|
||||
openedAtMs: 2,
|
||||
branch: null,
|
||||
},
|
||||
{ path: remoteLocation(wsl, "/root/projetos/datahub-front"), name: "datahub-front", openedAtMs: 1, branch: null },
|
||||
{ path: remoteLocation(wsl, "/root/projetos/other"), name: "other", openedAtMs: 0, branch: null },
|
||||
];
|
||||
const anchor = createRef<HTMLButtonElement>();
|
||||
render(
|
||||
<>
|
||||
<button ref={anchor} />
|
||||
<ProjectPopup anchor={anchor} onClose={() => {}} />
|
||||
</>,
|
||||
);
|
||||
await screen.findByText("Open Projects");
|
||||
const list = screen.getByRole("listbox");
|
||||
const text = list.textContent ?? "";
|
||||
expect(text.indexOf("Open Projects")).toBeLessThan(text.indexOf("FastAPIProject"));
|
||||
expect(text.indexOf("datahub-front")).toBeLessThan(text.indexOf("Recent Projects"));
|
||||
expect(text.indexOf("Recent Projects")).toBeLessThan(text.indexOf("other"));
|
||||
expect(within(list).getAllByText("FastAPIProject")).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,7 @@ import { askRemoveRecent, ProjectBadge, recentMenu } from "./RecentList";
|
||||
import { filterRecent, loadRecent, openRecent, useRecent, type RecentMatch } from "./recent";
|
||||
import styles from "./ProjectPopup.module.css";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { parseRemoteLocation, remoteLocation } from "@/platform/remote";
|
||||
|
||||
type Entry =
|
||||
| { kind: "action"; id: string; label: string; icon: IconName }
|
||||
@@ -47,9 +48,13 @@ export function ProjectPopup({ anchor, onClose }: ProjectPopupProps) {
|
||||
useEffect(() => void loadRecent(), []);
|
||||
|
||||
const entries = useMemo<Entry[]>(() => {
|
||||
const openPaths = new Set(openProjects.map((p) => p.root));
|
||||
const asRecent = (p: OpenProject): RecentProject =>
|
||||
recent.find((r) => r.path === p.root) ?? { path: p.root, name: p.name, openedAtMs: null, branch: null };
|
||||
// A remote window's project is keyed like its recent entry (`wsl://…`, `ssh://…`).
|
||||
const location = (p: OpenProject) => (p.remote ? remoteLocation(p.remote, p.root) : p.root);
|
||||
const openPaths = new Set(openProjects.map(location));
|
||||
const asRecent = (p: OpenProject): RecentProject => {
|
||||
const path = location(p);
|
||||
return recent.find((r) => r.path === path) ?? { path, name: p.name, openedAtMs: null, branch: null };
|
||||
};
|
||||
const open = filterRecent(openProjects.map(asRecent), query, home).map((m) => ({
|
||||
kind: "project" as const,
|
||||
open: true,
|
||||
@@ -73,7 +78,9 @@ export function ProjectPopup({ anchor, onClose }: ProjectPopupProps) {
|
||||
if (!e) return;
|
||||
onClose();
|
||||
if (e.kind === "action") void executeAction(e.id);
|
||||
else if (e.open) void call(commands.windowOpenProject(e.m.project.path, false, [])).catch(() => undefined);
|
||||
else if (e.open && !parseRemoteLocation(e.m.project.path))
|
||||
void call(commands.windowOpenProject(e.m.project.path, false, [])).catch(() => undefined);
|
||||
// Opening a remote location focuses the window already connected to it.
|
||||
else void openRecent(e.m.project);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user