дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-20 00:25:42 +02:00
Порівняти коміти
1
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
c277de9b1c |
No files matched your search
@@ -13,6 +13,10 @@ pub struct RecentProject {
|
||||
/// Git branch shown on the welcome screen. Persisted as of last open; [`RecentProjects::list_live`]
|
||||
/// refreshes it from `.git/HEAD` when the list is shown.
|
||||
pub branch: Option<String>,
|
||||
/// The local folder no longer exists (set by [`with_live_branches`] when the list is shown): the
|
||||
/// welcome screen shows the entry as unavailable.
|
||||
#[serde(default)]
|
||||
pub missing: bool,
|
||||
}
|
||||
|
||||
pub const MAX_RECENT_PROJECTS: usize = 30;
|
||||
@@ -139,11 +143,23 @@ pub fn with_live_branches(mut items: Vec<RecentProject>) -> Vec<RecentProject> {
|
||||
for item in &mut items {
|
||||
if let Ok(branch) = read_head_branch(item.path.as_ref()) {
|
||||
item.branch = branch;
|
||||
} else if is_missing(item.path.as_ref()) {
|
||||
// A deleted repository has no branch to show.
|
||||
item.missing = true;
|
||||
item.branch = None;
|
||||
}
|
||||
}
|
||||
items
|
||||
}
|
||||
|
||||
/// A local project folder that is gone. Remote locations (`ssh://`, `wsl://`, `devcontainer://`)
|
||||
/// and WSL shares, which a stopped distribution only hides, never count as missing.
|
||||
fn is_missing(path: &Path) -> bool {
|
||||
let text = path.to_string_lossy();
|
||||
let wsl = text.starts_with(r"\\wsl$") || text.starts_with(r"\\wsl.localhost");
|
||||
path.is_absolute() && !text.contains("://") && !wsl && !path.exists()
|
||||
}
|
||||
|
||||
impl RecentProjects {
|
||||
pub fn load(config_dir: &Path) -> Self {
|
||||
let file = config_dir.join("recent.json");
|
||||
@@ -192,7 +208,7 @@ impl RecentProjects {
|
||||
items.retain(|p| p.path != path);
|
||||
let name =
|
||||
path.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_else(|| path.display().to_string());
|
||||
items.insert(0, RecentProject { path: path.into(), name, opened_at_ms: now_ms(), branch });
|
||||
items.insert(0, RecentProject { path: path.into(), name, opened_at_ms: now_ms(), branch, missing: false });
|
||||
cap(&mut items, &self.groups.lock());
|
||||
self.persist(&items)
|
||||
}
|
||||
@@ -341,6 +357,33 @@ mod tests {
|
||||
assert_eq!(recent.list().iter().find(|i| i.path.as_ref() == repo).unwrap().branch.as_deref(), Some("stale"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_live_marks_deleted_folders_missing_without_their_branch() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let gone = tmp.path().join("removed-worktree");
|
||||
write_head(&gone.join(".git"), "ref: refs/heads/feature-x\n");
|
||||
let plain = tmp.path().join("plain");
|
||||
std::fs::create_dir_all(&plain).unwrap();
|
||||
let recent = RecentProjects::load(tmp.path().join("config").as_path());
|
||||
recent.touch(&gone, Some("feature-x".into())).unwrap();
|
||||
recent.touch(&plain, Some("kept".into())).unwrap();
|
||||
recent.touch(Path::new("ssh://server/home/me/app"), None).unwrap();
|
||||
std::fs::remove_dir_all(&gone).unwrap();
|
||||
|
||||
let live = recent.list_live();
|
||||
let by_path = |p: &Path| live.iter().find(|i| i.path.as_ref() == p).unwrap();
|
||||
assert!(by_path(&gone).missing);
|
||||
assert_eq!(by_path(&gone).branch, None);
|
||||
assert!(!by_path(&plain).missing);
|
||||
assert_eq!(by_path(&plain).branch.as_deref(), Some("kept"));
|
||||
assert!(!by_path(Path::new("ssh://server/home/me/app")).missing, "remote locations are not checked");
|
||||
// Only the shown list: the saved one keeps the last branch.
|
||||
let stored = recent.list();
|
||||
let stored = stored.iter().find(|i| i.path.as_ref() == gone).unwrap();
|
||||
assert!(!stored.missing);
|
||||
assert_eq!(stored.branch.as_deref(), Some("feature-x"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_live_follows_worktree_gitdir_and_shows_short_detached_head() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
|
||||
@@ -156,7 +156,7 @@ mod tests {
|
||||
use ide_core::IpcPath;
|
||||
|
||||
fn item(name: &str, path: &str) -> RecentProject {
|
||||
RecentProject { path: IpcPath::from(path), name: name.into(), opened_at_ms: 0.0, branch: None }
|
||||
RecentProject { path: IpcPath::from(path), name: name.into(), opened_at_ms: 0.0, branch: None, missing: false }
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -2056,6 +2056,7 @@ mod tests {
|
||||
name: "openidea".into(),
|
||||
opened_at_ms: 0.0,
|
||||
branch: None,
|
||||
missing: false,
|
||||
}];
|
||||
let items = recent_items(&recent, Some(Path::new("/home/me")));
|
||||
assert_eq!(items[0].label, "openidea — ~/code/openidea");
|
||||
|
||||
@@ -9587,6 +9587,11 @@ export type RecentProject = {
|
||||
* refreshes it from `.git/HEAD` when the list is shown.
|
||||
*/
|
||||
branch: string | null,
|
||||
/**
|
||||
* The local folder no longer exists (set by [`with_live_branches`] when the list is shown): the
|
||||
* welcome screen shows the entry as unavailable.
|
||||
*/
|
||||
missing?: boolean,
|
||||
};
|
||||
|
||||
/** A named group of recent projects on the welcome screen (New Project Group…, Move to Group). */
|
||||
|
||||
@@ -89,6 +89,10 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
/* A recent project whose folder is gone. */
|
||||
.name.unavailable {
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.branch {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { executeAction, useActions } from "@/platform/actions";
|
||||
import { call, commands, isTauri, type OpenProject, type RecentProject } from "@/platform/ipc";
|
||||
import { HighlightedText, Icon, Popup, showContextMenu, type IconName, T } from "@/ui";
|
||||
import type { ProjectPopupProps } from "@/workbench/contributions";
|
||||
import { askRemoveRecent, ProjectBadge, recentMenu } from "./RecentList";
|
||||
import { askRemoveRecent, ProjectBadge, recentMenu, unavailableTitle } from "./RecentList";
|
||||
import { filterRecent, loadRecent, openRecent, useRecent, type RecentMatch } from "./recent";
|
||||
import styles from "./ProjectPopup.module.css";
|
||||
import { tx } from "@/platform/i18n";
|
||||
@@ -197,11 +197,11 @@ function Header({ first, children }: { first: boolean; children: ReactNode }) {
|
||||
function ProjectRow({ m, active }: { m: RecentMatch; active: boolean }) {
|
||||
return (
|
||||
<>
|
||||
<ProjectBadge name={m.project.name} className={styles.badge} />
|
||||
<span className={styles.text}>
|
||||
<ProjectBadge name={m.project.name} className={styles.badge} missing={!!m.project.missing} />
|
||||
<span className={styles.text} title={unavailableTitle(m.project)}>
|
||||
<span className={styles.top}>
|
||||
<HighlightedText
|
||||
className={styles.name}
|
||||
className={clsx(styles.name, m.project.missing && styles.unavailable)}
|
||||
text={m.project.name}
|
||||
indices={m.nameMatch}
|
||||
tone={active ? "accent" : "strong"}
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
showContextMenu,
|
||||
T,
|
||||
} from "@/ui";
|
||||
import { askRemoveRecent, groupMenu, ProjectBadge, recentMenu } from "./RecentList";
|
||||
import { askRemoveRecent, groupMenu, ProjectBadge, recentMenu, unavailableTitle } from "./RecentList";
|
||||
import { openRecent, recentRows, setGroupExpanded, useRecent, type RecentMatch, type RecentRow } from "./recent";
|
||||
import type { RecentProjectGroup } from "@/platform/ipc";
|
||||
import styles from "./Welcome.module.css";
|
||||
@@ -245,7 +245,7 @@ function ProjectRow({
|
||||
id={id}
|
||||
role="option"
|
||||
aria-selected={selected}
|
||||
title={m.project.path}
|
||||
title={unavailableTitle(m.project) ?? m.project.path}
|
||||
className={clsx(styles.project, nested && styles.projectNested, selected && styles.projectSelected)}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => {
|
||||
@@ -258,9 +258,14 @@ function ProjectRow({
|
||||
showContextMenu(e, recentMenu(m.project));
|
||||
}}
|
||||
>
|
||||
<ProjectBadge name={m.project.name} className={styles.projectBadge} />
|
||||
<ProjectBadge name={m.project.name} className={styles.projectBadge} missing={!!m.project.missing} />
|
||||
<span className={styles.projectText}>
|
||||
<HighlightedText className={styles.projectName} text={m.project.name} indices={m.nameMatch} tone="strong" />
|
||||
<HighlightedText
|
||||
className={clsx(styles.projectName, m.project.missing && styles.unavailable)}
|
||||
text={m.project.name}
|
||||
indices={m.nameMatch}
|
||||
tone="strong"
|
||||
/>
|
||||
{stage ? (
|
||||
<span className={styles.projectPath} role="status">
|
||||
{stage}
|
||||
|
||||
@@ -50,14 +50,23 @@ export async function askRemoveRecent(project: RecentProject, before?: () => voi
|
||||
}
|
||||
|
||||
/** Rounded-square project avatar; same colour slot and initials as the title bar's project widget. */
|
||||
export function ProjectBadge({ name, className }: { name: string; className?: string }) {
|
||||
export function ProjectBadge({ name, className, missing }: { name: string; className?: string; missing?: boolean }) {
|
||||
return (
|
||||
<span className={clsx(styles.tile, className)} style={projectColorVars(name)} aria-hidden>
|
||||
<span
|
||||
className={clsx(styles.tile, missing && styles.tileMissing, className)}
|
||||
style={projectColorVars(name)}
|
||||
aria-hidden
|
||||
>
|
||||
{projectInitials(name)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** The tooltip of a recent project whose folder is gone. */
|
||||
export function unavailableTitle(project: Pick<RecentProject, "path" | "missing">): string | undefined {
|
||||
return project.missing ? tx`${project.path} (unavailable)` : undefined;
|
||||
}
|
||||
|
||||
/** New Project Group…: asks for a name; with `path`, that project moves into the new group. */
|
||||
export async function askNewGroup(path?: string) {
|
||||
const name = await promptInput({
|
||||
@@ -188,12 +197,12 @@ function RecentRow({
|
||||
const opening = useRecent((s) => s.opening === m.project.path);
|
||||
const when = relativeTime(m.project.openedAtMs);
|
||||
return (
|
||||
<div className={styles.recent}>
|
||||
<ProjectBadge name={m.project.name} />
|
||||
<div className={styles.recent} title={unavailableTitle(m.project)}>
|
||||
<ProjectBadge name={m.project.name} missing={!!m.project.missing} />
|
||||
<span className={styles.recentText}>
|
||||
<span className={styles.recentTop}>
|
||||
<HighlightedText
|
||||
className={styles.recentName}
|
||||
className={clsx(styles.recentName, m.project.missing && styles.unavailable)}
|
||||
text={m.project.name}
|
||||
indices={m.nameMatch}
|
||||
tone={active ? "accent" : "strong"}
|
||||
|
||||
@@ -526,6 +526,15 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
/* A recent project whose folder is gone. */
|
||||
.recentName.unavailable,
|
||||
.projectName.unavailable {
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.tileMissing {
|
||||
filter: grayscale(1);
|
||||
opacity: 0.5;
|
||||
}
|
||||
.branch {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -102,6 +102,18 @@ describe("Welcome › Projects", () => {
|
||||
expect(screen.getByRole("button", { name: "Open" })).toBeTruthy();
|
||||
});
|
||||
|
||||
it("shows a project whose folder is gone as unavailable", async () => {
|
||||
recent = [
|
||||
p("acme-api", "/Users/me/repo/acme-api", "dev"),
|
||||
{ ...p("gone", "/Users/me/worktrees/gone"), missing: true },
|
||||
];
|
||||
await renderWelcome();
|
||||
const [live, gone] = screen.getAllByRole("option");
|
||||
expect(live!.title).toBe("/Users/me/repo/acme-api");
|
||||
expect(gone!.title).toBe("/Users/me/worktrees/gone (unavailable)");
|
||||
expect(within(gone!).getByText("gone").className).toMatch(/unavailable/);
|
||||
});
|
||||
|
||||
it("moves with arrows, filters by typing, opens with Enter and removes with Delete", async () => {
|
||||
await renderWelcome();
|
||||
const search = screen.getByLabelText("Search projects") as HTMLInputElement;
|
||||
|
||||
Reference in new issue
Заблокувати користувача