diff --git a/crates/ide-build/src/gradle_deps.rs b/crates/ide-build/src/gradle_deps.rs index 109fea96f..6f634ba95 100644 --- a/crates/ide-build/src/gradle_deps.rs +++ b/crates/ide-build/src/gradle_deps.rs @@ -1,13 +1,16 @@ //! A Gradle project's resolved dependencies for the Dependency Analyzer: //! `gradle :dependencies --configuration `, parsed from its tree report. +//! The reports it read are kept per build ([`save_gradle_report`]) until a build file +//! changes, for readers that must not run Gradle themselves (plugins). use crate::gradle; use crate::process; -use crate::sync::{SyncOptions, error_summary}; +use crate::sync::{self, SyncOptions, error_summary}; use ide_core::{CancellationToken, IdeError, IdeResult}; use serde::{Deserialize, Serialize}; use specta::Type; use std::path::Path; +use std::sync::Mutex; /// One line of the report: an occurrence of a dependency where it is requested. #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Type)] @@ -158,6 +161,54 @@ pub fn gradle_dependencies( Ok(parse_report(&out.text)) } +/// A `dependencies` report of one project of a build for one configuration. +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +pub struct GradleReport { + /// Gradle path of the project (`:`, `:app`). + pub project: String, + pub configuration: String, + pub dependencies: Vec, +} + +#[derive(Default, Serialize, Deserialize)] +struct ReportCache { + /// The build files the reports were read with ([`sync::hash_gradle_files`]). + hash: String, + reports: Vec, +} + +const REPORT_CACHE: &str = "gradle-dependencies.json"; + +/// Keeps `report` with the build's other reports (`cache_dir` is the build's cache +/// directory), replacing an earlier one of the same project and configuration. Reports +/// read before a build file changed are dropped. +pub fn save_gradle_report( + root: &Path, + cache_dir: &Path, + model: &gradle::GradleModel, + report: &GradleReport, +) -> IdeResult<()> { + // Reports of several configurations may finish together: one read-modify-write at a time. + static SAVING: Mutex<()> = Mutex::new(()); + let _saving = SAVING.lock().unwrap_or_else(|e| e.into_inner()); + let hash = sync::hash_gradle_files(&gradle::build_files(root, model)); + let mut cache = sync::read_cache::(cache_dir, REPORT_CACHE) + .filter(|c| c.hash == hash) + .unwrap_or_else(|| ReportCache { hash, reports: Vec::new() }); + cache.reports.retain(|r| (&r.project, &r.configuration) != (&report.project, &report.configuration)); + cache.reports.push(report.clone()); + sync::write_cache(cache_dir, REPORT_CACHE, &cache) +} + +/// The reports kept for the build, unless a build file changed since they were read. +pub fn gradle_reports(root: &Path, cache_dir: &Path, model: &gradle::GradleModel) -> Vec { + let Some(cache) = sync::read_cache::(cache_dir, REPORT_CACHE) else { return Vec::new() }; + if cache.hash != sync::hash_gradle_files(&gradle::build_files(root, model)) { + return Vec::new(); + } + cache.reports +} + #[cfg(test)] mod tests { use super::*; @@ -234,6 +285,37 @@ runtimeClasspath - Runtime classpath of source set 'main'. ); } + #[test] + fn reports_are_kept_per_project_and_configuration_until_a_build_file_changes() { + let tmp = tempfile::tempdir().unwrap(); + let root = tmp.path(); + let cache = root.join("cache"); + std::fs::write(root.join("settings.gradle"), "include 'app'").unwrap(); + std::fs::write(root.join("build.gradle"), "").unwrap(); + let model = gradle::load(root).unwrap(); + assert!(gradle_reports(root, &cache, &model).is_empty()); + let report = |project: &str, configuration: &str, version: &str| GradleReport { + project: project.into(), + configuration: configuration.into(), + dependencies: vec![dep("org.a", "b", Some(version))], + }; + save_gradle_report(root, &cache, &model, &report(":app", "runtimeClasspath", "1.0")).unwrap(); + save_gradle_report(root, &cache, &model, &report(":app", "compileClasspath", "1.0")).unwrap(); + // Reading a report again replaces what was read before. + save_gradle_report(root, &cache, &model, &report(":app", "runtimeClasspath", "2.0")).unwrap(); + assert_eq!( + gradle_reports(root, &cache, &model), + [report(":app", "compileClasspath", "1.0"), report(":app", "runtimeClasspath", "2.0")] + ); + // A comment changes nothing Gradle reads; a dependency does. + std::fs::write(root.join("build.gradle"), "// notes").unwrap(); + assert_eq!(gradle_reports(root, &cache, &model).len(), 2); + std::fs::write(root.join("build.gradle"), "dependencies { implementation 'org.a:b:3.0' }").unwrap(); + assert!(gradle_reports(root, &cache, &model).is_empty()); + save_gradle_report(root, &cache, &model, &report(":", "compileClasspath", "3.0")).unwrap(); + assert_eq!(gradle_reports(root, &cache, &model), [report(":", "compileClasspath", "3.0")]); + } + #[cfg(unix)] #[test] fn runs_the_report_of_the_project_and_configuration() { diff --git a/crates/ide-build/src/lib.rs b/crates/ide-build/src/lib.rs index 94f385c60..9c48e468c 100644 --- a/crates/ide-build/src/lib.rs +++ b/crates/ide-build/src/lib.rs @@ -19,7 +19,7 @@ pub mod web; mod xml; pub use gradle::{GradleModel, GradleProject, GradleTask}; -pub use gradle_deps::{GradleDependency, gradle_dependencies}; +pub use gradle_deps::{GradleDependency, GradleReport, gradle_dependencies, gradle_reports, save_gradle_report}; pub use maven::{MavenDependency, MavenModel, MavenPlugin, MavenProfile, MavenProject, Omission}; pub use sbt::{SbtBuild, SbtProject}; pub use sync::{ diff --git a/crates/ide-build/src/sync.rs b/crates/ide-build/src/sync.rs index 2d437101a..a72c33014 100644 --- a/crates/ide-build/src/sync.rs +++ b/crates/ide-build/src/sync.rs @@ -136,11 +136,11 @@ pub fn save_maven_profiles(cache_dir: &Path, profiles: &[String]) -> IdeResult(dir: &Path, name: &str) -> Option { +pub(crate) fn read_cache(dir: &Path, name: &str) -> Option { serde_json::from_slice(&std::fs::read(dir.join(name)).ok()?).ok() } -fn write_cache(dir: &Path, name: &str, value: &T) -> IdeResult<()> { +pub(crate) fn write_cache(dir: &Path, name: &str, value: &T) -> IdeResult<()> { std::fs::create_dir_all(dir)?; let json = serde_json::to_vec(value).map_err(|e| IdeError::internal(e.to_string()))?; let tmp = dir.join(format!("{name}.tmp")); @@ -156,7 +156,7 @@ fn hash_files(files: &[PathBuf]) -> String { /// Like IDEA's auto-import CRC: editing a comment or reformatting a build script /// does not make the last sync stale. -fn hash_gradle_files(files: &[PathBuf]) -> String { +pub(crate) fn hash_gradle_files(files: &[PathBuf]) -> String { hash_contents(files, |f| { let text = std::fs::read_to_string(f).unwrap_or_default(); let script = f.extension().is_some_and(|e| e == "gradle" || e == "kts"); diff --git a/crates/ide-extension/src/capability.rs b/crates/ide-extension/src/capability.rs index ae314fb19..9b8ddc55b 100644 --- a/crates/ide-extension/src/capability.rs +++ b/crates/ide-extension/src/capability.rs @@ -26,6 +26,8 @@ pub enum Capability { DatabaseSources, VcsRead, VcsWrite, + /// The Maven / Gradle dependency graph the IDE resolved. + BuildRead, /// The plugin's own key-value store and data directory. Storage, /// The plugin's own secrets (kept in the client's OS keychain). @@ -75,7 +77,9 @@ pub enum Risk { impl Capability { pub fn risk(&self) -> Risk { match self { - Self::ProjectRead | Self::EditorRead | Self::Storage | Self::Events | Self::VcsRead => Risk::Low, + Self::ProjectRead | Self::EditorRead | Self::Storage | Self::Events | Self::VcsRead | Self::BuildRead => { + Risk::Low + } Self::EditorWrite | Self::DatabaseSources | Self::VcsWrite @@ -115,6 +119,7 @@ impl Capability { Self::IdeCommands => "Run any IDE action or other plugins' commands as if you chose them, including running programs, committing and pushing".into(), Self::VcsRead => "Read version control state".into(), Self::VcsWrite => "Change version control state (commit, fetch, checkout)".into(), + Self::BuildRead => "Read the project's resolved Maven and Gradle dependencies".into(), Self::Storage => "Store its own data".into(), Self::Secrets => "Store secrets in the system keychain".into(), Self::Events => "Observe editor, filesystem and version control events".into(), @@ -251,6 +256,7 @@ impl fmt::Display for Capability { Self::DatabaseSources => f.write_str("database.sources"), Self::VcsRead => f.write_str("vcs.read"), Self::VcsWrite => f.write_str("vcs.write"), + Self::BuildRead => f.write_str("build.read"), Self::Storage => f.write_str("storage"), Self::Secrets => f.write_str("secrets"), Self::Events => f.write_str("events"), @@ -336,6 +342,7 @@ impl FromStr for Capability { "database.sources" => Self::DatabaseSources, "vcs.read" => Self::VcsRead, "vcs.write" => Self::VcsWrite, + "build.read" => Self::BuildRead, "storage" => Self::Storage, "secrets" => Self::Secrets, "events" => Self::Events, @@ -390,6 +397,7 @@ mod tests { "editor.write", "project.write", "vcs.write", + "build.read", "storage", "secrets", "events", @@ -433,6 +441,7 @@ mod tests { assert_eq!(Capability::Clipboard.risk(), Risk::Medium); assert_eq!(Capability::Process("cargo".into()).risk(), Risk::High); assert_eq!(Capability::Lsp("phoxite".into()).risk(), Risk::High); + assert_eq!(Capability::BuildRead.risk(), Risk::Low); assert!(!Capability::Lsp("phoxite".into()).covers(&Capability::Lsp("intelephense".into()))); assert!(Capability::Storage.auto_migrates() && !Capability::EditorWrite.auto_migrates()); assert_eq!(Capability::JavaAgent.risk(), Risk::High); diff --git a/crates/ide-extension/src/manifest.rs b/crates/ide-extension/src/manifest.rs index 2db8c44ab..a08b49c1f 100644 --- a/crates/ide-extension/src/manifest.rs +++ b/crates/ide-extension/src/manifest.rs @@ -360,6 +360,9 @@ impl Manifest { if matches!(cap, Capability::Lsp(_)) { self.needs_api(&format!("capability `{cap}`"), 9)?; } + if matches!(cap, Capability::BuildRead) { + self.needs_api(&format!("capability `{cap}`"), 10)?; + } if matches!(cap, Capability::JavaAgent) { return Err( "`java.agent` comes from `[[contributes.javaAgents]]`: remove it from [capabilities]".into() @@ -735,6 +738,14 @@ required = [\"lsp:phoxite\"] assert_eq!(m.capabilities.required, [Capability::Lsp("phoxite".into())]); } + #[test] + fn the_build_capability_needs_api_1_10() { + let caps = "[capabilities]\noptional = [\"build.read\"]\n"; + assert!(err(&format!("{}{caps}", BASE.replace("^1.2", "^1.9"))).contains("new in plugin API 1.10")); + let m = Manifest::parse(&format!("{}{caps}", BASE.replace("^1.2", "^1.10"))).unwrap(); + assert_eq!(m.capabilities.optional, [Capability::BuildRead]); + } + #[test] fn java_agent_capability_is_not_declared() { for list in ["required", "optional"] { diff --git a/crates/ide-host/src/ops/build.rs b/crates/ide-host/src/ops/build.rs index a0bf843e6..59a7ecd1a 100644 --- a/crates/ide-host/src/ops/build.rs +++ b/crates/ide-host/src/ops/build.rs @@ -467,7 +467,15 @@ pub async fn gradle_dependencies( gradle_command: Some(gradle.command.clone()), ..Default::default() }; - ide_build::gradle_dependencies(&scope.root, gradle, &options, &gradle_path, &configuration, &token) + let dependencies = + ide_build::gradle_dependencies(&scope.root, gradle, &options, &gradle_path, &configuration, &token)?; + // What plugins read of the build (`build.dependencies`) instead of running Gradle. + let report = ide_build::GradleReport { project: gradle_path, configuration, dependencies }; + let cache = ide_build::gradle::cache_dir(&scope.cache, &gradle.dir); + if let Err(e) = ide_build::save_gradle_report(&scope.root, &cache, gradle, &report) { + tracing::debug!("keeping the dependencies report of {}: {e}", report.project); + } + Ok(report.dependencies) }) .await .map_err(join_err); @@ -475,6 +483,40 @@ pub async fn gradle_dependencies( result? } +/// What the Dependency Analyzer has of the builds of `project` at `root` (the project, or one +/// of its workspace members), without running a build tool: the Maven modules as last synced +/// and the Gradle reports read since the build files last changed. +pub(crate) fn analyzed_dependencies( + project: &Project, + config: &Path, + root: &Path, +) -> IdeResult { + let mut graph = crate::plugins::BuildGraph::default(); + for scope in workspace::scopes(project, config)?.iter().filter(|s| root == project.root || s.root == root) { + let settings = &scope.settings; + let model = ide_build::load_linked( + &scope.root, + &scope.cache, + ide_sdk::apply::maven_local_repository(&scope.root, settings), + &settings.languages.java.maven, + &settings.languages.java.gradle, + ); + graph.maven.extend(model.maven.into_iter().flat_map(|m| m.projects)); + for build in &model.gradle { + let reports = + ide_build::gradle_reports(&scope.root, &ide_build::gradle::cache_dir(&scope.cache, &build.dir), build); + // buildSrc can't be analyzed from the build, as in the Dependency Analyzer. + for p in build.projects.iter().filter(|p| !p.build.as_deref().is_some_and(|b| b.ends_with(":buildSrc"))) { + graph.gradle.push(crate::plugins::GradleModule { + path: p.path.clone(), + reports: reports.iter().filter(|r| r.project == p.path).cloned().collect(), + }); + } + } + } + Ok(graph) +} + /// Where the direct dependency `dependency` of the Maven module `pom` is declared. pub async fn maven_dependency_declaration( host: &Host, diff --git a/crates/ide-host/src/plugins/api.rs b/crates/ide-host/src/plugins/api.rs index c6fc0d49d..a7d39a8ed 100644 --- a/crates/ide-host/src/plugins/api.rs +++ b/crates/ide-host/src/plugins/api.rs @@ -112,6 +112,11 @@ pub trait PluginWorkspace: Send + Sync { ) -> Result { Err(HostError::NotFound(format!("no language server `{server}` is running for this project"))) } + /// What the IDE has resolved of the Maven / Gradle builds of the project at `root`; + /// never runs a build tool. + fn build_graph(&self, _root: &Path) -> Result { + Ok(super::BuildGraph::default()) + } /// Current index of the project rooted at `root`; never reads disk or calls LSP. fn symbols( &self, @@ -2224,6 +2229,20 @@ impl HostApi for PluginApi { Ok(result.to_string()) } + fn build_dependencies( + &self, + root: &Path, + module: Option<&str>, + ) -> Result, HostError> { + self.require_api("`build`", 10)?; + let workspace = self.shared.workspace().ok_or_else(|| HostError::NotFound("no project is open".into()))?; + // The graph comes from running the project's build, as `vcs.read` does git. + if !workspace.trusted(root) { + return Err(HostError::Denied("project is not trusted".into())); + } + super::build_graph::dependency_nodes(&workspace.build_graph(root)?, module) + } + fn find_files(&self, root: &Path, glob: &str, limit: usize) -> Result, HostError> { let matcher = globset::GlobBuilder::new(glob) .literal_separator(true) @@ -3374,6 +3393,13 @@ impl PluginWorkspace for HostWorkspace { }) } + fn build_graph(&self, root: &Path) -> Result { + let host = self.0.upgrade().ok_or(HostError::Cancelled)?; + let project = HostWorkspace::project_covering(self, root) + .ok_or_else(|| HostError::NotFound("the project is no longer open".into()))?; + crate::ops::build::analyzed_dependencies(&project, &host.config_dir, root).map_err(failed) + } + fn trusted(&self, root: &Path) -> bool { // A workspace member is as trusted as the group's project it was opened with. HostWorkspace::project_covering(self, root).is_some_and(|p| p.is_trusted()) diff --git a/crates/ide-host/src/plugins/build_graph.rs b/crates/ide-host/src/plugins/build_graph.rs new file mode 100644 index 000000000..f79f11e4e --- /dev/null +++ b/crates/ide-host/src/plugins/build_graph.rs @@ -0,0 +1,337 @@ +//! `build.dependencies`: the Dependency Analyzer's Maven / Gradle trees as the flat +//! list the plugin API passes (records can't nest), each module a root. + +use ide_build::{GradleDependency, GradleReport, MavenDependency, MavenProject, Omission}; +use ide_plugin::{DependencyNode, DependencyStatus, HostError}; + +/// Most nodes one call returns. +const MAX_NODES: usize = 100_000; + +/// What the IDE has resolved of a project's builds, without running a build tool. +#[derive(Clone, Debug, Default)] +pub struct BuildGraph { + /// Maven modules with their dependencies (with the transitive ones after a sync). + pub maven: Vec, + pub gradle: Vec, +} + +/// A Gradle project and the reports the Dependency Analyzer read for it. +#[derive(Clone, Debug, Default)] +pub struct GradleModule { + /// Gradle path (`:`, `:app`). + pub path: String, + /// One per configuration read. + pub reports: Vec, +} + +/// The graph of `module` (a Maven `groupId:artifactId` or a Gradle path), or of every module. +pub fn dependency_nodes(graph: &BuildGraph, module: Option<&str>) -> Result, HostError> { + let mut out = Nodes(Vec::new()); + let mut found = false; + for p in graph.maven.iter().filter(|p| module.is_none_or(|m| m == p.key())) { + found = true; + let root = out.push(DependencyNode { + group: p.group_id.clone(), + artifact: p.artifact_id.clone(), + version: p.version.clone(), + scope: String::new(), + status: DependencyStatus::Resolved, + requested_version: None, + parent: None, + })?; + out.maven(&p.dependencies, root)?; + } + for g in graph.gradle.iter().filter(|g| module.is_none_or(|m| m == g.path)) { + found = true; + let root = out.push(DependencyNode { + group: String::new(), + artifact: g.path.clone(), + version: String::new(), + scope: String::new(), + status: DependencyStatus::Resolved, + requested_version: None, + parent: None, + })?; + for report in &g.reports { + out.gradle(&report.dependencies, &report.configuration, root)?; + } + } + match module { + Some(m) if !found => Err(HostError::NotFound(format!("no Maven or Gradle module `{m}` in this project"))), + _ => Ok(out.0), + } +} + +struct Nodes(Vec); + +impl Nodes { + fn push(&mut self, node: DependencyNode) -> Result { + if self.0.len() >= MAX_NODES { + return Err(HostError::Failed(format!( + "the dependency graph has more than {MAX_NODES} nodes; ask for one module" + ))); + } + self.0.push(node); + Ok((self.0.len() - 1) as u32) + } + + fn maven(&mut self, deps: &[MavenDependency], parent: u32) -> Result<(), HostError> { + for d in deps { + let version = d.version.clone().unwrap_or_default(); + let (status, version, requested) = match d.omitted { + // `version` lost to `conflict_with`. + Some(Omission::Conflict) => ( + DependencyStatus::OmittedForConflict, + d.conflict_with.clone().unwrap_or_else(|| version.clone()), + Some(version), + ), + Some(Omission::Duplicate | Omission::Cycle) => { + (DependencyStatus::OmittedForDuplicate, version, d.managed_from.clone()) + } + None if d.managed_from.is_some() => (DependencyStatus::VersionManaged, version, d.managed_from.clone()), + None => (DependencyStatus::Resolved, version, None), + }; + let index = self.push(DependencyNode { + group: d.group_id.clone(), + artifact: d.artifact_id.clone(), + requested_version: requested.filter(|r| *r != version), + version, + scope: d.scope.clone(), + status, + parent: Some(parent), + })?; + self.maven(&d.children, index)?; + } + Ok(()) + } + + fn gradle(&mut self, deps: &[GradleDependency], configuration: &str, parent: u32) -> Result<(), HostError> { + // A constraint is not a dependency: it occurs as one elsewhere in the tree. + for d in deps.iter().filter(|d| !d.constraint) { + let (status, version, requested) = if d.project || d.unresolved { + (DependencyStatus::Resolved, String::new(), None) + } else { + match (&d.requested, &d.selected) { + (_, None) => (DependencyStatus::Resolved, d.requested.clone().unwrap_or_default(), None), + // A platform or a constraint supplies the version. + (None, Some(selected)) => (DependencyStatus::VersionManaged, selected.clone(), None), + // Conflict resolution picked another version than this exact request. + (Some(requested), Some(selected)) if exact_version(requested) => { + (DependencyStatus::OmittedForConflict, selected.clone(), Some(requested.clone())) + } + // A range or a rich version (`1.+`, `{strictly 2.0}`) resolved as asked. + (Some(requested), Some(selected)) => { + (DependencyStatus::Resolved, selected.clone(), Some(requested.clone())) + } + } + }; + let status = if d.repeated && status == DependencyStatus::Resolved { + DependencyStatus::OmittedForDuplicate + } else { + status + }; + let index = self.push(DependencyNode { + group: d.group.clone(), + artifact: d.name.clone(), + requested_version: requested.filter(|r| *r != version), + version, + scope: configuration.to_owned(), + status, + parent: Some(parent), + })?; + self.gradle(&d.children, configuration, index)?; + } + Ok(()) + } +} + +/// `1.2.3`, not a range, dynamic or rich version (`[1,2)`, `1.+`, `latest.release`, `{strictly 1}`). +fn exact_version(v: &str) -> bool { + !v.is_empty() && !v.starts_with("latest.") && !v.contains(['[', ']', '(', ')', ',', '+', '{', '}', ' ']) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn maven(group: &str, artifact: &str, version: &str, scope: &str) -> MavenDependency { + MavenDependency { + group_id: group.into(), + artifact_id: artifact.into(), + version: Some(version.into()), + kind: "jar".into(), + scope: scope.into(), + ..Default::default() + } + } + + fn gradle(group: &str, name: &str, requested: Option<&str>, selected: Option<&str>) -> GradleDependency { + GradleDependency { + group: group.into(), + name: name.into(), + requested: requested.map(Into::into), + selected: selected.map(Into::into), + ..Default::default() + } + } + + /// (group, artifact, version, scope, status, requested, parent) of every node. + type Row<'a> = (&'a str, &'a str, &'a str, &'a str, DependencyStatus, Option<&'a str>, Option); + + fn rows(nodes: &[DependencyNode]) -> Vec> { + nodes + .iter() + .map(|n| { + ( + n.group.as_str(), + n.artifact.as_str(), + n.version.as_str(), + n.scope.as_str(), + n.status, + n.requested_version.as_deref(), + n.parent, + ) + }) + .collect() + } + + fn graph() -> BuildGraph { + let mut lang3_lost = maven("org.apache.commons", "commons-lang3", "3.12.0", "compile"); + lang3_lost.omitted = Some(Omission::Conflict); + lang3_lost.conflict_with = Some("3.14.0".into()); + let mut text = maven("org.apache.commons", "commons-text", "1.11.0", "compile"); + text.children = vec![lang3_lost]; + let mut logging = maven("commons-logging", "commons-logging", "1.3.0", "compile"); + logging.managed_from = Some("1.2".into()); + let mut junit_again = maven("junit", "junit", "4.13.2", "test"); + junit_again.omitted = Some(Omission::Duplicate); + let mut hamcrest = maven("org.hamcrest", "hamcrest", "2.2", "test"); + hamcrest.children = vec![junit_again]; + let app = MavenProject { + group_id: "com.example".into(), + artifact_id: "app".into(), + version: "1.0".into(), + dependencies: vec![ + maven("org.apache.commons", "commons-lang3", "3.14.0", "compile"), + text, + logging, + hamcrest, + ], + ..Default::default() + }; + let mut databind = gradle("com.fasterxml.jackson.core", "jackson-databind", Some("2.15.0"), Some("2.15.3")); + databind.repeated = true; + let mut web = gradle("org.springframework.boot", "spring-boot-starter-web", None, Some("3.2.0")); + web.children = vec![databind]; + let mut constraint = gradle("com.google.guava", "guava", Some("32.1.3-jre"), None); + constraint.constraint = true; + let mut core = gradle("", ":core", None, None); + core.project = true; + core.children = vec![constraint]; + let mut failed = gradle("org.missing", "gone", Some("9"), None); + failed.unresolved = true; + let report = GradleReport { + project: ":web".into(), + configuration: "runtimeClasspath".into(), + dependencies: vec![ + web, + core, + gradle("org.slf4j", "slf4j-api", Some("2.+"), Some("2.0.13")), + gradle("org.yaml", "snakeyaml", Some("2.2"), None), + failed, + ], + }; + BuildGraph { + maven: vec![app], + gradle: vec![ + GradleModule { path: ":web".into(), reports: vec![report] }, + GradleModule { path: ":".into(), reports: Vec::new() }, + ], + } + } + + #[test] + fn modules_are_roots_with_their_trees_flattened_under_them() { + use DependencyStatus::*; + let nodes = dependency_nodes(&graph(), None).unwrap(); + assert_eq!( + rows(&nodes), + [ + ("com.example", "app", "1.0", "", Resolved, None, None), + ("org.apache.commons", "commons-lang3", "3.14.0", "compile", Resolved, None, Some(0)), + ("org.apache.commons", "commons-text", "1.11.0", "compile", Resolved, None, Some(0)), + ( + "org.apache.commons", + "commons-lang3", + "3.14.0", + "compile", + OmittedForConflict, + Some("3.12.0"), + Some(2) + ), + ("commons-logging", "commons-logging", "1.3.0", "compile", VersionManaged, Some("1.2"), Some(0)), + ("org.hamcrest", "hamcrest", "2.2", "test", Resolved, None, Some(0)), + ("junit", "junit", "4.13.2", "test", OmittedForDuplicate, None, Some(5)), + ("", ":web", "", "", Resolved, None, None), + ( + "org.springframework.boot", + "spring-boot-starter-web", + "3.2.0", + "runtimeClasspath", + VersionManaged, + None, + Some(7) + ), + ( + "com.fasterxml.jackson.core", + "jackson-databind", + "2.15.3", + "runtimeClasspath", + OmittedForConflict, + Some("2.15.0"), + Some(8) + ), + ("", ":core", "", "runtimeClasspath", Resolved, None, Some(7)), + ("org.slf4j", "slf4j-api", "2.0.13", "runtimeClasspath", Resolved, Some("2.+"), Some(7)), + ("org.yaml", "snakeyaml", "2.2", "runtimeClasspath", Resolved, None, Some(7)), + ("org.missing", "gone", "", "runtimeClasspath", Resolved, None, Some(7)), + ("", ":", "", "", Resolved, None, None), + ] + ); + } + + #[test] + fn one_module_by_its_maven_key_or_gradle_path() { + let maven = dependency_nodes(&graph(), Some("com.example:app")).unwrap(); + assert_eq!((maven.len(), maven[0].artifact.as_str()), (7, "app")); + let gradle = dependency_nodes(&graph(), Some(":web")).unwrap(); + assert_eq!((gradle.len(), gradle[0].artifact.as_str(), gradle[1].parent), (7, ":web", Some(0))); + // A Gradle project with no report read yet is known, with nothing under it. + assert_eq!(dependency_nodes(&graph(), Some(":")).unwrap().len(), 1); + let err = dependency_nodes(&graph(), Some("app")).unwrap_err(); + assert!(matches!(err, HostError::NotFound(_)), "{err:?}"); + assert!(dependency_nodes(&BuildGraph::default(), None).unwrap().is_empty()); + } + + #[test] + fn a_graph_too_large_for_one_call_fails() { + let app = MavenProject { + group_id: "g".into(), + artifact_id: "a".into(), + dependencies: vec![maven("g", "d", "1", "compile"); MAX_NODES], + ..Default::default() + }; + let graph = BuildGraph { maven: vec![app], gradle: Vec::new() }; + assert!(matches!(dependency_nodes(&graph, None), Err(HostError::Failed(_)))); + } + + #[test] + fn exact_versions() { + for v in ["1.0", "32.1.3-jre", "2.15.0"] { + assert!(exact_version(v), "{v}"); + } + for v in ["", "1.+", "[1.0,2.0)", "latest.release", "{strictly 1.0}"] { + assert!(!exact_version(v), "{v}"); + } + } +} diff --git a/crates/ide-host/src/plugins/mod.rs b/crates/ide-host/src/plugins/mod.rs index f8da780ae..cb1841118 100644 --- a/crates/ide-host/src/plugins/mod.rs +++ b/crates/ide-host/src/plugins/mod.rs @@ -17,6 +17,7 @@ mod api; mod auth; +mod build_graph; pub mod commands; pub mod commit; mod database; @@ -59,6 +60,7 @@ pub mod web; mod websocket; pub use api::{FileSecretStore, HostWorkspace, PluginWorkspace, SecretStore}; +pub use build_graph::{BuildGraph, GradleModule}; pub(crate) use hover::merge as merge_hover; pub use icons::{ MAX_PLUGIN_ICON, map_asset as icon_theme_map_asset, plugin_icon, sanitize_svg, svg_prefix as icon_theme_svg_prefix, diff --git a/crates/ide-host/tests/plugins.rs b/crates/ide-host/tests/plugins.rs index 84e6cc6ab..d9772fc58 100644 --- a/crates/ide-host/tests/plugins.rs +++ b/crates/ide-host/tests/plugins.rs @@ -196,6 +196,41 @@ impl PluginWorkspace for TestWorkspace { self.server_messages.lock().push((method.into(), params.clone(), notify)); Ok(if notify { serde_json::Value::Null } else { serde_json::json!({ "method": method, "params": params }) }) } + /// A Maven module with a lost version conflict, and a Gradle project with one report. + fn build_graph(&self, _root: &Path) -> Result { + let dep = |artifact: &str, version: &str| ide_build::MavenDependency { + group_id: "org.apache.commons".into(), + artifact_id: artifact.into(), + version: Some(version.into()), + scope: "compile".into(), + ..Default::default() + }; + let mut text = dep("commons-text", "1.11.0"); + text.children = vec![ide_build::MavenDependency { + omitted: Some(ide_build::Omission::Conflict), + conflict_with: Some("3.14.0".into()), + ..dep("commons-lang3", "3.12.0") + }]; + let app = ide_build::MavenProject { + group_id: "com.example".into(), + artifact_id: "app".into(), + version: "1.0".into(), + dependencies: vec![text], + ..Default::default() + }; + let snakeyaml = ide_build::GradleDependency { + group: "org.yaml".into(), + name: "snakeyaml".into(), + requested: Some("2.2".into()), + ..Default::default() + }; + let report = ide_build::GradleReport { + project: ":web".into(), + configuration: "runtimeClasspath".into(), + dependencies: vec![snakeyaml], + }; + Ok(BuildGraph { maven: vec![app], gradle: vec![GradleModule { path: ":web".into(), reports: vec![report] }] }) + } fn project_windows(&self, root: &Path) -> Vec { // `main` shows the fixture project; other open roots have no window left. if root == self.root { vec!["closing".into(), "main".into()] } else { Vec::new() } @@ -7076,6 +7111,59 @@ fn the_language_server_grant_needs_api_1_9() { assert!(err.message.contains("new in plugin API 1.9"), "{err:?}"); } +/// `build.dependencies` hands a plugin the resolved Maven / Gradle graph as a flat list, each +/// module a root, with `build.read` in a trusted project (API 1.10). +#[test] +fn build_dependencies_need_the_grant_and_a_trusted_project() { + let f = fixture(Limits::default()); + let id = "test.build-graph"; + let info = f.install(&sample("build-graph")); + assert!(info.capabilities.iter().any(|c| c.id == "build.read" && c.granted && c.risk == ide_extension::Risk::Low)); + + // `parent group:artifact:version scope status requested`, as the fixture prints them. + assert_eq!( + f.run(id, "dependencies", None).unwrap().unwrap(), + "- com.example:app:1.0 resolved -\n\ + 0 org.apache.commons:commons-text:1.11.0 compile resolved -\n\ + 1 org.apache.commons:commons-lang3:3.14.0 compile conflict 3.12.0\n\ + - ::web: resolved -\n\ + 3 org.yaml:snakeyaml:2.2 runtimeClasspath resolved -" + ); + assert_eq!( + f.run(id, "dependencies", Some(":web")).unwrap().unwrap(), + "- ::web: resolved -\n0 org.yaml:snakeyaml:2.2 runtimeClasspath resolved -" + ); + let err = f.host.run_command(id, "dependencies", Some("app"), f.inv()).unwrap_err(); + assert_eq!(err.kind, ErrorKind::NotFound, "{err:?}"); + + f.host.set_capability(id, "build.read", false).unwrap(); + let err = f.host.run_command(id, "dependencies", None, f.inv()).unwrap_err(); + assert_eq!(err.kind, ErrorKind::PermissionDenied, "{err:?}"); + assert!(err.message.contains("build.read"), "{err:?}"); + f.host.set_capability(id, "build.read", true).unwrap(); + + // The graph comes from running the project's build: not in an untrusted project. + let mut untrusted = TestWorkspace::new(&f.project); + Arc::get_mut(&mut untrusted).unwrap().trusted = false; + f.host.set_workspace(Some(untrusted)); + let err = f.host.run_command(id, "dependencies", None, f.inv()).unwrap_err(); + assert_eq!(err.kind, ErrorKind::PermissionDenied, "{err:?}"); + assert_eq!(f.host.info_of(id).unwrap().stats.crashes, 0); +} + +/// The grant is new in API 1.10: an older `engines.openidea` can't ask for it. +#[test] +fn the_build_grant_needs_api_1_10() { + let f = fixture(Limits::default()); + let tmp = tempfile::tempdir().unwrap(); + let pkg = tmp.path().join("build-graph"); + copy_dir(&sample("build-graph"), &pkg); + let manifest = std::fs::read_to_string(pkg.join("plugin.toml")).unwrap(); + std::fs::write(pkg.join("plugin.toml"), manifest.replace("\"^1.10\"", "\"^1.9\"")).unwrap(); + let err = f.host.install_from_dir(&pkg, &Consent::all()).unwrap_err(); + assert!(err.message.contains("new in plugin API 1.10"), "{err:?}"); +} + /// The UI's synthetic post-install `SettingsChanged([])` reaches a plugin that /// subscribes to `on-event:settings-changed`, though it carries no keys. #[test] diff --git a/crates/ide-plugin/src/runtime.rs b/crates/ide-plugin/src/runtime.rs index d95af157c..33f86a8cd 100644 --- a/crates/ide-plugin/src/runtime.rs +++ b/crates/ide-plugin/src/runtime.rs @@ -117,6 +117,13 @@ pub trait HostApi: Send + Sync { let _ = (root, method, params, notify, cancel, timeout); Err(HostError::NotFound(format!("no language server `{server}` is running for this project"))) } + /// The flat dependency graph of the Maven / Gradle builds of the project at `root` + /// (of the module `module` only, when given), as the IDE last resolved it; never runs + /// a build tool. + fn build_dependencies(&self, root: &Path, module: Option<&str>) -> Result, HostError> { + let _ = (root, module); + Err(HostError::Failed("build data is unavailable on this host".into())) + } /// Stdio argv only; no URL or bearer token. fn mcp_stdio_command(&self, client: &str) -> Option> { let _ = client; diff --git a/crates/ide-plugin/src/types.rs b/crates/ide-plugin/src/types.rs index 18c578975..d09d5afd8 100644 --- a/crates/ide-plugin/src/types.rs +++ b/crates/ide-plugin/src/types.rs @@ -959,6 +959,28 @@ pub struct BlameLine { pub summary: String, } +/// How an occurrence in a build's dependency graph was resolved (API 1.10). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum DependencyStatus { + Resolved, + OmittedForConflict, + OmittedForDuplicate, + VersionManaged, +} + +/// One occurrence in the flat dependency graph of `build.dependencies` (API 1.10); +/// `parent` indexes the list. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct DependencyNode { + pub group: String, + pub artifact: String, + pub version: String, + pub scope: String, + pub status: DependencyStatus, + pub requested_version: Option, + pub parent: Option, +} + /// Non-secret settings of a plugin-owned project database source (API 1.4). #[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/crates/ide-plugin/src/wit_host.rs b/crates/ide-plugin/src/wit_host.rs index fd7f4dc2b..df618fe54 100644 --- a/crates/ide-plugin/src/wit_host.rs +++ b/crates/ide-plugin/src/wit_host.rs @@ -48,6 +48,7 @@ pub(crate) mod syntax_bindings { "openidea:plugin/decorations": super::bindings::openidea::plugin::decorations, "openidea:plugin/invocation": super::bindings::openidea::plugin::invocation, "openidea:plugin/vcs": super::bindings::openidea::plugin::vcs, + "openidea:plugin/build": super::bindings::openidea::plugin::build, "openidea:plugin/commit": super::bindings::openidea::plugin::commit, "openidea:plugin/events": super::bindings::openidea::plugin::events, "openidea:plugin/tasks": super::bindings::openidea::plugin::tasks, @@ -87,6 +88,7 @@ pub(crate) mod providers_bindings { "openidea:plugin/decorations": super::bindings::openidea::plugin::decorations, "openidea:plugin/invocation": super::bindings::openidea::plugin::invocation, "openidea:plugin/vcs": super::bindings::openidea::plugin::vcs, + "openidea:plugin/build": super::bindings::openidea::plugin::build, "openidea:plugin/commit": super::bindings::openidea::plugin::commit, "openidea:plugin/events": super::bindings::openidea::plugin::events, "openidea:plugin/tasks": super::bindings::openidea::plugin::tasks, @@ -126,6 +128,7 @@ pub(crate) mod views_bindings { "openidea:plugin/decorations": super::bindings::openidea::plugin::decorations, "openidea:plugin/invocation": super::bindings::openidea::plugin::invocation, "openidea:plugin/vcs": super::bindings::openidea::plugin::vcs, + "openidea:plugin/build": super::bindings::openidea::plugin::build, "openidea:plugin/commit": super::bindings::openidea::plugin::commit, "openidea:plugin/events": super::bindings::openidea::plugin::events, "openidea:plugin/tasks": super::bindings::openidea::plugin::tasks, @@ -150,8 +153,8 @@ pub(crate) mod views_bindings { } use bindings::openidea::plugin::{ - commit, detail_types, diagnostics, editor, events, fs, invocation, ipc, log, net, process, secrets, settings, - storage, tasks, types as wit, ui, vcs, views, workspace, + build, commit, detail_types, diagnostics, editor, events, fs, invocation, ipc, log, net, process, secrets, + settings, storage, tasks, types as wit, ui, vcs, views, workspace, }; /// A project handle: its root. @@ -1192,6 +1195,44 @@ impl vcs::Host for StoreData { } } +impl build::Host for StoreData { + fn dependencies( + &mut self, + project: Resource, + module: Option, + ) -> Fallible> { + if let Err(e) = self.require(Capability::BuildRead) { + return Ok(Err(e)); + } + let root = self.table.get(&project)?.root.clone(); + Ok(self + .host + .build_dependencies(&root, module.as_deref()) + .map(|nodes| { + nodes + .into_iter() + .map(|n| build::DependencyNode { + group: n.group, + artifact: n.artifact, + version: n.version, + scope: n.scope, + status: match n.status { + crate::DependencyStatus::Resolved => build::DependencyStatus::Resolved, + crate::DependencyStatus::OmittedForConflict => build::DependencyStatus::OmittedForConflict, + crate::DependencyStatus::OmittedForDuplicate => { + build::DependencyStatus::OmittedForDuplicate + } + crate::DependencyStatus::VersionManaged => build::DependencyStatus::VersionManaged, + }, + requested_version: n.requested_version, + parent: n.parent, + }) + .collect() + }) + .map_err(to_wit)) + } +} + impl commit::Host for StoreData { fn pending_commit(&mut self) -> Fallible> { if let Err(e) = self.require(Capability::VcsRead) { diff --git a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm index 02e27f099..0bf2d311d 100644 Binary files a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources index 54bc3031a..083342155 100644 --- a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources @@ -1 +1 @@ -47eb797508a8b7c4f2b8de276656a936cb7b603edf6d5cb0997fd55f06c18d74 +f6069ad2d31b629e4c99fbb800b3bf389ffb87ca7f24fc9cf7803fef68997ef5 diff --git a/crates/ide-plugin/tests/fixtures/build-graph/Cargo.lock b/crates/ide-plugin/tests/fixtures/build-graph/Cargo.lock new file mode 100644 index 000000000..157b47197 --- /dev/null +++ b/crates/ide-plugin/tests/fixtures/build-graph/Cargo.lock @@ -0,0 +1,336 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown", + "serde", + "serde_core", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "macro-string" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e7b3a5bbb2f63aaa223a671ea1bd0e7bc16bd30ce387324cf63995deaddbbd2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "openidea-plugin" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", + "wit-bindgen", +] + +[[package]] +name = "openidea-test-build-graph" +version = "0.1.0" +dependencies = [ + "openidea-plugin", +] + +[[package]] +name = "prettyplease" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bfe0f4c752e450fc2faf62654f1c134747922825d5b04ca717b8874f41a40c0" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "syn" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "wasm-encoder" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4495a6f85dd94c411c749303efcbc5defade0b0cbdbc0541495241ab917a9b5a" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c86ff6668190d9fb70372b306b4f9fe8930f0e2f57ce72e4922bf2f117900949" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "974d643b125b272607e2fff8012ea14a8328acd7621e4bafa7afb32500052b1b" +dependencies = [ + "bitflags", + "hashbrown", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b85a987ab61d365382d25c7d47e26edd48941b3bf6e3fbf76eff918bc71dab06" +dependencies = [ + "bitflags", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e122e390603abfacd548027016cd0113a6e2bf2f8ce6bdd3658b013456ea8" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84e26e13b9d972026778d2ffb7985736de116026fdc8d9464f966e12df2eb240" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a008a0d6b4840677326beb4edbeb210a2f1b7d0183fb7cc33f466b90fd7fb6" +dependencies = [ + "anyhow", + "macro-string", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078def49fdb49cab405c3006e05793b3fdaf7069126ba6b9c97d01ec8c98fe4c" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00f0dc051466ffe46787721fca3d088536f158ae400be044f1b1c386ba9397ad" +dependencies = [ + "anyhow", + "hashbrown", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-ident", + "wasmparser", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/crates/ide-plugin/tests/fixtures/build-graph/Cargo.toml b/crates/ide-plugin/tests/fixtures/build-graph/Cargo.toml new file mode 100644 index 000000000..6d3c09a53 --- /dev/null +++ b/crates/ide-plugin/tests/fixtures/build-graph/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "openidea-test-build-graph" +version = "0.1.0" +edition = "2024" +publish = false + +[workspace] + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +openidea-plugin = { path = "../../../../../sdk/rust/openidea-plugin" } + +[profile.release] +opt-level = "s" +lto = true +strip = true +codegen-units = 1 +panic = "abort" diff --git a/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm new file mode 100644 index 000000000..3046b8aa4 Binary files /dev/null and b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm.sources new file mode 100644 index 000000000..f18844707 --- /dev/null +++ b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm.sources @@ -0,0 +1 @@ +178a2dd60891bfa56a02be322b47dfdbbf22f6e0a50ac56a4b7e4ae1520a821a diff --git a/crates/ide-plugin/tests/fixtures/build-graph/plugin.toml b/crates/ide-plugin/tests/fixtures/build-graph/plugin.toml new file mode 100644 index 000000000..83358bcc4 --- /dev/null +++ b/crates/ide-plugin/tests/fixtures/build-graph/plugin.toml @@ -0,0 +1,12 @@ +id = "test.build-graph" +name = "Build dependency graph fixture" +version = "0.1.0" +engines.openidea = "^1.10" +wasm = "dist/plugin.wasm" + +[capabilities] +optional = ["build.read"] + +[[contributes.commands]] +id = "dependencies" +title = "List the dependency graph of a module, or of every module" diff --git a/crates/ide-plugin/tests/fixtures/build-graph/src/lib.rs b/crates/ide-plugin/tests/fixtures/build-graph/src/lib.rs new file mode 100644 index 000000000..4bdd24006 --- /dev/null +++ b/crates/ide-plugin/tests/fixtures/build-graph/src/lib.rs @@ -0,0 +1,32 @@ +use openidea_plugin::{DependencyStatus, Error, Invocation, Plugin, register_plugin}; + +#[derive(Default)] +struct BuildGraph; + +impl Plugin for BuildGraph { + fn run_command(&mut self, id: &str, inv: &Invocation, arg: Option<&str>) -> Result, Error> { + if id != "dependencies" { + return Err(Error::NotFound(id.into())); + } + let project = inv.project().ok_or("no project")?; + // One line per node: `parent group:artifact:version scope status requested`. + let lines: Vec = project + .build_dependencies(arg.filter(|m| !m.is_empty()))? + .into_iter() + .map(|n| { + let status = match n.status { + DependencyStatus::Resolved => "resolved", + DependencyStatus::OmittedForConflict => "conflict", + DependencyStatus::OmittedForDuplicate => "duplicate", + DependencyStatus::VersionManaged => "managed", + }; + let parent = n.parent.map_or("-".into(), |p| p.to_string()); + let requested = n.requested_version.unwrap_or_else(|| "-".into()); + format!("{parent} {}:{}:{} {} {status} {requested}", n.group, n.artifact, n.version, n.scope) + }) + .collect(); + Ok(Some(lines.join("\n"))) + } +} + +register_plugin!(BuildGraph); diff --git a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm index 67097a44b..a99502f9d 100644 Binary files a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources index 054f36b59..59a7282b4 100644 --- a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources @@ -1 +1 @@ -baabfa459d287fe78389fc5d71951248942902b9cf029ab3782cc929c1ca7bf3 +c39252e48882cb605286f95d1115a3293c191538d7762d1d3ce3afb1bfad814b diff --git a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm index 42cc0c533..7e8087e9d 100644 Binary files a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources index d5915ad80..57fcc2f89 100644 --- a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources @@ -1 +1 @@ -e86a42a3716d37a7e5034d922a097487f3659691dc8879ad16e4efa63e4e030f +0809519ebb56f31b1f00d1e256a6d1af4e1c357990226ef949ac61f1e61989d6 diff --git a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm index 31b707261..79328d0fd 100644 Binary files a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources index 7ceb25758..d35ee9ed1 100644 --- a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources @@ -1 +1 @@ -d5f2d8b20bfbd0f2dbd566dae490645f6f266f0dd87498e5476ead56ca1fe09e +9a9ace3a2818a4cee15f6a20cb0bab96d908090cdcf98a708b4e3558006e224a diff --git a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm index 47b83e39c..006c8418c 100644 Binary files a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources index 494cb0742..92ecbbea8 100644 --- a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources @@ -1 +1 @@ -65748dfb8348c17e464c2378e6b66ae0e30883aee0e1b27130078e3b970c3bf7 +910123140c7d4b354c820088df9adde69916051ebc6cc732bc7847f6d7eb5f52 diff --git a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm index a8d965c4a..6f7639f85 100644 Binary files a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources index 8f18b2c27..cddc0a1fd 100644 --- a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources @@ -1 +1 @@ -2f25d04ba6260c54e1010b310b696428672975c3c0986aab952f534be2783847 +067039e5e40e0c0586277641797557c3f454b44909cd2b008ea46b3b81963686 diff --git a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm index bae6b3f77..536ec685c 100644 Binary files a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources index 0ea527b5f..9803eee17 100644 --- a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources @@ -1 +1 @@ -f2bcf27e33c50fcffd3dcb3a9f7029f4774105b143d881e78b5b1c80b10f04f3 +93bda7983e8597f6b90b9a2877de8e4217451a2cdf47436c525490554f2168d2 diff --git a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm index 3d809ac8c..447fd01ea 100644 Binary files a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources index 2fbfd68e2..a6cecc467 100644 --- a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources @@ -1 +1 @@ -88d11e9fc45c98000f296e46e8105cc83e7fbe6c248a993d82f333caab51e152 +7e27dfe47fa8bd6bf35f0dadf34b66cb84cfcc88f08031c2587d52387611dece diff --git a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm index f31bf1ab0..6ee811fff 100644 Binary files a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources index d979da399..e5f00e797 100644 --- a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources @@ -1 +1 @@ -52768373487be5388e5de2cc577d9c3d74eb0877ecd78a0b641188aed2d18004 +a9ac8f8c212694d1c5cf8fe50772014d5a5dec6a814ef1db9de2178c61263f7f diff --git a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm index 7076883b8..0ba4dfe8e 100644 Binary files a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources index d8408ec6b..1e1c2bae5 100644 --- a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources @@ -1 +1 @@ -63368e7ba560204b6913261bc631579387e42a178cd39d106985ef114a88e54a +20539c87dcf133733139bce6f82971051a6d0c82feac7e9ffe877ac4fc166d94 diff --git a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm index 8c962831a..3af73a380 100644 Binary files a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources index 9d62cb490..ca96ffcbf 100644 --- a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources @@ -1 +1 @@ -6466e46285c132256a03dee9814d3a8f899eab1aaedd389a7087601d2f236bcc +0461c86372899d127238640aa300010111d75a29026a5201ce0f48e77bac26d4 diff --git a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm index 8a861aeff..3a1fd6d30 100644 Binary files a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources index db2cacc4b..64ed1968b 100644 --- a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources @@ -1 +1 @@ -e9fa2ec856fd9c3b19a1a0b233ce55b6e844d0a6f0909018062814eff63c7d6b +d140f25d43a59de5a067fb24ce4831ca01b3f3f83f33d6640fa81d0baa48713e diff --git a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm index 26a944661..a3b1bb410 100644 Binary files a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources index 83d09779a..af46db3fe 100644 --- a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources @@ -1 +1 @@ -26893acfd5486f2df35efb28a1719bf3306118a10b1ad346ad74e4b3318f8258 +37dbfaef6f29c8f6801d180e8083d650ec801a3a550ed1c73fec670dc130143d diff --git a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm index 5eae31d15..4387727d8 100644 Binary files a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources index 1a659b4f4..4ca493b29 100644 --- a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources @@ -1 +1 @@ -b6ebe9a4c121e4a1f6d2b4d932c8e6a89e52ab3bb957dc241fb6087130c9fe56 +01b54df0ad274b7f39d0a2d80fdf9ceec4460d6d360b43323d9e74899cccd99d diff --git a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm index dcf1da710..a63c06186 100644 Binary files a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources index 99e9df9dd..78eb5d19b 100644 --- a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources @@ -1 +1 @@ -a6d0fe560d3492db63fb58a1f898d7090860f2c9dd4dc4e8b97079cd7a97c0b1 +f9ccdb66148b31773199af87956e9564b471ffd987b651f74cbf8430631dc77b diff --git a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm index c070a8335..44eed5341 100644 Binary files a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources index 668e437c9..64c8958e5 100644 --- a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources @@ -1 +1 @@ -3eee2fe2eab305a66a5650dcc9892fed7cc028538d31ab31ed448edbdfa0cdf9 +e14b08260fc0a97300a3b2d2e267e44f0dd85abea3169c9ae1980d0a4f0a63b4 diff --git a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm index 4e7b2252f..f57ddfc41 100644 Binary files a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources index ba164e3d7..4e946858d 100644 --- a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources @@ -1 +1 @@ -3d76b858a8fbf868c36d19897cf85c72e516340eb3e47f27c59b8323dc53b8a3 +fed687bad8c67d8868f94e0cd207541031599e7316150bf0b13d78740e5d0216 diff --git a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm index d9bf2c034..11b0eeeac 100644 Binary files a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources index 89321dfae..6a98f71b3 100644 --- a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources @@ -1 +1 @@ -8d80e89b4b5025c874e467abbea578da52f61a48eeea4573645d362c530fef70 +9a1d344d693d7a3ff1f81778f6f7dc2de211c3213b442aeb65a75b582d5f0019 diff --git a/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm index 9382115ac..65b88439b 100644 Binary files a/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources index 4908dfdc0..0d4ab3ae8 100644 --- a/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources @@ -1 +1 @@ -f052bab94de44b140f957d360f16e6c8dd2bc5d80dd7732b62536b6e74f4e868 +082645a9941796e029e4bc6e400a0b1bdcb8a87b5c2faa0df396359186935093 diff --git a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm index 05266768f..d07e83bad 100644 Binary files a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources index 4e3ae123d..3e77faee7 100644 --- a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources @@ -1 +1 @@ -f9c4279e7972e89fdc0bc1849ed84b72b983b2230526b492110c4de87a843ed0 +f9c0cb4fca66ede5adcb1951dd05c3938c218224cb61e63a574ba08a93f4a041 diff --git a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm index ef8d54c70..fb1a1f4a8 100644 Binary files a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources index d9acd5546..14a06f474 100644 --- a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources @@ -1 +1 @@ -ae0aa9ed34eb508f388fc43b92544ebdd91c3dfcace3c281d0c32b4947ab09ce +43ab17ff2a31fcfe01bd64a068a007a2102ddc2e99010d74c8f640ee65bd064c diff --git a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm index dcc13a629..a06e2bcc8 100644 Binary files a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources index 4b5295384..9937973bb 100644 --- a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources @@ -1 +1 @@ -d75dcfcdb4c2f49e391e21bba9f58567937c8fbc739a853bfed8fce58cd6c753 +751cd3c2403777c8547c9f5081366463e0e8d10428e0319d33ab65c1091c793f diff --git a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm index c05253829..716d2e14c 100644 Binary files a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources index d06b83594..0ce25d069 100644 --- a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources @@ -1 +1 @@ -a25338eaf06fcd417cbd851e8447666ba25214e424c4ba7ee06919d563ff2e88 +7e4a38d17faaccdfd34869f9fa6436a909e08bcf0eb381a45278c72604f33b6b diff --git a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm index 647000e0c..6e5b2f827 100644 Binary files a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources index fecd0794e..68d9175f6 100644 --- a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources @@ -1 +1 @@ -aa9072503d07f0963b115a7ac3b5cdee008d9369263375c9621ba19259647db6 +9bfc5a75f0604912a338b2130bd3923f4c11c016caa7c5904fefc29ce7520688 diff --git a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm index 9296441bb..855e696a0 100644 Binary files a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources index 53b26cb2f..8b6e57b86 100644 --- a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources @@ -1 +1 @@ -ea3b652f16052305b8cfd45216651da96af6603a1c9018bdcb61897e287a6be6 +2ac1d012c8130eeb8a816ab0071f4c3c7d13f264f16dd3bd805f9ec1c22def76 diff --git a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm index 81f954912..f61cdc0ab 100644 Binary files a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources index 74f39e37e..786e2667d 100644 --- a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources @@ -1 +1 @@ -b62841f3469339fcdd3d718963ca3a4a0971a98d770c625334ebb558613f0eb4 +c40bfcba9df10c261e09ec9d3dfe23644da76faa0c1db49327cfbfd8febf0d72 diff --git a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm index 9fb231bfa..2a44057c4 100644 Binary files a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources index c5bb078ad..e2f859e71 100644 --- a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources @@ -1 +1 @@ -535501e8df328c2d340b967de4cf0e9099d2d7ac1186a67b6cc45a88c033b2eb +6bc5c35c8638750a5332a02bbe0d1e8e13b27fc5ebeb6c336113261ead7b6bbe diff --git a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm index dc97b0317..c9d3c95c1 100644 Binary files a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources index 4d47b122e..4b3d03220 100644 --- a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources @@ -1 +1 @@ -29f72aaff35386bb1d340638234f7c63535b5fb2b447d19da53ed703cfa4ab8e +e1405f2e787193f28ce6da05aa6f57fe7ce42ad82e9c68ca11390ff07b252ae6 diff --git a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm index 25fcd74d3..d9f1a0304 100644 Binary files a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources index 916bd565c..d25d4d6db 100644 --- a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources @@ -1 +1 @@ -e28ef416c0034a8006692fab43df24eb14fd43ac6f783e4a36ba223eac1dbff5 +74b7933d8b192a44726b457bdefdd7eb9f3e5fe7cb22f6991f90112fae41c154 diff --git a/docs/en/plugins/api/index.mdx b/docs/en/plugins/api/index.mdx index 31ea080bd..f81e602be 100644 --- a/docs/en/plugins/api/index.mdx +++ b/docs/en/plugins/api/index.mdx @@ -33,6 +33,7 @@ The plugin calls these. Most are gated by a [capability](/en/plugins/capabilitie | `editor` | [workspace.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/workspace.wit) | Text editors: document, selections, versioned edits, reveal; open editors and opening files | | `invocation` | [workspace.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/workspace.wit) | Where a command or event came from: its project, editor and selected paths | | `vcs` | [workspace.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/workspace.wit) | Git for a project's repository: status, remotes, fetch, log, blame, diff | +| `build` | [workspace.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/workspace.wit) | The Maven / Gradle dependency graph the IDE resolved, flat, with conflict and omission status (API 1.10, `build.read`) | | `fs` | [fs.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/fs.wit) | Files outside the open projects (`fs.read:` / `fs.write:`) and the plugin's private directory | | `decorations` | [decorations.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/decorations.wit) | Editor annotations and project-tree badges (API 1.4) | | `commit` | [commit.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/commit.wit) | The commit being prepared and its message | diff --git a/docs/en/plugins/capabilities.mdx b/docs/en/plugins/capabilities.mdx index 17a564a47..c388b8994 100644 --- a/docs/en/plugins/capabilities.mdx +++ b/docs/en/plugins/capabilities.mdx @@ -39,6 +39,7 @@ Later: | `editor.write` | Medium | `TextEditor::apply_edits` | 1.0 | | `vcs.read` | Low | `vcs_status`, `vcs_remotes`, `vcs_log`, `vcs_blame`, `vcs_diff`, the pending commit, before-commit checks | 1.0 | | `vcs.write` | Medium | `vcs_fetch` (trusted projects only), `host::set_commit_message` | 1.0 | +| `build.read` | Low | `build_dependencies`: the Maven / Gradle dependency graph the IDE resolved; trusted projects only | 1.10 | | `storage` | Low | `host::storage`, 64 MiB per plugin | 1.0 | | `events` | Low | File opened, closed and saved, files changed, editor focused, repository changed, settings changed | 1.0 | | `events.input` | Medium | `action-performed` and `input-mode-changed` events (keystrokes and editor input) | 1.0 | diff --git a/docs/en/plugins/versioning.mdx b/docs/en/plugins/versioning.mdx index a477b48ae..5bf757722 100644 --- a/docs/en/plugins/versioning.mdx +++ b/docs/en/plugins/versioning.mdx @@ -3,7 +3,7 @@ title: "API versions and compatibility" description: "engines.openidea, the plugin API versions from 1.0 to 1.6, and the rules that keep released plugins loading in newer IDEs." --- -The plugin API has one version number: the version of the WIT package in [`wit/`](https://github.com/l0ng-ai/openidea/tree/main/wit) (`openidea:plugin@1.8.0` on `main`). The host's engine version and the SDK's `API_VERSION` always agree with it, and the SDK carries an identical copy of the WIT files. +The plugin API has one version number: the version of the WIT package in [`wit/`](https://github.com/l0ng-ai/openidea/tree/main/wit) (`openidea:plugin@1.10.0` on `main`). The host's engine version and the SDK's `API_VERSION` always agree with it, and the SDK carries an identical copy of the WIT files. The plugin system is a preview. The compatibility rules below hold for released 1.x versions; what is still unreleased @@ -12,17 +12,19 @@ The plugin API has one version number: the version of the WIT package in [`wit/` ## Versions -| API | Shipped with | Highlights | -| ----- | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| 1.0.0 | OpenIDEA 0.1.36 | The base API: commands, events, storage, tasks, project and editor access, VCS, diagnostics, network and secrets, processes, declarative views and custom editors, settings, editor providers, syntax provider | -| 1.1.0 | OpenIDEA 0.1.37 | `vcs.remotes`, `ui.copy-to-clipboard`, `ui.open-url`, opening a project file at a line from a view | -| 1.2.0 | OpenIDEA 0.1.38 | Background document indexers, pickers, input boxes and confirmations, plugin context keys for `when` clauses, the files selected in the Project view, a manifest `icon`, the `viewItem.context` menu | -| 1.3.0 | OpenIDEA 0.1.39 | Commit message and before-commit checks, Services detail panes, diagnostics while typing, hover, inlay hints, semantic tokens, file-changing code actions, HTTP endpoints, files outside the project (`fs.read`/`fs.write`, `project.write`, private plugin directory), batched `files-changed` events and path filters, workspace symbols, long-running processes, notifications with buttons, translations, multi-page settings, file template variables, web view PTYs, log tabs and content tabs | -| 1.4.0 | OpenIDEA 0.1.40 | `net.http:`, `ipc:`, `ide.commands` and `database.sources` capabilities; editor and project snapshots, decorations, text search, Problems, Git log/blame/diff; output channels; OAuth loopback; runs, terminal sessions, run configurations, test result parsing and run targets; formatting and other language features; embedded languages; snippets; more menu locations; database sources; MCP tools | -| 1.5.0 | OpenIDEA 0.1.41 | `Project::notify` (a notification in one project's window), the `net:ask` capability, run target validation, per-command run target working-directory arguments | -| 1.6.0 | OpenIDEA 0.1.43 | Bounded, project-bound background WebSockets for event-stream plugins | -| 1.7.0 | OpenIDEA 0.1.44 | `views.open-diff`: two texts in the diff viewer, such as a review's file before and after | -| 1.8.0 | In development on `main` | The `problems-changed` workbench event: the host keeps every producer's diagnostics per file, so an annotation follows the file rather than the invoking window | +| API | Shipped with | Highlights | +| ------ | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1.0.0 | OpenIDEA 0.1.36 | The base API: commands, events, storage, tasks, project and editor access, VCS, diagnostics, network and secrets, processes, declarative views and custom editors, settings, editor providers, syntax provider | +| 1.1.0 | OpenIDEA 0.1.37 | `vcs.remotes`, `ui.copy-to-clipboard`, `ui.open-url`, opening a project file at a line from a view | +| 1.2.0 | OpenIDEA 0.1.38 | Background document indexers, pickers, input boxes and confirmations, plugin context keys for `when` clauses, the files selected in the Project view, a manifest `icon`, the `viewItem.context` menu | +| 1.3.0 | OpenIDEA 0.1.39 | Commit message and before-commit checks, Services detail panes, diagnostics while typing, hover, inlay hints, semantic tokens, file-changing code actions, HTTP endpoints, files outside the project (`fs.read`/`fs.write`, `project.write`, private plugin directory), batched `files-changed` events and path filters, workspace symbols, long-running processes, notifications with buttons, translations, multi-page settings, file template variables, web view PTYs, log tabs and content tabs | +| 1.4.0 | OpenIDEA 0.1.40 | `net.http:`, `ipc:`, `ide.commands` and `database.sources` capabilities; editor and project snapshots, decorations, text search, Problems, Git log/blame/diff; output channels; OAuth loopback; runs, terminal sessions, run configurations, test result parsing and run targets; formatting and other language features; embedded languages; snippets; more menu locations; database sources; MCP tools | +| 1.5.0 | OpenIDEA 0.1.41 | `Project::notify` (a notification in one project's window), the `net:ask` capability, run target validation, per-command run target working-directory arguments | +| 1.6.0 | OpenIDEA 0.1.43 | Bounded, project-bound background WebSockets for event-stream plugins | +| 1.7.0 | OpenIDEA 0.1.44 | `views.open-diff`: two texts in the diff viewer, such as a review's file before and after | +| 1.8.0 | OpenIDEA 0.1.45 | The `problems-changed` workbench event: the host keeps every producer's diagnostics per file, so an annotation follows the file rather than the invoking window | +| 1.9.0 | OpenIDEA 0.1.46 | Run configurations with an environment and a debugger, requests to a running language server (`lsp:`), server commands routed to plugins, editor panels | +| 1.10.0 | In development on `main` | `build.dependencies`: the Maven / Gradle dependency graph the IDE resolved (`build.read`) | The full list of what each version added is in [`plugins/README.md`](https://github.com/l0ng-ai/openidea/blob/main/plugins/README.md). diff --git a/docs/zh/plugins/api/index.mdx b/docs/zh/plugins/api/index.mdx index ca90409d2..e8f477c85 100644 --- a/docs/zh/plugins/api/index.mdx +++ b/docs/zh/plugins/api/index.mdx @@ -33,6 +33,7 @@ description: "openidea:plugin WIT 包中的每个 interface:一句话说明及 | `editor` | [workspace.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/workspace.wit) | 文本编辑器:文档、选区、带版本号的编辑、滚动定位;已打开的编辑器和打开文件 | | `invocation` | [workspace.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/workspace.wit) | 命令或事件的来源:所在项目、编辑器和选中的路径 | | `vcs` | [workspace.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/workspace.wit) | 项目所在仓库的 Git:状态、远程、fetch、log、blame、diff | +| `build` | [workspace.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/workspace.wit) | IDE 已解析的 Maven / Gradle 依赖图,扁平列表,带冲突与省略状态(API 1.10,`build.read`) | | `fs` | [fs.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/fs.wit) | 打开的项目以外的文件(`fs.read:` / `fs.write:`),以及插件私有目录 | | `decorations` | [decorations.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/decorations.wit) | 编辑器标注和项目树徽标(API 1.4) | | `commit` | [commit.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/commit.wit) | 正在准备的提交及其提交信息 | diff --git a/docs/zh/plugins/capabilities.mdx b/docs/zh/plugins/capabilities.mdx index 607bdd9a6..b34262bfa 100644 --- a/docs/zh/plugins/capabilities.mdx +++ b/docs/zh/plugins/capabilities.mdx @@ -39,6 +39,7 @@ optional = ["net:api.example.com", "secrets"] | `editor.write` | 中 | `TextEditor::apply_edits` | 1.0 | | `vcs.read` | 低 | `vcs_status`、`vcs_remotes`、`vcs_log`、`vcs_blame`、`vcs_diff`、待提交的内容、提交前检查 | 1.0 | | `vcs.write` | 中 | `vcs_fetch`(仅受信任项目)、`host::set_commit_message` | 1.0 | +| `build.read` | 低 | `build_dependencies`:IDE 已解析的 Maven / Gradle 依赖图;仅限受信任的项目 | 1.10 | | `storage` | 低 | `host::storage`,每个插件 64 MiB | 1.0 | | `events` | 低 | 文件打开、关闭、保存,文件变化,编辑器焦点变化,仓库变化,设置变化 | 1.0 | | `events.input` | 中 | `action-performed` 和 `input-mode-changed` 事件(按键和编辑器输入) | 1.0 | diff --git a/docs/zh/plugins/versioning.mdx b/docs/zh/plugins/versioning.mdx index 1be2ca697..42ddf5e1b 100644 --- a/docs/zh/plugins/versioning.mdx +++ b/docs/zh/plugins/versioning.mdx @@ -3,23 +3,25 @@ title: "API 版本与兼容" description: "engines.openidea、插件 API 从 1.0 到 1.6 的各个版本,以及让已发布插件在新 IDE 中继续加载的规则。" --- -插件 API 只有一个版本号:[`wit/`](https://github.com/l0ng-ai/openidea/tree/main/wit) 中 WIT 包的版本(`main` 上是 `openidea:plugin@1.8.0`)。宿主的引擎版本和 SDK 的 `API_VERSION` 始终与它一致,SDK 里也带着一份完全相同的 WIT 文件。 +插件 API 只有一个版本号:[`wit/`](https://github.com/l0ng-ai/openidea/tree/main/wit) 中 WIT 包的版本(`main` 上是 `openidea:plugin@1.10.0`)。宿主的引擎版本和 SDK 的 `API_VERSION` 始终与它一致,SDK 里也带着一份完全相同的 WIT 文件。 插件系统目前是预览版。下面的兼容规则适用于已发布的 1.x 版本;`main` 上尚未发布的内容在发布前仍可能变化。 ## 版本历史 -| API | 随哪个版本发布 | 主要内容 | -| ----- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| 1.0.0 | OpenIDEA 0.1.36 | 基础 API:命令、事件、存储、任务、项目和编辑器访问、VCS、诊断、网络与密钥、进程、声明式视图和自定义编辑器、设置、编辑器 provider、syntax provider | -| 1.1.0 | OpenIDEA 0.1.37 | `vcs.remotes`、`ui.copy-to-clipboard`、`ui.open-url`,从视图中打开项目文件的指定行 | -| 1.2.0 | OpenIDEA 0.1.38 | 后台文档索引器;选择器、输入框和确认框;插件自定义的 `when` 上下文键;项目视图中选中的文件;清单 `icon`;`viewItem.context` 菜单 | -| 1.3.0 | OpenIDEA 0.1.39 | 提交信息和提交前检查、Services 详情面板、输入时诊断、悬停、内嵌提示、语义 token、改动文件的代码操作、HTTP 端点、项目外文件(`fs.read`/`fs.write`、`project.write`、插件私有目录)、批量 `files-changed` 事件和路径过滤、工作区符号、长时间运行的进程、带按钮的通知、翻译、多页设置、文件模板变量、Web 视图 PTY、日志标签页和内容标签页 | -| 1.4.0 | OpenIDEA 0.1.40 | `net.http:`、`ipc:`、`ide.commands` 和 `database.sources` 能力;编辑器与项目快照、装饰、文本搜索、问题视图、Git log/blame/diff;输出通道;OAuth 回环;运行、终端会话、运行配置、测试结果解析和运行目标;格式化等语言功能;嵌入语言;代码片段;更多菜单位置;数据库数据源;MCP 工具 | -| 1.5.0 | OpenIDEA 0.1.41 | `Project::notify`(只在某个项目的窗口中显示通知)、`net:ask` 能力、运行目标启动前校验、运行目标按命令设置工作目录参数 | -| 1.6.0 | OpenIDEA 0.1.43 | 面向事件流插件、受容量限制且绑定项目的后台 WebSocket | -| 1.7.0 | OpenIDEA 0.1.44 | `views.open-diff`:在差异查看器中对比两段文本,例如评审中某个文件的修改前后 | -| 1.8.0 | `main` 上开发中 | `problems-changed` 工作台事件:宿主按文件保存每个生产者的诊断,注解跟着文件走,而不是跟着调用它的窗口 | +| API | 随哪个版本发布 | 主要内容 | +| ------ | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1.0.0 | OpenIDEA 0.1.36 | 基础 API:命令、事件、存储、任务、项目和编辑器访问、VCS、诊断、网络与密钥、进程、声明式视图和自定义编辑器、设置、编辑器 provider、syntax provider | +| 1.1.0 | OpenIDEA 0.1.37 | `vcs.remotes`、`ui.copy-to-clipboard`、`ui.open-url`,从视图中打开项目文件的指定行 | +| 1.2.0 | OpenIDEA 0.1.38 | 后台文档索引器;选择器、输入框和确认框;插件自定义的 `when` 上下文键;项目视图中选中的文件;清单 `icon`;`viewItem.context` 菜单 | +| 1.3.0 | OpenIDEA 0.1.39 | 提交信息和提交前检查、Services 详情面板、输入时诊断、悬停、内嵌提示、语义 token、改动文件的代码操作、HTTP 端点、项目外文件(`fs.read`/`fs.write`、`project.write`、插件私有目录)、批量 `files-changed` 事件和路径过滤、工作区符号、长时间运行的进程、带按钮的通知、翻译、多页设置、文件模板变量、Web 视图 PTY、日志标签页和内容标签页 | +| 1.4.0 | OpenIDEA 0.1.40 | `net.http:`、`ipc:`、`ide.commands` 和 `database.sources` 能力;编辑器与项目快照、装饰、文本搜索、问题视图、Git log/blame/diff;输出通道;OAuth 回环;运行、终端会话、运行配置、测试结果解析和运行目标;格式化等语言功能;嵌入语言;代码片段;更多菜单位置;数据库数据源;MCP 工具 | +| 1.5.0 | OpenIDEA 0.1.41 | `Project::notify`(只在某个项目的窗口中显示通知)、`net:ask` 能力、运行目标启动前校验、运行目标按命令设置工作目录参数 | +| 1.6.0 | OpenIDEA 0.1.43 | 面向事件流插件、受容量限制且绑定项目的后台 WebSocket | +| 1.7.0 | OpenIDEA 0.1.44 | `views.open-diff`:在差异查看器中对比两段文本,例如评审中某个文件的修改前后 | +| 1.8.0 | OpenIDEA 0.1.45 | `problems-changed` 工作台事件:宿主按文件保存每个生产者的诊断,注解跟着文件走,而不是跟着调用它的窗口 | +| 1.9.0 | OpenIDEA 0.1.46 | 带环境变量和调试器的运行配置、向正在运行的语言服务器发送请求(`lsp:`)、交给插件处理的服务器命令、编辑器面板 | +| 1.10.0 | `main` 上开发中 | `build.dependencies`:IDE 已解析的 Maven / Gradle 依赖图(`build.read`) | 每个版本新增内容的完整列表见 [`plugins/README.md`](https://github.com/l0ng-ai/openidea/blob/main/plugins/README.md)。 diff --git a/plugins/README.md b/plugins/README.md index ae163274c..9452767f0 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -355,6 +355,7 @@ machine. Users can revoke optional capabilities in Settings › Plugins. | `editor.write` | medium | `TextEditor::apply_edits` | | `vcs.read` | low | `Project::vcs_status`, `vcs_remotes`, `vcs_log`, `vcs_blame`, `vcs_diff` (new reads require trust), `host::pending_commit`, before-commit checks | | `vcs.write` | medium | `Project::vcs_fetch` (trusted projects only), `host::set_commit_message` | +| `build.read` | low | API 1.10: `Project::build_dependencies`, the Maven / Gradle dependency graph the IDE resolved; trusted projects only | | `storage` | low | `host::storage` (64 MiB per plugin, counting UTF-8 bytes of keys and values) | | `events` | low | file opened/saved, editor focused, repository changed events | | `events.input` | medium | `action-performed` and `input-mode-changed` events | @@ -438,6 +439,10 @@ matching SDK. Released 1.9 plugins keep working. New in 1.10: - **`[[contributes.javaAgents]]`** loads a Java agent from the package into the JVM of Application, Spring Boot and JAR Application configurations, behind the high-risk `java.agent` capability. See _Java agents_. +- **The build dependency graph.** `Project::build_dependencies(module)` (WIT + `build.dependencies`) returns the Maven / Gradle graph the Dependency Analyzer + has, as a flat list with conflict and omission status, behind the low-risk + `build.read` capability. No build tool runs. See _Build dependency graph_. ### API 1.9 @@ -665,6 +670,7 @@ then run `openidea-plugin check`. | `host::problems(path)` | `diagnostics.problems` | API 1.4: project Problems reports grouped by file/source, optional file filter. Requires `project.read` and an invoking window. Empty for remote projects. | | `Project::vcs_log(path, limit)` | `vcs.log` | API 1.4: newest first, at most 1000 commits, optional file history. Requires `vcs.read` and trust. | | `Project::vcs_blame(path)` | `vcs.blame` | API 1.4: attribution including unsaved editor text. Requires `vcs.read` and trust. | +| `Project::build_dependencies(module)` | `build.dependencies` | API 1.10: the Maven / Gradle dependency graph the IDE resolved, flat, each module a root; nothing is resolved for the call. Requires `build.read` and trust. | | `Project::vcs_diff(path, against)` | `vcs.diff` | API 1.4: disk working tree against HEAD/revision, optionally one file. None outside Git; fails above 4 MiB. Requires `vcs.read` and trust. | | `TextEditor::apply_edits(version, edits)` | `editor.text-editor.apply-edits` | One undoable change, only if the document is still at `version` — else `Error::Stale` and nothing changes. `transform_selections` retries once. | | `Project::root()`, `read_file(path)` | `workspace.project` | Absolute or project-relative; `..`/symlinks escaping the root are rejected; UTF-8 only, ≤ 16 MiB; unsaved editor contents win; a missing path is `Error::NotFound`. | @@ -839,6 +845,63 @@ In tests, `MockHost::set_language_server_response(server, method, json)` makes a server run and answer, and `language_server_requests()` / `language_server_notifications()` list what the plugin sent. +### Build dependency graph (API 1.10) + +A plugin can read the Maven / Gradle dependency graph the IDE already resolved +for its Dependency Analyzer: resolved versions, conflicts, omitted duplicates +and managed versions, and so "why is this artifact here". Declare `build.read` +(low risk): + +```toml +engines.openidea = "^1.10" + +[capabilities] +required = ["build.read"] +``` + +```rust +let project = inv.project().ok_or("no project")?; +let graph = project.build_dependencies(Some("com.example:app"))?; // or None: every module +for (i, node) in graph.iter().enumerate() { + if node.status == DependencyStatus::OmittedForConflict { + // Walk `parent` up to the module to see who asked for the losing version. + let path: Vec<_> = std::iter::successors(Some(i), |&i| graph[i].parent.map(|p| p as usize)) + .map(|i| format!("{}:{}", graph[i].group, graph[i].artifact)) + .collect(); + host::log(LogLevel::Info, &path.join(" <- ")); + } +} +``` + +| SDK | WIT | Notes | +| ------------------------------------- | ------------------------------------- | --------------------------------------------- | +| `Project::build_dependencies(module)` | `build.dependencies(project, module)` | A flat `list`, modules first | + +- WIT records can't nest, so the graph is a flat list. Each module is a root + (`parent` none, empty `scope`) — a Maven module by its `groupId:artifactId`, a + Gradle project by its path (`:app`, `group` empty) — followed by its tree; + `parent` is the index of the occurrence that brings a node in. +- `module` is a Maven module's `groupId:artifactId` or a Gradle project's path + (`:` for the root project); `None` returns every module of the project's + builds. An unknown module is `not-found`. +- `status`: `resolved`; `omitted-for-conflict` (`version` is the version that + won, `requested-version` the one this occurrence asked for); + `omitted-for-duplicate` (listed with its dependencies elsewhere: Maven's + duplicates and cycles, Gradle's `(*)`); `version-managed` (Maven + ``, a Gradle platform or constraint supplies the + version; `requested-version` is the declared one, if any). `scope` is the + Maven scope or the Gradle configuration. +- Nothing is resolved for the call. Maven trees are those of the last Reload in + the Maven tool window (with the occurrences Maven omitted); before one, or + after a POM changed, only the declared dependencies. Gradle trees are the + configurations the Dependency Analyzer has read for that project, kept until a + build file changes; before that the module has only its own node. +- At most 100,000 nodes per call (else `failed`: ask for one module). The + project must be trusted; otherwise the call is `denied`. + +In tests, `MockHost::set_build_dependencies(nodes)` sets the graph that +`build_dependencies(None)` returns; a module narrows it as the IDE does. + ### Database sources (API 1.4) Declare `database.sources` (medium risk). All five calls require it and a diff --git a/plugins/official/ai-completion/dist/plugin.wasm b/plugins/official/ai-completion/dist/plugin.wasm index cd42ee794..3e434e0e2 100644 Binary files a/plugins/official/ai-completion/dist/plugin.wasm and b/plugins/official/ai-completion/dist/plugin.wasm differ diff --git a/plugins/official/ai-completion/dist/plugin.wasm.sources b/plugins/official/ai-completion/dist/plugin.wasm.sources index 22376d59b..c358cd535 100644 --- a/plugins/official/ai-completion/dist/plugin.wasm.sources +++ b/plugins/official/ai-completion/dist/plugin.wasm.sources @@ -1 +1 @@ -8e875bb7ed12f235be46b32ec1377f251474b0c6b663a066c36fbadc6a7fefb3 +7b31c3eb3541c1766ca63b4e2ecc4475fc6c7ed0db7436cbdc1fba60ec3a7e4c diff --git a/plugins/official/blame-annotations/dist/plugin.wasm b/plugins/official/blame-annotations/dist/plugin.wasm index fb39a9716..8210e60eb 100644 Binary files a/plugins/official/blame-annotations/dist/plugin.wasm and b/plugins/official/blame-annotations/dist/plugin.wasm differ diff --git a/plugins/official/blame-annotations/dist/plugin.wasm.sources b/plugins/official/blame-annotations/dist/plugin.wasm.sources index 6f676efea..8f81a7d75 100644 --- a/plugins/official/blame-annotations/dist/plugin.wasm.sources +++ b/plugins/official/blame-annotations/dist/plugin.wasm.sources @@ -1 +1 @@ -75b4e1267fbf4a93d62963481021970e3eace3442023182e84cd9357744242c9 +055939da8a1db35911b8ecfded94ab1778be7f86f545f46e9b377a0d20fe3572 diff --git a/plugins/official/checkstyle/dist/plugin.wasm b/plugins/official/checkstyle/dist/plugin.wasm index f473ed8a3..51a63b02c 100644 Binary files a/plugins/official/checkstyle/dist/plugin.wasm and b/plugins/official/checkstyle/dist/plugin.wasm differ diff --git a/plugins/official/checkstyle/dist/plugin.wasm.sources b/plugins/official/checkstyle/dist/plugin.wasm.sources index 3ee07a4f8..097a64166 100644 --- a/plugins/official/checkstyle/dist/plugin.wasm.sources +++ b/plugins/official/checkstyle/dist/plugin.wasm.sources @@ -1 +1 @@ -63ad90e231b3cf22ed47710822022f4f80fbdb621b1116998e2599dab7a9b87b +a98b68f34d7a33ccf67b3770008c0817a5515475e49471456e73d18a133d2e3c diff --git a/plugins/official/container-runner/dist/plugin.wasm b/plugins/official/container-runner/dist/plugin.wasm index 62c45bb0c..390755f9c 100644 Binary files a/plugins/official/container-runner/dist/plugin.wasm and b/plugins/official/container-runner/dist/plugin.wasm differ diff --git a/plugins/official/container-runner/dist/plugin.wasm.sources b/plugins/official/container-runner/dist/plugin.wasm.sources index eb396ac18..5ab8fc7f4 100644 --- a/plugins/official/container-runner/dist/plugin.wasm.sources +++ b/plugins/official/container-runner/dist/plugin.wasm.sources @@ -1 +1 @@ -bfd7039bb90e1a4352b7961bbbf83e3af276ba86945fbc23bc34cbf1e3b8c272 +9ae1c4497b986c6722c15d28e38bac2a905c7f9ee3bf4b6e235f924be8798d16 diff --git a/plugins/official/csv-editor/dist/plugin.wasm b/plugins/official/csv-editor/dist/plugin.wasm index a2f4dd072..9a06ad42b 100644 Binary files a/plugins/official/csv-editor/dist/plugin.wasm and b/plugins/official/csv-editor/dist/plugin.wasm differ diff --git a/plugins/official/csv-editor/dist/plugin.wasm.sources b/plugins/official/csv-editor/dist/plugin.wasm.sources index 7f384c34d..370cabece 100644 --- a/plugins/official/csv-editor/dist/plugin.wasm.sources +++ b/plugins/official/csv-editor/dist/plugin.wasm.sources @@ -1 +1 @@ -0ff9eddb3f6fa47c4afd8375471b882cd323631a383a5da97b25271cdd2850a7 +51dcb30b1762236f6cc3fb3c35830c3ce2ec51e92fda6b6a95a849771f3b2592 diff --git a/plugins/official/git-toolbox/dist/plugin.wasm b/plugins/official/git-toolbox/dist/plugin.wasm index 42d4ccdd3..da88fc4f1 100644 Binary files a/plugins/official/git-toolbox/dist/plugin.wasm and b/plugins/official/git-toolbox/dist/plugin.wasm differ diff --git a/plugins/official/git-toolbox/dist/plugin.wasm.sources b/plugins/official/git-toolbox/dist/plugin.wasm.sources index 39ad2fa0c..64f08a449 100644 --- a/plugins/official/git-toolbox/dist/plugin.wasm.sources +++ b/plugins/official/git-toolbox/dist/plugin.wasm.sources @@ -1 +1 @@ -471ddce51119b0fd9caa46c24248f368d48beb8953b5ad6253ba0cfc2c5aa141 +2134d13e021969e0dbd889d9ba29d51a4cb4f6ee162310338762dd3260f1b316 diff --git a/plugins/official/graphviz/dist/plugin.wasm b/plugins/official/graphviz/dist/plugin.wasm index 0536f4f47..bbd0c2f92 100644 Binary files a/plugins/official/graphviz/dist/plugin.wasm and b/plugins/official/graphviz/dist/plugin.wasm differ diff --git a/plugins/official/graphviz/dist/plugin.wasm.sources b/plugins/official/graphviz/dist/plugin.wasm.sources index c32aebade..9079a82c6 100644 --- a/plugins/official/graphviz/dist/plugin.wasm.sources +++ b/plugins/official/graphviz/dist/plugin.wasm.sources @@ -1 +1 @@ -4fc818b0af1abfd9d9d0cdaf4c56cce02cc7e05be501de59b1cbea4672aa91b3 +b818149b051bae73a9bcb460438200799eb6a41b73139722225aeca731a826f7 diff --git a/plugins/official/key-promoter/dist/plugin.wasm b/plugins/official/key-promoter/dist/plugin.wasm index 7edeadd59..1c1c03e06 100644 Binary files a/plugins/official/key-promoter/dist/plugin.wasm and b/plugins/official/key-promoter/dist/plugin.wasm differ diff --git a/plugins/official/key-promoter/dist/plugin.wasm.sources b/plugins/official/key-promoter/dist/plugin.wasm.sources index 09ee2cb32..98bd1511c 100644 --- a/plugins/official/key-promoter/dist/plugin.wasm.sources +++ b/plugins/official/key-promoter/dist/plugin.wasm.sources @@ -1 +1 @@ -d701b0d87cb4f0ff428bb663cb899c1ad85a3c2f10bc97b97ddbc67cdb88e07b +cba8d5dc822a4f48ceeb2002bbbe8dbc5a36375dbcbd034052a0d62d2884db75 diff --git a/plugins/official/license-header/dist/plugin.wasm b/plugins/official/license-header/dist/plugin.wasm index 9b5664282..ffc46023b 100644 Binary files a/plugins/official/license-header/dist/plugin.wasm and b/plugins/official/license-header/dist/plugin.wasm differ diff --git a/plugins/official/license-header/dist/plugin.wasm.sources b/plugins/official/license-header/dist/plugin.wasm.sources index ec15997dd..87537d697 100644 --- a/plugins/official/license-header/dist/plugin.wasm.sources +++ b/plugins/official/license-header/dist/plugin.wasm.sources @@ -1 +1 @@ -72e8802492777bf94f686ce6c09a4a24b16d06dfb0802c56e83a2170cf27393a +8a1722b0be6c36ab7d41836559c064c60a5d9fef638afe90c99af6f6fb6a00b7 diff --git a/plugins/official/mybatis/dist/plugin.wasm b/plugins/official/mybatis/dist/plugin.wasm index 3d1885573..95b631060 100644 Binary files a/plugins/official/mybatis/dist/plugin.wasm and b/plugins/official/mybatis/dist/plugin.wasm differ diff --git a/plugins/official/mybatis/dist/plugin.wasm.sources b/plugins/official/mybatis/dist/plugin.wasm.sources index 6aa075aa8..01de07d91 100644 --- a/plugins/official/mybatis/dist/plugin.wasm.sources +++ b/plugins/official/mybatis/dist/plugin.wasm.sources @@ -1 +1 @@ -594995ca3941ed3ec89625e51b43bfa45d4b5b70248c22787ed7a3291ed07678 +bf9fefe687af7adcd6265de3c4b2e6515ae7c35e375222e6d6f21384782b10ca diff --git a/plugins/official/regex-tester/dist/plugin.wasm b/plugins/official/regex-tester/dist/plugin.wasm index 2d0ba57a4..f61b75dc5 100644 Binary files a/plugins/official/regex-tester/dist/plugin.wasm and b/plugins/official/regex-tester/dist/plugin.wasm differ diff --git a/plugins/official/regex-tester/dist/plugin.wasm.sources b/plugins/official/regex-tester/dist/plugin.wasm.sources index 7f2d7d164..0a0aadd92 100644 --- a/plugins/official/regex-tester/dist/plugin.wasm.sources +++ b/plugins/official/regex-tester/dist/plugin.wasm.sources @@ -1 +1 @@ -2caaf82921e6b942ad043e91e02a8fa59c59ec497bb5d2c84b2f6c156b134e69 +f84dafb8438c8b20a1c6fec3c9bc1e634554358e16ebe4e4300a22b3d7f57f53 diff --git a/plugins/official/solidity/dist/plugin.wasm b/plugins/official/solidity/dist/plugin.wasm index 06a0256b0..712af36aa 100644 Binary files a/plugins/official/solidity/dist/plugin.wasm and b/plugins/official/solidity/dist/plugin.wasm differ diff --git a/plugins/official/solidity/dist/plugin.wasm.sources b/plugins/official/solidity/dist/plugin.wasm.sources index 9693ce149..a47f53338 100644 --- a/plugins/official/solidity/dist/plugin.wasm.sources +++ b/plugins/official/solidity/dist/plugin.wasm.sources @@ -1 +1 @@ -9d4fbc2a435f718863198609928018e0120abfbbd62937cfe8da4c861839ce0d +3197a3110003f71507bbe844f072a8c2a6961dac30f2b66a8ace9192ea9fd07a diff --git a/plugins/official/string-tools/dist/plugin.wasm b/plugins/official/string-tools/dist/plugin.wasm index 51cce12c9..5d6f50318 100644 Binary files a/plugins/official/string-tools/dist/plugin.wasm and b/plugins/official/string-tools/dist/plugin.wasm differ diff --git a/plugins/official/string-tools/dist/plugin.wasm.sources b/plugins/official/string-tools/dist/plugin.wasm.sources index 516331fa6..e76251968 100644 --- a/plugins/official/string-tools/dist/plugin.wasm.sources +++ b/plugins/official/string-tools/dist/plugin.wasm.sources @@ -1 +1 @@ -71b7187c3187e932d5416dd7acff60d60470015ee74b3be9f8d5d5e1469e01d8 +d42c35128fdd8ddcefcd2d9883d959faca9801605879bba7a8a2ac6dbfe5794b diff --git a/plugins/official/test-runner/dist/plugin.wasm b/plugins/official/test-runner/dist/plugin.wasm index 0a76ad924..7e0e5f505 100644 Binary files a/plugins/official/test-runner/dist/plugin.wasm and b/plugins/official/test-runner/dist/plugin.wasm differ diff --git a/plugins/official/test-runner/dist/plugin.wasm.sources b/plugins/official/test-runner/dist/plugin.wasm.sources index 570288ef4..1b779ce50 100644 --- a/plugins/official/test-runner/dist/plugin.wasm.sources +++ b/plugins/official/test-runner/dist/plugin.wasm.sources @@ -1 +1 @@ -de457dec1dca333f217ea499c92eba4d23c0a72729b22de4106cec513396bd96 +0711527e56cdf50d5dd7522eb1c5812c11306cef320c8f9baf3686eb71c4cac6 diff --git a/plugins/official/todo-finder/dist/plugin.wasm b/plugins/official/todo-finder/dist/plugin.wasm index eb2f3c988..628192165 100644 Binary files a/plugins/official/todo-finder/dist/plugin.wasm and b/plugins/official/todo-finder/dist/plugin.wasm differ diff --git a/plugins/official/todo-finder/dist/plugin.wasm.sources b/plugins/official/todo-finder/dist/plugin.wasm.sources index d704a1fb0..1221f4b1c 100644 --- a/plugins/official/todo-finder/dist/plugin.wasm.sources +++ b/plugins/official/todo-finder/dist/plugin.wasm.sources @@ -1 +1 @@ -575c9f2087bbc6233258875530a720c5e72de3f60ab580aa05778703f5fcafcc +349358466a8cedb1c77402f1a5e1f32ee558c05ddd6f08e6053467e04d5c5f62 diff --git a/sdk/rust/openidea-plugin/src/host.rs b/sdk/rust/openidea-plugin/src/host.rs index d07a98e73..13bb632fe 100644 --- a/sdk/rust/openidea-plugin/src/host.rs +++ b/sdk/rust/openidea-plugin/src/host.rs @@ -828,6 +828,30 @@ mod imp { pub fn lsp_notify(project: &ProjectRes, server: &str, method: &str, params: Option<&str>) -> Result<(), Error> { wit::language_servers::notify(project, server, method, params).map_err(error) } + pub fn build_dependencies(project: &ProjectRes, module: Option<&str>) -> Result, Error> { + use wit::build::DependencyStatus as S; + wit::build::dependencies(project, module) + .map(|nodes| { + nodes + .into_iter() + .map(|n| DependencyNode { + group: n.group, + artifact: n.artifact, + version: n.version, + scope: n.scope, + status: match n.status { + S::Resolved => DependencyStatus::Resolved, + S::OmittedForConflict => DependencyStatus::OmittedForConflict, + S::OmittedForDuplicate => DependencyStatus::OmittedForDuplicate, + S::VersionManaged => DependencyStatus::VersionManaged, + }, + requested_version: n.requested_version, + parent: n.parent, + }) + .collect() + }) + .map_err(error) + } pub fn mcp_stdio_command() -> Option> { wit::mcp::stdio_command() } @@ -1082,6 +1106,16 @@ impl Project { imp::lsp_notify(&self.inner, server, method, params) } + /// The Maven / Gradle dependency graph of `module` (a Maven `groupId:artifactId` or a + /// Gradle project path such as `:app`), or of every module with `None` (API 1.10), as + /// the IDE last resolved it: no build tool runs. A flat list, each module a root; see + /// [`DependencyNode`]. Gradle configurations appear once the Dependency Analyzer has + /// read them. An unknown module is [`Error::NotFound`]. Requires `build.read` and a + /// trusted project. + pub fn build_dependencies(&self, module: Option<&str>) -> Result, Error> { + imp::build_dependencies(&self.inner, module) + } + /// Find in Files with unsaved text, project excludes, cancellation and a 10,000 match cap. /// Requires project.read; locations use zero-based lines and UTF-16 columns. pub fn search_text(&self, query: &TextQuery, limit: u32) -> Result { diff --git a/sdk/rust/openidea-plugin/src/mock.rs b/sdk/rust/openidea-plugin/src/mock.rs index 532a1612e..4aefbb33d 100644 --- a/sdk/rust/openidea-plugin/src/mock.rs +++ b/sdk/rust/openidea-plugin/src/mock.rs @@ -151,6 +151,7 @@ struct State { owned_commands: BTreeSet, search: Option, commits: Vec, + build_graph: Vec, blame: BTreeMap>, patch: Option, restricted: bool, @@ -240,6 +241,7 @@ const ALL: &[&str] = &[ "editor.write", "vcs.read", "vcs.write", + "build.read", "storage", "events", "events.input", @@ -302,6 +304,11 @@ impl MockHost { s.blame.insert(path.into(), blame); s.patch = patch; } + /// The project's dependency graph as the IDE would answer `build_dependencies(None)`: + /// modules are the roots, every parent comes before its children. + pub fn set_build_dependencies(&self, nodes: Vec) { + self.state.borrow_mut().build_graph = nodes; + } /// Simulates Restricted Mode for new VCS read APIs. pub fn set_restricted(&self, restricted: bool) { self.state.borrow_mut().restricted = restricted; @@ -2344,6 +2351,46 @@ pub mod current { answer.ok_or_else(|| Error::Failed(format!("{server}: method not found: {method}"))) }) } + /// The module roots matching `module` (`group:artifact`, or a Gradle path) and what is + /// under them, with `parent` renumbered. + pub fn build_dependencies(_project: &ProjectRes, module: Option<&str>) -> Result, Error> { + with(|s| { + require(s, "build.read")?; + if s.restricted { + return Err(Error::Denied("project is not trusted".into())); + } + let mut index = vec![None; s.build_graph.len()]; + let mut out: Vec = Vec::new(); + for (i, node) in s.build_graph.iter().enumerate() { + let parent = match node.parent { + // A Maven module is named `group:artifact`, a Gradle project by its path. + None if module.is_none_or(|m| { + if node.group.is_empty() { + m == node.artifact + } else { + m == format!("{}:{}", node.group, node.artifact) + } + }) => + { + None + } + None => continue, + Some(p) => match index.get(p as usize).copied().flatten() { + Some(p) => Some(p), + None => continue, + }, + }; + index[i] = Some(out.len() as u32); + out.push(DependencyNode { parent, ..node.clone() }); + } + match module { + Some(m) if out.is_empty() => { + Err(Error::NotFound(format!("no Maven or Gradle module `{m}` in this project"))) + } + _ => Ok(out), + } + }) + } pub fn lsp_notify(_project: &ProjectRes, server: &str, method: &str, params: Option<&str>) -> Result<(), Error> { with(|s| { let message = lsp_message(s, server, method, params)?; diff --git a/sdk/rust/openidea-plugin/src/types.rs b/sdk/rust/openidea-plugin/src/types.rs index 802e34258..5718350eb 100644 --- a/sdk/rust/openidea-plugin/src/types.rs +++ b/sdk/rust/openidea-plugin/src/types.rs @@ -713,6 +713,39 @@ pub struct BlameLine { pub summary: String, } +/// How an occurrence in a build's dependency graph was resolved (API 1.10). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum DependencyStatus { + /// Part of the resolved graph. + Resolved, + /// Another version won: `version` is the winner, `requested_version` what this occurrence asked for. + OmittedForConflict, + /// Listed with its dependencies elsewhere in the graph; its children are not repeated. + OmittedForDuplicate, + /// Dependency management (a BOM, a platform, a constraint) supplies the version. + VersionManaged, +} + +/// One occurrence in a build's flat dependency graph ([`crate::Project::build_dependencies`]). +/// Each module is a root (`parent` is `None`, `scope` is empty) with its direct +/// dependencies under it; walk `parent` up to see why an artifact is there. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct DependencyNode { + /// Empty for a Gradle project of the build. + pub group: String, + /// Artifact id, or a Gradle project's path (`:core`). + pub artifact: String, + /// The version in use; empty for a Gradle project of the build or one Gradle could not resolve. + pub version: String, + /// Maven scope, or the Gradle configuration (`runtimeClasspath`). + pub scope: String, + pub status: DependencyStatus, + /// What this occurrence asked for, when it differs from `version`. + pub requested_version: Option, + /// Index of the occurrence bringing this one in. + pub parent: Option, +} + /// Non-secret settings of a plugin-owned project database source (API 1.4). #[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/sdk/rust/openidea-plugin/tests/build_dependencies.rs b/sdk/rust/openidea-plugin/tests/build_dependencies.rs new file mode 100644 index 000000000..4f9b3f0c9 --- /dev/null +++ b/sdk/rust/openidea-plugin/tests/build_dependencies.rs @@ -0,0 +1,51 @@ +use openidea_plugin::{DependencyNode, DependencyStatus, Error, mock::MockHost}; + +fn node(group: &str, artifact: &str, version: &str, scope: &str, parent: Option) -> DependencyNode { + DependencyNode { + group: group.into(), + artifact: artifact.into(), + version: version.into(), + scope: scope.into(), + status: DependencyStatus::Resolved, + requested_version: None, + parent, + } +} + +#[test] +fn the_graph_of_one_module_or_all_behind_the_grant() { + let mock = MockHost::install().with_capabilities(&[]); + let lost = DependencyNode { + status: DependencyStatus::OmittedForConflict, + requested_version: Some("3.12.0".into()), + ..node("org.apache.commons", "commons-lang3", "3.14.0", "compile", Some(1)) + }; + mock.set_build_dependencies(vec![ + node("com.example", "app", "1.0", "", None), + node("org.apache.commons", "commons-text", "1.11.0", "compile", Some(0)), + lost.clone(), + node("", ":web", "", "", None), + node("org.yaml", "snakeyaml", "2.2", "runtimeClasspath", Some(3)), + ]); + let p = mock.invocation().project().unwrap(); + assert!(matches!(p.build_dependencies(None), Err(Error::Denied(c)) if c == "build.read")); + + let mock = mock.with_capabilities(&["build.read"]); + assert_eq!(p.build_dependencies(None).unwrap().len(), 5); + let app = p.build_dependencies(Some("com.example:app")).unwrap(); + assert_eq!(app.len(), 3); + assert_eq!(app[2], lost); + // Why is commons-lang3 here: up through commons-text to the module. + let why: Vec<_> = + std::iter::successors(Some(2), |&i| app[i].parent.map(|p| p as usize)).map(|i| &app[i].artifact).collect(); + assert_eq!(why, ["commons-lang3", "commons-text", "app"]); + let web = p.build_dependencies(Some(":web")).unwrap(); + assert_eq!( + web, + [node("", ":web", "", "", None), node("org.yaml", "snakeyaml", "2.2", "runtimeClasspath", Some(0))] + ); + assert!(matches!(p.build_dependencies(Some("app")), Err(Error::NotFound(_)))); + + mock.set_restricted(true); + assert!(matches!(p.build_dependencies(None), Err(Error::Denied(_)))); +} diff --git a/sdk/rust/openidea-plugin/wit/plugin.wit b/sdk/rust/openidea-plugin/wit/plugin.wit index 077eab417..2d5a5fe35 100644 --- a/sdk/rust/openidea-plugin/wit/plugin.wit +++ b/sdk/rust/openidea-plugin/wit/plugin.wit @@ -20,6 +20,7 @@ world plugin { import decorations; import invocation; import vcs; + import build; import commit; import events; import tasks; diff --git a/sdk/rust/openidea-plugin/wit/workspace.wit b/sdk/rust/openidea-plugin/wit/workspace.wit index fd0799e2c..c1435d86a 100644 --- a/sdk/rust/openidea-plugin/wit/workspace.wit +++ b/sdk/rust/openidea-plugin/wit/workspace.wit @@ -227,3 +227,65 @@ interface vcs { /// Long-running: call it inside a task. fetch: func(project: borrow) -> result<_, error>; } + +/// The Maven / Gradle dependency graph of a project, as the Dependency Analyzer +/// has it (API 1.10). Read-only: no call runs a build tool. +interface build { + use types.{error}; + use workspace.{project}; + + /// How an occurrence of a dependency was resolved. + enum dependency-status { + /// Part of the resolved graph. + resolved, + /// Another version won (Maven: nearer the root; Gradle: the version the + /// build selected). `version` is the winner, `requested-version` what + /// this occurrence asked for. + omitted-for-conflict, + /// Listed with its dependencies elsewhere in the graph (Maven: a + /// duplicate or a cycle; Gradle: `(*)`); its children are not repeated. + omitted-for-duplicate, + /// The version comes from dependency management (Maven + /// ``, a Gradle platform or constraint); + /// `requested-version` is the one declared here, when there is one. + version-managed, + } + + /// One occurrence in the graph. Records don't nest, so the graph is a flat + /// list: `parent` is the index of the occurrence that brings this one in. + /// Each module is a root (`parent` none, empty `scope`) with its direct + /// dependencies under it, so walking `parent` up answers "why is this + /// artifact here". + record dependency-node { + /// Empty for a Gradle project of the build. + group: string, + /// Artifact id; a Gradle project's path (`:core`). + artifact: string, + /// The version in use; empty when there is none (a Gradle project of + /// the build) or it could not be resolved (Gradle `FAILED`). + version: string, + /// Maven scope (`compile`, `test`, …); the Gradle configuration + /// (`runtimeClasspath`, …). + scope: string, + status: dependency-status, + /// What this occurrence asked for, when it differs from `version`. + requested-version: option, + parent: option, + } + + /// The dependency graph of `module` (a Maven module's `groupId:artifactId` + /// or a Gradle project's path, `:` for the root project), or of every + /// module of the project's builds with `none`; an unknown module is + /// `not-found`. Answered from what the IDE already resolved: + /// + /// - Maven: the trees of the last Reload in the Maven tool window (with + /// the occurrences Maven omitted); before one, or after a POM changed, + /// only the dependencies the POMs declare. + /// - Gradle: the configurations the Dependency Analyzer has read for the + /// project, until a build file changes; none read yet is the module's + /// own node only. + /// + /// At most 100,000 nodes (else `failed`: ask for one module). Trusted + /// projects only; requires `build.read`. + dependencies: func(project: borrow, module: option) -> result, error>; +} diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index ed835d474..a92329983 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -962,6 +962,7 @@ "Connect to {host} over unencrypted HTTP (from the machine the project is on)": "Connect to {host} over unencrypted HTTP (from the machine the project is on)", "Connect to local socket {path} — equivalent to running arbitrary code on the project machine": "Connect to local socket {path} — equivalent to running arbitrary code on the project machine", "Send requests to the {server} language server, which reads and changes the project's files": "Send requests to the {server} language server, which reads and changes the project's files", + "Read the project's resolved Maven and Gradle dependencies": "Read the project's resolved Maven and Gradle dependencies", "Output: {channel}": "Output: {channel}", "You can close this tab.": "You can close this tab.", "Run any IDE action or other plugins' commands as if you chose them, including running programs, committing and pushing": "Run any IDE action or other plugins' commands as if you chose them, including running programs, committing and pushing", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 8cdd6149d..5bee2dfa4 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -7344,6 +7344,7 @@ "Connect to {host} over unencrypted HTTP (from the machine the project is on)": "通过未加密的 HTTP 连接到 {host}(从项目所在的计算机)", "Connect to local socket {path} — equivalent to running arbitrary code on the project machine": "连接到本地套接字 {path} — 等同于在项目所在的计算机上运行任意代码", "Send requests to the {server} language server, which reads and changes the project's files": "向 {server} 语言服务器发送请求,该服务器会读取和修改项目文件", + "Read the project's resolved Maven and Gradle dependencies": "读取项目已解析的 Maven 和 Gradle 依赖", "Output: {channel}": "输出:{channel}", "You can close this tab.": "你可以关闭此标签页。", "Run any IDE action or other plugins' commands as if you chose them, including running programs, committing and pushing": "如同您亲自选择一样运行任意 IDE 操作或其他插件的命令,包括运行程序、提交和推送", diff --git a/wit/plugin.wit b/wit/plugin.wit index 077eab417..2d5a5fe35 100644 --- a/wit/plugin.wit +++ b/wit/plugin.wit @@ -20,6 +20,7 @@ world plugin { import decorations; import invocation; import vcs; + import build; import commit; import events; import tasks; diff --git a/wit/workspace.wit b/wit/workspace.wit index fd0799e2c..c1435d86a 100644 --- a/wit/workspace.wit +++ b/wit/workspace.wit @@ -227,3 +227,65 @@ interface vcs { /// Long-running: call it inside a task. fetch: func(project: borrow) -> result<_, error>; } + +/// The Maven / Gradle dependency graph of a project, as the Dependency Analyzer +/// has it (API 1.10). Read-only: no call runs a build tool. +interface build { + use types.{error}; + use workspace.{project}; + + /// How an occurrence of a dependency was resolved. + enum dependency-status { + /// Part of the resolved graph. + resolved, + /// Another version won (Maven: nearer the root; Gradle: the version the + /// build selected). `version` is the winner, `requested-version` what + /// this occurrence asked for. + omitted-for-conflict, + /// Listed with its dependencies elsewhere in the graph (Maven: a + /// duplicate or a cycle; Gradle: `(*)`); its children are not repeated. + omitted-for-duplicate, + /// The version comes from dependency management (Maven + /// ``, a Gradle platform or constraint); + /// `requested-version` is the one declared here, when there is one. + version-managed, + } + + /// One occurrence in the graph. Records don't nest, so the graph is a flat + /// list: `parent` is the index of the occurrence that brings this one in. + /// Each module is a root (`parent` none, empty `scope`) with its direct + /// dependencies under it, so walking `parent` up answers "why is this + /// artifact here". + record dependency-node { + /// Empty for a Gradle project of the build. + group: string, + /// Artifact id; a Gradle project's path (`:core`). + artifact: string, + /// The version in use; empty when there is none (a Gradle project of + /// the build) or it could not be resolved (Gradle `FAILED`). + version: string, + /// Maven scope (`compile`, `test`, …); the Gradle configuration + /// (`runtimeClasspath`, …). + scope: string, + status: dependency-status, + /// What this occurrence asked for, when it differs from `version`. + requested-version: option, + parent: option, + } + + /// The dependency graph of `module` (a Maven module's `groupId:artifactId` + /// or a Gradle project's path, `:` for the root project), or of every + /// module of the project's builds with `none`; an unknown module is + /// `not-found`. Answered from what the IDE already resolved: + /// + /// - Maven: the trees of the last Reload in the Maven tool window (with + /// the occurrences Maven omitted); before one, or after a POM changed, + /// only the dependencies the POMs declare. + /// - Gradle: the configurations the Dependency Analyzer has read for the + /// project, until a build file changes; none read yet is the module's + /// own node only. + /// + /// At most 100,000 nodes (else `failed`: ask for one module). Trusted + /// projects only; requires `build.read`. + dependencies: func(project: borrow, module: option) -> result, error>; +}