Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai f3007e4093 fix(app): list Remote Development projects in File > Open Recent
Manage Projects merged the frontend's recent remote projects (SSH, WSL,
Dev Containers) with the backend's local list, but Open Recent, in the
macOS menu bar and the Windows/Linux title bar menu, read only the local
one. The frontend now hands its remote list to the menu, which merges it
by when each project was opened; choosing one opens it on its host.

Fixes #6124
2026-11-26 18:29:29 +08:00
8 змінених файлів з 149 додано та 18 видалено

No files matched your search

+18 -1
Переглянути файл
@@ -463,7 +463,23 @@ pub fn menu_model(app: AppHandle, state: State<'_, AppState>, menu_state: State<
}
let home = dirs::home_dir();
let config = menu_state.config.lock().clone();
menu::model(&spec, &menu::recent_items(&state.recent.list(), home.as_deref()), &config)
let remote = menu_state.remote_recent.lock().clone();
menu::model(&spec, &menu::recent_items(&state.recent.list(), &remote, home.as_deref()), &config)
}
/// The Remote Development projects of the frontend's recent list, for Open Recent.
#[desktop_command(trust = always)]
#[tauri::command]
#[specta::specta]
pub fn menu_set_remote_recent(
app: AppHandle,
menu_state: State<'_, MenuState>,
state: State<'_, AppState>,
projects: Vec<menu::RemoteRecent>,
) {
if menu::store_remote_recent(&menu_state, projects) {
menu::install(&app, &menu_state, &state.recent.list());
}
}
/// Action ids the focused window cannot run now: their native menu items are
@@ -996,6 +1012,7 @@ ide_command::desktop_domain!(
menu_model,
menu_refresh,
menu_set_disabled,
menu_set_remote_recent,
window_begin_prompt,
window_close_context,
window_complete_launch,
+77 -14
Переглянути файл
@@ -1117,6 +1117,31 @@ pub struct MenuState {
/// Visible menu last installed. Accelerators of actions that are not on the menu
/// are not part of this, so they must not redraw the macOS menu bar.
rendered: Mutex<Option<Vec<RenderedMenu>>>,
/// The Remote Development projects of the frontend's recent list.
pub remote_recent: Mutex<Vec<RemoteRecent>>,
}
/// A recent Remote Development project (SSH, WSL, Dev Container), kept by the frontend: Open
/// Recent lists it among the local projects, as Manage Projects does.
#[derive(Debug, Clone, PartialEq, Deserialize, Type)]
#[serde(rename_all = "camelCase")]
pub struct RemoteRecent {
/// `ssh://host/path`, `wsl://Ubuntu/path`…: what `file.openRecentProject` gets back.
pub location: String,
pub name: String,
/// Where it lives, as shown after the name (`me@host:/srv/app`).
pub detail: String,
pub opened_at_ms: f64,
}
/// Stores the remote recent list; `false` when it is unchanged.
pub fn store_remote_recent(state: &MenuState, next: Vec<RemoteRecent>) -> bool {
let mut current = state.remote_recent.lock();
if *current == next {
return false;
}
*current = next;
true
}
/// Stores `next` when it differs from the config last used to build the menu.
@@ -1193,18 +1218,28 @@ pub struct RecentItem {
pub label: String,
}
pub fn recent_items(recent: &[ide_workspace::RecentProject], home: Option<&Path>) -> Vec<RecentItem> {
recent
.iter()
.take(MAX_RECENT)
.map(|p| {
let shown = match home.and_then(|h| p.path.strip_prefix(h).ok()) {
Some(rest) => format!("~/{}", rest.display()),
None => p.path.display().to_string(),
};
RecentItem { path: p.path.to_string_lossy().into_owned(), label: format!("{} — {shown}", p.name) }
})
.collect()
/// The local and remote recent projects, most recently opened first.
pub fn recent_items(
recent: &[ide_workspace::RecentProject],
remote: &[RemoteRecent],
home: Option<&Path>,
) -> Vec<RecentItem> {
let local = recent.iter().map(|p| {
let shown = match home.and_then(|h| p.path.strip_prefix(h).ok()) {
Some(rest) => format!("~/{}", rest.display()),
None => p.path.display().to_string(),
};
let item =
RecentItem { path: p.path.to_string_lossy().into_owned(), label: format!("{} — {shown}", p.name) };
(p.opened_at_ms, item)
});
let remote = remote.iter().map(|r| {
(r.opened_at_ms, RecentItem { path: r.location.clone(), label: format!("{} — {}", r.name, r.detail) })
});
let mut items: Vec<(f64, RecentItem)> = local.chain(remote).collect();
// Stable: the local list's own order holds among equal times.
items.sort_by(|a, b| b.0.total_cmp(&a.0));
items.into_iter().take(MAX_RECENT).map(|(_, item)| item).collect()
}
/// One top-level menu, as it will actually be drawn.
@@ -1746,7 +1781,7 @@ pub fn install<R: Runtime>(app: &AppHandle<R>, menu_state: &MenuState, recent: &
return;
}
let home = dirs::home_dir();
let items = recent_items(recent, home.as_deref());
let items = recent_items(recent, &menu_state.remote_recent.lock(), home.as_deref());
let config = menu_state.config.lock().clone();
let disabled = menu_state.disabled.lock().clone();
let rendered = render_bar(&prepared_spec(app, Os::current()), &config, &items);
@@ -2233,11 +2268,39 @@ mod tests {
branch: None,
missing: false,
}];
let items = recent_items(&recent, Some(Path::new("/home/me")));
let items = recent_items(&recent, &[], Some(Path::new("/home/me")));
assert_eq!(items[0].label, "openidea — ~/code/openidea");
assert_eq!(items[0].path, "/home/me/code/openidea");
}
#[test]
fn remote_projects_join_the_recent_list_by_when_they_were_opened() {
let local = |path: &str, at: f64| ide_workspace::RecentProject {
path: path.into(),
name: path.rsplit('/').next().unwrap().into(),
opened_at_ms: at,
branch: None,
missing: false,
};
let recent = vec![local("/home/me/new", 30.0), local("/home/me/old", 10.0)];
let remote = [RemoteRecent {
location: "wsl://Ubuntu/home/me/api".into(),
name: "api".into(),
detail: "Ubuntu:/home/me/api".into(),
opened_at_ms: 20.0,
}];
let items = recent_items(&recent, &remote, Some(Path::new("/home/me")));
let paths: Vec<&str> = items.iter().map(|i| i.path.as_str()).collect();
assert_eq!(paths, ["/home/me/new", "wsl://Ubuntu/home/me/api", "/home/me/old"]);
assert_eq!(items[1].label, "api — Ubuntu:/home/me/api");
let many: Vec<_> = (0..20).map(|i| local(&format!("/p/{i}"), f64::from(i))).collect();
let items = recent_items(&many, &remote, None);
assert_eq!(items.len(), MAX_RECENT);
assert_eq!([items[0].path.as_str(), items[1].path.as_str()], ["wsl://Ubuntu/home/me/api", "/p/19"]);
assert_eq!(items[MAX_RECENT - 1].path, format!("/p/{}", 20 - MAX_RECENT + 1), "the remote one takes a slot");
}
#[test]
fn model_drops_native_roles_and_fills_recent() {
let spec = vec![sub(
+1
Переглянути файл
@@ -429,6 +429,7 @@ menu_configure always desktop bin
menu_model always desktop bindings sync
menu_refresh always desktop bindings sync
menu_set_disabled always desktop bindings sync
menu_set_remote_recent always desktop bindings sync
nav_index_definitions always project_host bindings async
nav_inheritance always project_host bindings async
nav_python_stubs always project_host bindings async
+15
Переглянути файл
@@ -1162,6 +1162,8 @@ export const commands = {
* disabled in place (no rebuild).
*/
menuSetDisabled: (ids: string[]) => __TAURI_INVOKE<void>("menu_set_disabled", { ids }),
/** The Remote Development projects of the frontend's recent list, for Open Recent. */
menuSetRemoteRecent: (projects: RemoteRecent[]) => __TAURI_INVOKE<void>("menu_set_remote_recent", { projects }),
/**
* Index definitions named `name` within the roots `from` may navigate into (its own root
* plus its configured dependencies).
@@ -12166,6 +12168,19 @@ export type RemoteProject_Serialize = {
project: ProjectInfo_Serialize,
};
/**
* A recent Remote Development project (SSH, WSL, Dev Container), kept by the frontend: Open
* Recent lists it among the local projects, as Manage Projects does.
*/
export type RemoteRecent = {
/** `ssh://host/path`, `wsl://Ubuntu/path`…: what `file.openRecentProject` gets back. */
location: string,
name: string,
/** Where it lives, as shown after the name (`me@host:/srv/app`). */
detail: string,
openedAtMs: number | null,
};
export type RemoteSession = RemoteSession_Serialize | RemoteSession_Deserialize;
export type RemoteSession_Deserialize = {
+10
Переглянути файл
@@ -12,6 +12,7 @@ const windowGroupJoin = vi.fn();
const windowTakeLaunch = vi.fn();
const windowCompleteLaunch = vi.fn();
const wslResolve = vi.fn();
const windowOpenRemote = vi.fn();
const cancelClose = vi.fn();
const notify = vi.fn();
const listen = vi.fn();
@@ -51,6 +52,7 @@ vi.mock("@/platform/ipc", async (orig) => {
windowTakeLaunch: () => windowTakeLaunch(),
windowCompleteLaunch: () => windowCompleteLaunch(),
wslResolve: (p: string) => wslResolve(p),
windowOpenRemote: (...a: unknown[]) => windowOpenRemote(...a),
lightEditOpen: (p: string) => lightEditOpen(p),
fsReadDir: (p: string) => fsReadDir(p),
},
@@ -266,6 +268,14 @@ describe("a recent project opened with a modifier key", () => {
await action.run({ arg: "/p/b" } as never);
expect(windowOpenProject).toHaveBeenLastCalledWith("/p/b", false, []);
});
it("opens a Remote Development project from Open Recent on its host (#6124)", async () => {
windowOpenRemote.mockResolvedValue(ok({ kind: "focused" }));
const action = windowActions().find((a) => a.id === "file.openRecentProject")!;
await action.run({ arg: "wsl://Ubuntu/home/me/api" } as never);
expect(windowOpenRemote).toHaveBeenCalledWith({ kind: "wsl", distro: "Ubuntu" }, "/home/me/api", false);
expect(windowOpenProject).not.toHaveBeenCalled();
});
});
describe("loose files (LightEdit)", () => {
+2
Переглянути файл
@@ -20,6 +20,7 @@ import {
useKeymap,
} from "@/platform/keymap";
import { useProject } from "@/platform/project";
import { syncRemoteRecentMenu } from "@/platform/remote";
import { useContributions, useMenuSlotItems, useStandaloneEditor } from "@/workbench/contributions";
import { useDistractionFree } from "@/workbench/distractionFree";
import { javaFileNameOf, menuLabelParams } from "@/workbench/menuLabels";
@@ -258,6 +259,7 @@ export function installMenuBridge(): () => void {
.catch(() => {});
push();
syncRemoteRecentMenu();
const onFocus = () => {
push();
pushEnablement(true);
+11 -3
Переглянути файл
@@ -22,10 +22,10 @@ import {
} from "@/platform/project";
import { confirmProjectTrust } from "@/platform/projectTrust";
import { ask } from "@/workbench/messages";
import { connectRemote, isRemoteWindow } from "@/platform/remote";
import { connectRemote, isRemoteWindow, parseRemoteLocation } from "@/platform/remote";
import { holdSplash } from "@/platform/splash";
import { editorService, maybeEditorService, notifications } from "@/workbench/contributions";
import { chooseProjectWindow, type ProjectWindowOverride } from "@/workbench/projectWindow";
import { chooseProjectWindow, openRemoteProject, type ProjectWindowOverride } from "@/workbench/projectWindow";
import { openTabColorPicker } from "@/workbench/TabColorPicker";
import { cycleWindowTab, useWindowGroup } from "@/platform/windowGroups";
import { editorSwitching } from "@/editor/api";
@@ -606,7 +606,15 @@ export function windowActions(): Action[] {
hidden: true,
run: async (c) => {
const recent = recentProjectArg(c.arg);
if (recent) await openProjectWithPolicy(recent.path, [], recent.window);
if (!recent) return;
// Open Recent lists Remote Development projects by their location (`ssh://host/path`).
const remote = parseRemoteLocation(recent.path);
if (!remote) return openProjectWithPolicy(recent.path, [], recent.window);
try {
await openRemoteProject(remote.target, remote.path, undefined, recent.window);
} catch (e) {
openFailed(remote.path, e);
}
},
},
{
+15
Переглянути файл
@@ -455,6 +455,21 @@ function saveRemotes(list: RecentRemote[]) {
} catch {
/* storage unavailable */
}
syncRemoteRecentMenu();
}
/** Hands the recent remote projects to File › Open Recent, which lists them among the local ones. */
export function syncRemoteRecentMenu() {
if (!isTauri()) return;
const projects = recentRemotes().map((r) => ({
location: remoteLocation(r.target, r.path),
name: r.name,
detail: `${r.host || targetName(r.target)}:${r.path}`,
openedAtMs: r.openedAtMs,
}));
void Promise.resolve()
.then(() => commands.menuSetRemoteRecent(projects))
.catch(() => {});
}
const sameRemote = (a: Pick<RecentRemote, "target" | "path">, b: Pick<RecentRemote, "target" | "path">) =>