From ee9b50179e136a687ae78371eb027d7fb7789f3b Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Mon, 30 Nov 2026 21:15:11 +0900 Subject: [PATCH] feat(welcome): import recent projects and groups from a JetBrains IDE (#6979) Import Recent Projects from JetBrains IDE (Welcome screen more menu, File > Manage IDE Settings) reads the IDE's options/recentProjects.xml and merges its recent projects and project groups into OpenIDEA's. Entries keep their custom or display name and the later of their open and activation times; hidden (LightEdit) entries are skipped, $USER_HOME$ and $APPLICATION_CONFIG_DIR$ are expanded, and projects whose folder is gone are skipped and counted. Existing entries and groups are kept, a taken group name gets a number, and importing twice adds nothing. Import Settings from JetBrains IDE lists the recent projects as a row of its confirmation and merges them too. Closes #6970 Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com> --- Cargo.lock | 1 + crates/ide-host/src/menu.rs | 1 + crates/ide-workspace/Cargo.toml | 1 + crates/ide-workspace/src/recent.rs | 349 +++++++++++++++++- src-tauri/src/commands/app.rs | 31 ++ src-tauri/src/menu.rs | 1 + src-tauri/tests/commands.snap | 1 + src/bindings.ts | 15 + .../__tests__/importFromJetBrainsIde.test.tsx | 62 +++- .../jetbrainsSettingsImport.test.tsx | 30 ++ .../jetbrainsTemplatesImport.test.tsx | 1 + src/features/app/jetbrainsSettings.tsx | 35 +- src/features/app/projectActions.ts | 69 +++- src/features/welcome/ProjectsPage.tsx | 7 + src/platform/locales/en.json | 1 + src/platform/locales/text/en.json | 8 + src/platform/locales/text/zh.json | 7 + src/platform/locales/zh.json | 1 + 18 files changed, 594 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8b19cd0c07..0e01cf43a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5116,6 +5116,7 @@ dependencies = [ "ide-text", "ide-vfs", "parking_lot 0.12.5", + "quick-xml 0.42.0", "semver", "serde", "serde_json", diff --git a/crates/ide-host/src/menu.rs b/crates/ide-host/src/menu.rs index 65eeca5483..d80bb212cd 100644 --- a/crates/ide-host/src/menu.rs +++ b/crates/ide-host/src/menu.rs @@ -277,6 +277,7 @@ pub fn spec(os: Os) -> Vec { act("file.exportSettings", "Export Settings…"), act("file.importSettings", "Import Settings…"), act("file.importJetBrainsSettings", "Import Settings from JetBrains IDE…"), + act("file.importJetBrainsRecentProjects", "Import Recent Projects from JetBrains IDE…"), act("file.syncSettings", "Sync Settings Now"), ], ), diff --git a/crates/ide-workspace/Cargo.toml b/crates/ide-workspace/Cargo.toml index f3e8d275e5..f4d324b079 100644 --- a/crates/ide-workspace/Cargo.toml +++ b/crates/ide-workspace/Cargo.toml @@ -24,6 +24,7 @@ globset.workspace = true uuid.workspace = true zip.workspace = true encoding_rs.workspace = true +quick-xml = "0.42" [target.'cfg(windows)'.dependencies] winreg = "0.56" diff --git a/crates/ide-workspace/src/recent.rs b/crates/ide-workspace/src/recent.rs index 7db02c3cd7..5a027f892b 100644 --- a/crates/ide-workspace/src/recent.rs +++ b/crates/ide-workspace/src/recent.rs @@ -162,6 +162,127 @@ fn is_missing(path: &Path) -> bool { path.is_absolute() && !text.contains("://") && !wsl && !path.exists() } +fn folder_name(path: &Path) -> String { + path.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_else(|| path.display().to_string()) +} + +/// What importing a JetBrains IDE's recent projects did (or, as a preview, would do). +#[derive(Clone, Debug, Default, PartialEq, Serialize, Type)] +#[serde(rename_all = "camelCase")] +pub struct JetBrainsRecentImport { + /// Projects added to the recent projects. + pub imported: u32, + /// Projects left out because their folder no longer exists. + pub missing: u32, + /// Project groups added. + pub groups: u32, +} + +/// A recent project as a JetBrains IDE keeps it in `options/recentProjects.xml`. +#[derive(Debug, Default, PartialEq)] +struct JetBrainsRecent { + path: String, + name: Option, + opened_at_ms: f64, + /// Opened but not listed (LightEdit, a file opened alone): the IDE does not show it. + hidden: bool, +} + +#[derive(Debug, Default, PartialEq)] +struct JetBrainsGroup { + name: String, + paths: Vec, + expanded: bool, +} + +/// The `RecentProjectsManager` state: `additionalInfo` entries (path → `RecentProjectMetaInfo`) and +/// `groups` (`ProjectGroup` with `name`, `expanded` and its `projects`). +fn parse_jetbrains_recent(xml: &str) -> (Vec, Vec) { + use quick_xml::{Reader, XmlVersion, events::Event}; + let mut reader = Reader::from_str(xml); + let (mut projects, mut groups) = (Vec::new(), Vec::new()); + let mut project: Option = None; + let mut group: Option = None; + loop { + let (tag, empty) = match reader.read_event() { + Ok(Event::Start(tag)) => (tag, false), + Ok(Event::Empty(tag)) => (tag, true), + Ok(Event::End(tag)) => { + match tag.local_name().as_ref() { + "entry" => projects.extend(project.take()), + "ProjectGroup" => groups.extend(group.take()), + _ => {} + } + continue; + } + Ok(Event::Eof) | Err(_) => break, + _ => continue, + }; + let attr = |key: &str| { + tag.attributes() + .flatten() + .find(|a| a.key.as_ref() == key) + .and_then(|a| a.normalized_value(XmlVersion::Implicit1_0).ok().map(|v| v.into_owned())) + }; + match tag.local_name().as_ref() { + "entry" if !empty && group.is_none() => { + project = attr("key").map(|path| JetBrainsRecent { path, ..Default::default() }); + } + "RecentProjectMetaInfo" => { + if let Some(p) = &mut project { + p.hidden = attr("hidden").as_deref() == Some("true"); + } + } + "ProjectGroup" if !empty => group = Some(JetBrainsGroup::default()), + "option" => { + let (name, value) = (attr("name"), attr("value")); + if let Some(g) = &mut group { + match (name.as_deref(), value) { + (Some("name"), Some(v)) => g.name = v, + (Some("expanded"), Some(v)) => g.expanded = v == "true", + // `