From 03809ea5f31c5738c2b6d574c93deae9329d42c6 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Mon, 16 Nov 2026 21:42:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(build):=20Build=20=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E7=9A=84=E6=A0=91=E7=94=B1=20Core=20?= =?UTF-8?q?=E6=8C=89=E7=88=B6=E5=AD=90=E9=A1=B9=E7=9B=AE=E5=B5=8C=E5=A5=97?= =?UTF-8?q?=E6=8E=92=E5=B8=83=20(build.modelTree)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 build.modelTree:项目按 parentID 嵌套,每个项目依次列出按 category (没有时按 group)分好文件夹的任务、项目依赖、目标(带目标级任务)和子项目; 只作用于整个工作区的任务、依赖和测试在根项目旁边只出现一次;只有一个根项目时 它的内容直接作为实例内容。过滤保留匹配的整个节点和通往它的路径。规则只看声明的 作用域、分组、分类和模型,不认任何构建工具。 - 节点 key 稳定且唯一,宿主按 key 记住展开状态 - 循环、自身或缺失的父项目变为根;重复项目 ID 只保留第一个 - 模型上限 2,000 项目 / 10,000 目标与任务,树最多 50,000 节点并标记 truncated - 契约 README、Core API 文档、构建系统参考页与协议更新记录同步 --- rust/contracts/rust-core-api.md | 51 + rust/crates/build/src/commands.rs | 12 + rust/crates/build/src/lib.rs | 1 + rust/crates/build/src/model.rs | 3 +- rust/crates/build/src/tree.rs | 760 +++++++ rust/crates/core/src/protocol/command.rs | 3 + .../core/src/runtime/dispatcher/build.rs | 5 + .../crates/core/src/tests/build_model_tree.rs | 119 + rust/crates/core/src/tests/mod.rs | 1 + rust/fixtures/build/model-tree-v1.json | 2018 +++++++++++++++++ shared/plugins/contract/v1/README.md | 21 + .../reference/domains/build-systems.md | 4 +- .../plugins/reference/protocol-changelog.md | 1 + 13 files changed, 2996 insertions(+), 3 deletions(-) create mode 100644 rust/crates/build/src/tree.rs create mode 100644 rust/crates/core/src/tests/build_model_tree.rs create mode 100644 rust/fixtures/build/model-tree-v1.json diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index f40b6ded..f0f56eab 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -540,6 +540,7 @@ or removing a command fails until the table changes in the same commit. | `build.decodeDiagnostics` | Decode build output into workspace file diagnostics | | `build.decodeDependencies` | Decode dependency output or a provider result into one project's bounded tree | | `build.syncFingerprint` | Digest the files a build model depends on, to tell whether it is stale | +| `build.modelTree` | Nest a decoded model's projects by parent and file each one's tasks, dependencies and targets for a tool window | | `build.resolveTestRunOutcome` | Reduce a test run's termination, selected scope and decoded summary to one tool-neutral verdict | | `build.mergeTestOutcomes` | Merge a run's test result ids into the stored history inside the host-stated id/prefix scope | | `vcs.detectRoots` | Find the VCS roots of a workspace from static markers, with registered providers, ambiguous directories, and applied mappings | @@ -4748,6 +4749,7 @@ and the directories are absolute host paths used only as substitution text. | `build.decodeDiagnostics` | `{ workspaceRoot, root, output }` | `diagnostics`: `[{ path, line, column?, severity, message }]`, deduplicated, inside the workspace only | | `build.decodeDependencies` | `{ workspaceRoot, root, project?, output?, outputFile?, result? }` | `dependencies`: `{ project, dependencies: [{ name, group?, version?, scope?, properties?, children }], truncated }` | | `build.syncFingerprint` | `{ workspaceRoot, root, projects, options? }` | `sync`: `{ fingerprint, watch }` | +| `build.modelTree` | `{ model: { projects, targets, tasks }, query?, groupHeadings?: { : heading } }`; `model` is a `build.decodeModel` result, other model fields are ignored | `tree`: `{ project?, nodes, truncated? }`; see below | Invocation candidates also include `{ kind: "toolchain", toolchainID, root }`. Hosts resolve them through the same canonical project/subproject @@ -4774,6 +4776,55 @@ sum their times; when any invocation lacks a valid non-negative time, or the sum exceeds 2^53 - 1, the field is omitted. A reported zero is valid. Hosts hide a missing duration and never substitute a suite or console summary. +#### Build model tree + +`build.modelTree` lays out one instance's tool window, the same way for every +build tool; hosts render the nodes and neither nest projects nor file tasks +themselves. It reads no file and starts no process. + +- Projects nest by `parentID`. A project whose parent is missing, itself, or + part of a loop, or that is nested deeper than 64 levels, becomes a root; + roots whose parent is missing or themselves come first, then the rest in + model order. A repeated project ID keeps its first project. +- A `project` node holds, in order: its tasks in folders, a `dependencies` + node when `dependencies.scopes` contains `project`, a `targets` node of + `target` nodes, and its child projects. A target's children are the + declared `target`-scoped tasks whose `targetTags` match it. +- A declared task (not `fromModel`) with a `project` scope appears in every + project; one with a `workspace` scope that has no `project` scope or + `requiresUserArguments` appears once in `nodes`, as do tasks with a + `workspace` scope when the model has no projects. Model tasks appear in their + project. Workspace dependencies (`scopes` with `workspace` but not + `project`, or a model with no projects) and test discovery + (`test.discovery`) add a `dependencies` or `tests` node to `nodes`. +- A task is filed under its `category` headings, outermost first, or under + one `folder` for its `group`. A group folder carries `group` and the + host-sent `groupHeadings` label; a host that sends none labels it itself. + Folders keep the order they first appear in; a folder's subfolders come + before its tasks. +- With exactly one root project, `project` is that project's node without + children and `nodes` is its contents plus the instance's own; otherwise + `nodes` holds the instance's nodes, then the root projects. +- `query` (at most 256 bytes, no control characters) is trimmed and matched + case-insensitively against `label`, `detail` and `tooltip`. A matching node + is kept whole with the nodes on the way to it, an unmatched `dependencies` + node is dropped, and a `tests` node is always kept because its entries load + later. A blank query, or one the single root project matches, keeps + everything. +- A node is `{ kind, key, label?, detail?, tooltip?, group?, projectID?, + targetID?, taskID?, children? }`, `kind` one of `project`, `folder`, `task`, + `targets`, `target`, `dependencies`, `tests`. `key` is opaque, unique in the + instance and stable across reloads and filters, so hosts remember open nodes + by it. `projectID` and `targetID` are what a task runs on (absent: the whole + instance); `taskID` is a declared task's ID or a model task's ID. + `targets`, `dependencies` and `tests` nodes have no label. +- The model may hold at most 2,000 projects and 10,000 targets and 10,000 + tasks; more is `invalid_request`, as are unknown request fields and group + headings that are blank, longer than 120 bytes or contain control + characters. A tree is cut at 50,000 nodes and then carries + `truncated: true`. `rust/fixtures/build/model-tree-v1.json` holds the golden + trees. + ### VCS providers The `vcs.*` commands implement the `vcsProviders` capability of diff --git a/rust/crates/build/src/commands.rs b/rust/crates/build/src/commands.rs index 515283c3..a145f46f 100644 --- a/rust/crates/build/src/commands.rs +++ b/rust/crates/build/src/commands.rs @@ -16,6 +16,7 @@ use super::outputs::{ }; use super::plans::{self, OutputPlanRequest, TaskPlanRequest, TestPlanRequest}; use super::test_discovery::{self, DecodeTestDiscoveryRequest}; +use super::tree::{self, ModelTreeRequest}; use super::BuildManifest; use lithe_plugin_model::{decode_payload, outcome, PluginRejection, Validation}; use lithe_protocol::CoreError; @@ -317,6 +318,17 @@ pub fn build_sync_fingerprint_command( ) } +/// `build.modelTree`: a loaded model's projects nested by parent, each with +/// its tasks filed in folders, its dependencies, and its targets. +pub fn build_model_tree_command(payload: Value) -> Result { + with_build_system::( + payload, + "build.modelTree", + "tree", + |build_system, request: &ModelTreeRequest| tree::model_tree(build_system, request), + ) +} + /// `build.prepareDebugPlan`: a selected provider run's native debug preparation. pub fn build_prepare_debug_plan_command( payload: Value, diff --git a/rust/crates/build/src/lib.rs b/rust/crates/build/src/lib.rs index c17154a0..66eea3a2 100644 --- a/rust/crates/build/src/lib.rs +++ b/rust/crates/build/src/lib.rs @@ -37,6 +37,7 @@ mod template; mod test_discovery; mod test_outcome; mod test_outcome_merge; +mod tree; pub use commands::*; pub use manifest::{ diff --git a/rust/crates/build/src/model.rs b/rust/crates/build/src/model.rs index b489c5e2..9e809981 100644 --- a/rust/crates/build/src/model.rs +++ b/rust/crates/build/src/model.rs @@ -20,7 +20,8 @@ use std::collections::{BTreeMap, BTreeSet}; /// Version of the canonical `litheBuildModel` format. pub(crate) const CANONICAL_MODEL_VERSION: u32 = 0; pub(crate) const MAX_PROJECTS: usize = 2_000; -const MAX_ITEMS: usize = 10_000; +/// Most targets, tasks, or content roots one model holds. +pub(crate) const MAX_ITEMS: usize = 10_000; const MAX_NAME: usize = 256; const MAX_PROPERTY_VALUE: usize = 1_024; /// Tags that name what a target is, in the order one of them becomes the diff --git a/rust/crates/build/src/tree.rs b/rust/crates/build/src/tree.rs new file mode 100644 index 00000000..1f7524a5 --- /dev/null +++ b/rust/crates/build/src/tree.rs @@ -0,0 +1,760 @@ +//! `build.modelTree`: the tree a build tool window shows for one loaded +//! model, nested the way the build tool nests its projects. +//! +//! A project holds, in this order, its tasks filed under folders, its +//! dependencies, its targets, and its child projects, which are found through +//! `parentID`; a multi-module build therefore reads as the tool's own +//! hierarchy instead of one long list per instance. Tasks that run on the +//! whole instance appear once, beside the root projects. When the instance +//! has exactly one root project, the root's contents become the instance's +//! contents, because the host already shows the instance as a row. +//! +//! The rules depend only on the declaration's scopes, groups and categories +//! and on the model, never on a build tool. Hosts render the nodes and keep +//! which ones are open by `key`; they neither nest projects nor file tasks +//! themselves. Nothing here reads a file or starts a process. + +use super::manifest::{ + BuildSystemDeclaration, DependenciesSource, Scope, TaskDeclaration, TaskGroup, +}; +use super::model::{MAX_ITEMS, MAX_PROJECTS}; +use lithe_plugin_model::Validation; +use serde::de::Error as _; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_json::Value; +use std::collections::BTreeMap; + +/// Most nodes one tree holds; a larger tree is cut and marked `truncated`. +const MAX_NODES: usize = 50_000; +/// Deepest project nesting kept; a project nested deeper becomes a root. +const MAX_NESTING: usize = 64; +const MAX_QUERY: usize = 256; +const MAX_HEADING: usize = 120; +/// Joins the parts of a key. Labels and IDs never contain control +/// characters, so the parts cannot run into each other. +const KEY_SEPARATOR: char = '\u{1f}'; + +/// A loaded model to show and the text the user filters it by. +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub(crate) struct ModelTreeRequest { + model: TreeModel, + /// Case-insensitive filter; empty or blank keeps every node. + #[serde(default, deserialize_with = "query")] + query: String, + /// Host-localized label of each group folder; a group without one leaves + /// the folder's label to the host. The filter matches these labels. + #[serde(default, deserialize_with = "headings")] + group_headings: BTreeMap, +} + +/// The parts of a decoded `BuildModel` the tree reads; other fields are +/// accepted and ignored, so a host can send back the model it received. +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +struct TreeModel { + #[serde(default, deserialize_with = "projects")] + projects: Vec, + #[serde(default, deserialize_with = "items")] + targets: Vec, + #[serde(default, deserialize_with = "items")] + tasks: Vec, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +struct TreeProject { + id: String, + path: String, + name: String, + #[serde(default)] + display_name: Option, + #[serde(default, rename = "parentID")] + parent_id: Option, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +struct TreeTarget { + id: String, + #[serde(rename = "projectID")] + project_id: String, + name: String, + path: String, + #[serde(default, deserialize_with = "nullable")] + tags: Vec, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +struct TreeTask { + id: String, + #[serde(rename = "projectID")] + project_id: String, + name: String, + #[serde(default)] + display_name: Option, + #[serde(default)] + description: Option, + group: TaskGroup, + #[serde(default, deserialize_with = "nullable")] + category: Vec, +} + +/// The nodes of one instance. +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +struct ModelTree { + /// The instance's only root project, without children; its contents and + /// the instance's own are `nodes`. + #[serde(skip_serializing_if = "Option::is_none")] + project: Option, + nodes: Vec, + /// True when [`MAX_NODES`] cut the tree. + #[serde(skip_serializing_if = "std::ops::Not::not")] + truncated: bool, +} + +/// What a node stands for. `targets`, `dependencies` and `tests` nodes have +/// no label: the host names them, and loads a `dependencies` or `tests` +/// node's entries itself. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] +#[serde(rename_all = "camelCase")] +enum NodeKind { + Project, + /// A category heading of the plugin, or a task group. + Folder, + Task, + Targets, + Target, + Dependencies, + Tests, +} + +/// One row of the tree and the rows nested in it. +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +struct TreeNode { + kind: NodeKind, + /// Unique within the instance and stable across reloads and filters, so + /// the host can remember open nodes by it. Opaque to the host. + key: String, + #[serde(skip_serializing_if = "String::is_empty")] + label: String, + #[serde(skip_serializing_if = "String::is_empty")] + detail: String, + #[serde(skip_serializing_if = "String::is_empty")] + tooltip: String, + /// The group a folder stands for; absent on category folders. + #[serde(skip_serializing_if = "Option::is_none")] + group: Option, + /// The project a node acts on, its own for a project; absent on what + /// acts on the whole instance. + #[serde(rename = "projectID", skip_serializing_if = "String::is_empty")] + project_id: String, + #[serde(rename = "targetID", skip_serializing_if = "String::is_empty")] + target_id: String, + /// A declared task's ID or a model task's ID. + #[serde(rename = "taskID", skip_serializing_if = "String::is_empty")] + task_id: String, + #[serde(skip_serializing_if = "Vec::is_empty")] + children: Vec, +} + +impl TreeNode { + fn new(kind: NodeKind, key: String) -> Self { + Self { + kind, + key, + label: String::new(), + detail: String::new(), + tooltip: String::new(), + group: None, + project_id: String::new(), + target_id: String::new(), + task_id: String::new(), + children: Vec::new(), + } + } + + fn matches(&self, query: &str) -> bool { + [&self.label, &self.detail, &self.tooltip] + .iter() + .any(|text| text.to_lowercase().contains(query)) + } +} + +/// `build.modelTree`. +pub(crate) fn model_tree( + build_system: &BuildSystemDeclaration, + request: &ModelTreeRequest, +) -> Validation { + let index = Index::new(build_system, request); + let mut budget = Budget { + left: MAX_NODES, + truncated: false, + }; + let (project, nodes) = match index.roots.as_slice() { + &[root] => ( + index.project_node(root, &mut budget), + index.contents(Some(root), true, &mut budget), + ), + _ => (None, index.contents(None, true, &mut budget)), + }; + let query = request.query.trim().to_lowercase(); + let unfiltered = query.is_empty() || project.as_ref().is_some_and(|node| node.matches(&query)); + let tree = ModelTree { + project, + nodes: if unfiltered { + nodes + } else { + filter(nodes, &query) + }, + truncated: budget.truncated, + }; + Ok(serde_json::to_value(tree).expect("a model tree serializes")) +} + +/// Keeps the nodes that match `query`, each with its whole subtree, and the +/// nodes on the way to them. Dependencies are loaded by the host, so their +/// node stays only inside a match; tests are filtered by the host, so their +/// node always stays. +fn filter(nodes: Vec, query: &str) -> Vec { + nodes + .into_iter() + .filter_map(|mut node| { + if node.kind == NodeKind::Tests || node.matches(query) { + return Some(node); + } + if node.kind == NodeKind::Dependencies { + return None; + } + node.children = filter(std::mem::take(&mut node.children), query); + (!node.children.is_empty()).then_some(node) + }) + .collect() +} + +/// Nodes left to build; reaching zero cuts the tree. +struct Budget { + left: usize, + truncated: bool, +} + +impl Budget { + /// Takes one node; false, and the tree marked cut, when none is left. + fn take(&mut self) -> bool { + if self.left == 0 { + self.truncated = true; + return false; + } + self.left -= 1; + true + } +} + +/// The model indexed by project. +struct Index<'a> { + build_system: &'a BuildSystemDeclaration, + headings: &'a BTreeMap, + projects: &'a [TreeProject], + /// Children shown under each project, in model order, once cycles, + /// duplicate IDs and too deep nesting are resolved. + children: Vec>, + roots: Vec, + targets: Vec>, + tasks: Vec>, +} + +impl<'a> Index<'a> { + fn new(build_system: &'a BuildSystemDeclaration, request: &'a ModelTreeRequest) -> Self { + let model = &request.model; + let count = model.projects.len(); + let mut by_id = BTreeMap::new(); + for (at, project) in model.projects.iter().enumerate() { + by_id.entry(project.id.as_str()).or_insert(at); + } + // A project repeating an earlier project's ID is left out; targets + // and tasks naming that ID belong to the first. + let kept: Vec = (0..count) + .filter(|&at| by_id.get(model.projects[at].id.as_str()) == Some(&at)) + .collect(); + let mut declared = vec![Vec::new(); count]; + let mut first_roots = Vec::new(); + for &at in &kept { + let parent = model.projects[at] + .parent_id + .as_deref() + .and_then(|id| by_id.get(id).copied()) + .filter(|&parent| parent != at); + match parent { + Some(parent) => declared[parent].push(at), + None => first_roots.push(at), + } + } + let mut children = vec![Vec::new(); count]; + let mut roots = Vec::new(); + let mut reached = vec![false; count]; + // The projects without a parent first; then, in model order, each + // project a cycle or the nesting bound left unreached becomes a root. + for start in first_roots.into_iter().chain(kept) { + if reached[start] { + continue; + } + reached[start] = true; + roots.push(start); + let mut stack = vec![(start, 1)]; + while let Some((at, depth)) = stack.pop() { + if depth == MAX_NESTING { + continue; + } + for &child in &declared[at] { + if !reached[child] { + reached[child] = true; + children[at].push(child); + stack.push((child, depth + 1)); + } + } + } + } + // Targets and tasks of an unknown project have nowhere to show. + let mut targets = vec![Vec::new(); count]; + for target in &model.targets { + if let Some(&at) = by_id.get(target.project_id.as_str()) { + targets[at].push(target); + } + } + let mut tasks = vec![Vec::new(); count]; + for task in &model.tasks { + if let Some(&at) = by_id.get(task.project_id.as_str()) { + tasks[at].push(task); + } + } + Self { + build_system, + headings: &request.group_headings, + projects: &model.projects, + children, + roots, + targets, + tasks, + } + } + + fn project_node(&self, at: usize, budget: &mut Budget) -> Option { + if !budget.take() { + return None; + } + let project = &self.projects[at]; + let mut node = TreeNode::new(NodeKind::Project, project_key(&project.id)); + node.label = shown_name(project.display_name.as_deref(), &project.name); + // The project at the build root says nothing more with a path of ".". + if project.path != "." { + node.detail = project.path.clone(); + } + node.project_id = project.id.clone(); + Some(node) + } + + /// The nodes inside a project, or inside the instance when `project` is + /// `None`. `instance` adds what acts on the whole instance; with a + /// project as well, the instance's tasks share that project's folders. + fn contents( + &self, + project: Option, + instance: bool, + budget: &mut Budget, + ) -> Vec { + let tasks = &self.build_system.tasks; + let container = project.map_or_else(String::new, |at| project_key(&self.projects[at].id)); + let mut folders = Folders::default(); + if let Some(at) = project { + let id = &self.projects[at].id; + for task in tasks.iter().filter(|task| runs_on_each_project(task)) { + let node = declared_task(task, id, ""); + self.file( + &mut folders, + &container, + &task.category, + task.group, + node, + budget, + ); + } + for task in &self.tasks[at] { + let mut node = TreeNode::new(NodeKind::Task, String::new()); + node.label = shown_name(task.display_name.as_deref(), &task.name); + node.tooltip = task.description.clone().unwrap_or_default(); + node.project_id = task.project_id.clone(); + node.task_id = task.id.clone(); + self.file( + &mut folders, + &container, + &task.category, + task.group, + node, + budget, + ); + } + } + if instance { + let without_projects = self.projects.is_empty(); + for task in tasks + .iter() + .filter(|task| runs_once(task, without_projects)) + { + let node = declared_task(task, "", ""); + self.file( + &mut folders, + &container, + &task.category, + task.group, + node, + budget, + ); + } + } + let mut nodes = folders.into_nodes(); + + let scopes = dependency_scopes(self.build_system); + let per_project = scopes.contains(&Scope::Project); + let dependencies = match project { + Some(at) if per_project => Some(self.projects[at].id.clone()), + _ if instance + && scopes.contains(&Scope::Workspace) + && (!per_project || self.projects.is_empty()) => + { + Some(String::new()) + } + _ => None, + }; + if let Some(project_id) = dependencies { + if budget.take() { + let key = format!("{container}{KEY_SEPARATOR}dependencies"); + let mut node = TreeNode::new(NodeKind::Dependencies, key); + node.project_id = project_id; + nodes.push(node); + } + } + + if let Some(at) = project { + if !self.targets[at].is_empty() && budget.take() { + let key = format!("{container}{KEY_SEPARATOR}targets"); + let mut folder = TreeNode::new(NodeKind::Targets, key); + folder.project_id = self.projects[at].id.clone(); + for target in &self.targets[at] { + if let Some(node) = self.target_node(target, &folder.key, budget) { + folder.children.push(node); + } + } + nodes.push(folder); + } + } + + let discovers_tests = self + .build_system + .test + .as_ref() + .is_some_and(|test| test.discovery); + if instance && discovers_tests && budget.take() { + let key = format!("{container}{KEY_SEPARATOR}tests"); + nodes.push(TreeNode::new(NodeKind::Tests, key)); + } + + let projects = match project { + Some(at) => &self.children[at], + None => &self.roots, + }; + for &at in projects { + if let Some(mut node) = self.project_node(at, budget) { + node.children = self.contents(Some(at), false, budget); + nodes.push(node); + } + } + nodes + } + + /// A target with the declared tasks that run on a target carrying one of + /// their tags. + fn target_node( + &self, + target: &TreeTarget, + container: &str, + budget: &mut Budget, + ) -> Option { + if !budget.take() { + return None; + } + let mut node = TreeNode::new( + NodeKind::Target, + format!("{container}{KEY_SEPARATOR}{}", target.id), + ); + (node.label, node.detail, node.tooltip) = target_label(target); + node.project_id = target.project_id.clone(); + node.target_id = target.id.clone(); + let applies = |task: &&TaskDeclaration| { + !task.from_model + && task.scopes.contains(&Scope::Target) + && (task.target_tags.is_empty() + || target.tags.iter().any(|tag| task.target_tags.contains(tag))) + }; + for task in self.build_system.tasks.iter().filter(applies) { + if !budget.take() { + break; + } + let mut child = declared_task(task, &target.project_id, &target.id); + child.key = task_key(&node.key, &task.id); + node.children.push(child); + } + Some(node) + } + + /// Files a task under its category path, else under its group, making + /// the folders it needs. A task the budget cannot hold is left out. + fn file( + &self, + folders: &mut Folders, + container: &str, + category: &[String], + group: TaskGroup, + mut task: TreeNode, + budget: &mut Budget, + ) { + let path: Vec = if category.is_empty() { + vec![Segment::Group(group)] + } else { + category.iter().cloned().map(Segment::Category).collect() + }; + let mut key = container.to_string(); + let mut level = folders; + for segment in path { + key.push(KEY_SEPARATOR); + key.push_str(&segment.key()); + let at = match level + .folders + .iter() + .position(|folder| folder.segment == segment) + { + Some(at) => at, + None => { + if !budget.take() { + return; + } + let mut node = TreeNode::new(NodeKind::Folder, key.clone()); + match &segment { + Segment::Category(label) => node.label = label.clone(), + Segment::Group(group) => { + node.group = Some(*group); + node.label = self.headings.get(group).cloned().unwrap_or_default(); + } + } + level.folders.push(Folder { + segment, + node, + contents: Folders::default(), + }); + level.folders.len() - 1 + } + }; + level = &mut level.folders[at].contents; + } + if budget.take() { + task.key = task_key(&key, &task.task_id); + level.tasks.push(task); + } + } +} + +/// A declared task's node, without its key. +fn declared_task(task: &TaskDeclaration, project_id: &str, target_id: &str) -> TreeNode { + let mut node = TreeNode::new(NodeKind::Task, String::new()); + node.label = task.display_name.clone(); + node.tooltip = task.description.clone().unwrap_or_default(); + node.project_id = project_id.to_string(); + node.target_id = target_id.to_string(); + node.task_id = task.id.clone(); + node +} + +fn shown_name(display_name: Option<&str>, name: &str) -> String { + display_name + .filter(|shown| !shown.trim().is_empty()) + .unwrap_or(name) + .to_string() +} + +/// One folder level: its subfolders by first appearance, then the tasks +/// filed directly in it. +#[derive(Default)] +struct Folders { + folders: Vec, + tasks: Vec, +} + +struct Folder { + segment: Segment, + node: TreeNode, + contents: Folders, +} + +impl Folders { + fn into_nodes(self) -> Vec { + let mut nodes: Vec = self + .folders + .into_iter() + .map(|folder| { + let mut node = folder.node; + node.children = folder.contents.into_nodes(); + node + }) + .collect(); + nodes.extend(self.tasks); + nodes + } +} + +/// One heading of a task's folder path. +#[derive(Debug, Clone, PartialEq, Eq)] +enum Segment { + Category(String), + Group(TaskGroup), +} + +impl Segment { + /// The key part, by group ID rather than by heading so a change of + /// language keeps open folders open. + fn key(&self) -> String { + match self { + Self::Category(label) => format!("c{KEY_SEPARATOR}{label}"), + Self::Group(group) => format!("g{KEY_SEPARATOR}{}", group_id(*group)), + } + } +} + +fn group_id(group: TaskGroup) -> &'static str { + match group { + TaskGroup::Lifecycle => "lifecycle", + TaskGroup::Build => "build", + TaskGroup::Test => "test", + TaskGroup::Run => "run", + TaskGroup::Verification => "verification", + TaskGroup::Documentation => "documentation", + TaskGroup::Other => "other", + } +} + +fn project_key(id: &str) -> String { + format!("p{KEY_SEPARATOR}{id}") +} + +/// The key of a task in the folder or target with key `container`. +fn task_key(container: &str, id: &str) -> String { + format!("{container}{KEY_SEPARATOR}t{KEY_SEPARATOR}{id}") +} + +/// A declared task that each project lists: it runs on a project, unless it +/// asks for arguments and also runs on the instance, which lists it once. +fn runs_on_each_project(task: &TaskDeclaration) -> bool { + !task.from_model + && task.scopes.contains(&Scope::Project) + && !(task.requires_user_arguments && task.scopes.contains(&Scope::Workspace)) +} + +/// A declared task the instance lists once. +fn runs_once(task: &TaskDeclaration, without_projects: bool) -> bool { + !task.from_model + && task.scopes.contains(&Scope::Workspace) + && (!task.scopes.contains(&Scope::Project) + || task.requires_user_arguments + || without_projects) +} + +fn dependency_scopes(build_system: &BuildSystemDeclaration) -> &[Scope] { + match &build_system.dependencies { + Some( + DependenciesSource::Command { scopes, .. } | DependenciesSource::Provider { scopes }, + ) => scopes, + None => &[], + } +} + +/// What a target's node shows: its name with its path beside it, or the path +/// alone when the name already ends with it, as a Go import path ends with +/// the folder of its package; the full name is then the tooltip. +fn target_label(target: &TreeTarget) -> (String, String, String) { + let name = &target.name; + let path = target.path.trim_matches('/'); + if !path.is_empty() && path != "." { + if name == path { + return (path.to_string(), String::new(), String::new()); + } + if name.ends_with(&format!("/{path}")) { + return (path.to_string(), String::new(), name.clone()); + } + } + (name.clone(), target.path.clone(), String::new()) +} + +fn nullable<'de, D, T>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, + T: Deserialize<'de>, +{ + Ok(Option::>::deserialize(deserializer)?.unwrap_or_default()) +} + +fn bounded<'de, D, T>(deserializer: D, limit: usize) -> Result, D::Error> +where + D: Deserializer<'de>, + T: Deserialize<'de>, +{ + let list: Vec = nullable(deserializer)?; + if list.len() > limit { + return Err(D::Error::invalid_length( + list.len(), + &format!("at most {limit} entries").as_str(), + )); + } + Ok(list) +} + +fn projects<'de, D, T>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, + T: Deserialize<'de>, +{ + bounded(deserializer, MAX_PROJECTS) +} + +fn items<'de, D, T>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, + T: Deserialize<'de>, +{ + bounded(deserializer, MAX_ITEMS) +} + +fn query<'de, D: Deserializer<'de>>(deserializer: D) -> Result { + let query = String::deserialize(deserializer)?; + if query.len() > MAX_QUERY || query.chars().any(char::is_control) { + return Err(D::Error::custom(format!( + "query must be at most {MAX_QUERY} bytes without control characters" + ))); + } + Ok(query) +} + +fn headings<'de, D: Deserializer<'de>>( + deserializer: D, +) -> Result, D::Error> { + let headings = BTreeMap::::deserialize(deserializer)?; + for heading in headings.values() { + let text = heading.trim(); + if text.is_empty() || text.len() > MAX_HEADING || text.chars().any(char::is_control) { + return Err(D::Error::custom(format!( + "group headings must be 1 to {MAX_HEADING} bytes without control characters" + ))); + } + } + Ok(headings) +} diff --git a/rust/crates/core/src/protocol/command.rs b/rust/crates/core/src/protocol/command.rs index 3a692c73..c3f0da0a 100644 --- a/rust/crates/core/src/protocol/command.rs +++ b/rust/crates/core/src/protocol/command.rs @@ -484,6 +484,8 @@ pub enum BuildCommand { DecodeDependencies, /// Digests the files a build model depends on (`build.syncFingerprint`). SyncFingerprint, + /// Nests a loaded model's projects and files their tasks for a tool window (`build.modelTree`). + ModelTree, /// Reduces a test run's termination and decoded summary to one verdict (`build.resolveTestRunOutcome`). ResolveTestRunOutcome, /// Merges a run's test results into the stored history inside the host-stated scope (`build.mergeTestOutcomes`). @@ -1163,6 +1165,7 @@ impl CoreCommand { "build.decodeDiagnostics" => Some(Self::Build(BuildCommand::DecodeDiagnostics)), "build.decodeDependencies" => Some(Self::Build(BuildCommand::DecodeDependencies)), "build.syncFingerprint" => Some(Self::Build(BuildCommand::SyncFingerprint)), + "build.modelTree" => Some(Self::Build(BuildCommand::ModelTree)), "build.resolveTestRunOutcome" => Some(Self::Build(BuildCommand::ResolveTestRunOutcome)), "build.mergeTestOutcomes" => Some(Self::Build(BuildCommand::MergeTestOutcomes)), "vcs.detectRoots" => Some(Self::VcsDetectRoots), diff --git a/rust/crates/core/src/runtime/dispatcher/build.rs b/rust/crates/core/src/runtime/dispatcher/build.rs index 22469e7a..8e1e2fb1 100644 --- a/rust/crates/core/src/runtime/dispatcher/build.rs +++ b/rust/crates/core/src/runtime/dispatcher/build.rs @@ -141,6 +141,11 @@ pub(super) fn dispatch(command: BuildCommand, id: Option, payload: Value payload, crate::build::build_sync_fingerprint_command::, ), + BuildCommand::ModelTree => plugin_response( + id, + payload, + crate::build::build_model_tree_command::, + ), BuildCommand::ResolveTestRunOutcome => reducer_response( id, payload, diff --git a/rust/crates/core/src/tests/build_model_tree.rs b/rust/crates/core/src/tests/build_model_tree.rs new file mode 100644 index 00000000..4c2bc5ae --- /dev/null +++ b/rust/crates/core/src/tests/build_model_tree.rs @@ -0,0 +1,119 @@ +//! `build.modelTree`: the nested project tree every host's build tool window +//! renders, checked against the shared fixture. + +use crate::build::build_model_tree_command; +use crate::protocol::ErrorCode; +use lithe_plugin_manifest::DeclarativePluginManifest as Manifest; +use serde_json::{json, Value}; +use std::collections::BTreeSet; + +const FIXTURE: &str = include_str!("../../../../fixtures/build/model-tree-v1.json"); + +fn fixture() -> Value { + serde_json::from_str(FIXTURE).unwrap() +} + +fn tree(manifest: &Value, build_system: &Value, request: &Value) -> Value { + let result = build_model_tree_command::( + json!({"manifest": manifest, "buildSystemID": build_system, "request": request}), + ) + .unwrap(); + assert_eq!(result["status"], "ok", "{result}"); + result["tree"].clone() +} + +/// Every key once, so a host can keep open nodes by key. +fn assert_unique_keys(nodes: &Value, keys: &mut BTreeSet) { + for node in nodes.as_array().into_iter().flatten() { + let key = node["key"].as_str().unwrap().to_string(); + assert!(keys.insert(key.clone()), "repeated key {key:?}"); + assert_unique_keys(&node["children"], keys); + } +} + +fn count(nodes: &Value) -> usize { + nodes + .as_array() + .into_iter() + .flatten() + .map(|node| 1 + count(&node["children"])) + .sum() +} + +#[test] +fn model_tree_nests_projects_and_files_their_tasks() { + let fixture = fixture(); + for case in fixture["cases"].as_array().unwrap() { + let actual = tree( + &fixture["manifest"], + &case["buildSystemID"], + &case["request"], + ); + assert_eq!(actual, case["expected"], "{}", case["name"]); + let mut keys = BTreeSet::new(); + if let Some(project) = actual.get("project") { + keys.insert(project["key"].as_str().unwrap().to_string()); + } + assert_unique_keys(&actual["nodes"], &mut keys); + } +} + +#[test] +fn model_tree_keeps_every_node_when_the_root_project_matches() { + let fixture = fixture(); + let case = &fixture["cases"][0]; + let mut request = case["request"].clone(); + request["query"] = json!(" APP "); + assert_eq!( + tree(&fixture["manifest"], &case["buildSystemID"], &request), + case["expected"] + ); +} + +#[test] +fn model_tree_refuses_malformed_requests() { + let fixture = fixture(); + for case in fixture["rejected"].as_array().unwrap() { + let error = build_model_tree_command::(json!({ + "manifest": fixture["manifest"], + "buildSystemID": case["buildSystemID"], + "request": case["request"], + })) + .expect_err(case["name"].as_str().unwrap()); + assert!( + matches!(error.code, ErrorCode::InvalidRequest), + "{}", + case["name"] + ); + } +} + +#[test] +fn model_tree_bounds_the_model_and_cuts_a_huge_tree() { + let fixture = fixture(); + let project = |at: usize| json!({"id": format!("nested:p{at}"), "path": format!("p{at}"), "name": format!("p{at}")}); + let too_many: Vec = (0..2_001).map(project).collect(); + let error = build_model_tree_command::(json!({ + "manifest": fixture["manifest"], + "buildSystemID": "nested", + "request": {"model": {"projects": too_many}}, + })) + .unwrap_err(); + assert!(matches!(error.code, ErrorCode::InvalidRequest)); + + // Every task its own four-level folder path: far more nodes than a tree holds. + let projects: Vec = (0..2_000).map(project).collect(); + let tasks: Vec = (0..10_000) + .map(|at| { + json!({"id": format!("nested:t{at}"), "projectID": format!("nested:p{}", at % 2_000), + "name": format!("t{at}"), "group": "build", "category": [format!("a{at}"), "b", "c", "d"]}) + }) + .collect(); + let cut = tree( + &fixture["manifest"], + &json!("nested"), + &json!({"model": {"projects": projects, "tasks": tasks}}), + ); + assert_eq!(cut["truncated"], true); + assert!(count(&cut["nodes"]) <= 50_000, "{}", count(&cut["nodes"])); +} diff --git a/rust/crates/core/src/tests/mod.rs b/rust/crates/core/src/tests/mod.rs index e6e3d064..6ad9c866 100644 --- a/rust/crates/core/src/tests/mod.rs +++ b/rust/crates/core/src/tests/mod.rs @@ -1,4 +1,5 @@ mod build_configuration; +mod build_model_tree; mod build_project_options; mod build_runtime_versions; mod build_systems; diff --git a/rust/fixtures/build/model-tree-v1.json b/rust/fixtures/build/model-tree-v1.json new file mode 100644 index 00000000..01b26211 --- /dev/null +++ b/rust/fixtures/build/model-tree-v1.json @@ -0,0 +1,2018 @@ +{ + "version": 0, + "description": "build.modelTree: projects nest by parentID; each holds its tasks filed by category, else by group, then its dependencies, its targets and its child projects. Workspace tasks appear once beside the root projects, and one root project is merged into the instance. A filter keeps each match whole and the nodes on the way to it.", + "manifest": { + "schemaVersion": 0, + "id": "dev.lithe.fixture.build-model-tree", + "displayName": "Build Model Tree Fixture", + "version": "0.1.0", + "pluginAPIVersion": 0, + "requires": { + "buildProviders": 0, + "buildSystems": 0 + }, + "requiresTools": [ + "java" + ], + "vendor": { + "id": "org.example", + "displayName": "Example", + "signatureRequirement": "publisherPackage" + }, + "permissions": [ + "languageServer.launch", + "process.build" + ], + "activationEvents": [ + "onBuildSystem:nested", + "onBuildSystem:flat" + ], + "languages": [], + "buildSystems": [ + { + "id": "nested", + "displayName": "Nested", + "detection": { + "markers": [ + "nested.toml" + ] + }, + "invocation": { + "executables": [ + { + "kind": "command", + "command": "nested" + } + ] + }, + "model": { + "source": "command", + "arguments": [ + "model" + ], + "decoder": "litheBuildModel", + "executesProjectCode": false, + "mayUseNetwork": false + }, + "tasks": [ + { + "id": "clean", + "displayName": "clean", + "description": "Deletes the build outputs.", + "group": "lifecycle", + "scopes": [ + "workspace", + "project" + ], + "category": [ + "Lifecycle" + ], + "arguments": [ + "clean" + ] + }, + { + "id": "package", + "displayName": "package", + "group": "lifecycle", + "scopes": [ + "workspace", + "project" + ], + "category": [ + "Lifecycle" + ], + "arguments": [ + "package" + ] + }, + { + "id": "check", + "displayName": "Check", + "group": "verification", + "scopes": [ + "project" + ], + "arguments": [ + "check" + ] + }, + { + "id": "plugin-goal", + "displayName": "Plugin Goal", + "group": "build", + "fromModel": true, + "category": [ + "Plugins" + ], + "arguments": [ + "${task.name}" + ] + }, + { + "id": "goal", + "displayName": "Run Goal…", + "group": "other", + "scopes": [ + "workspace", + "project" + ], + "requiresUserArguments": true, + "arguments": [ + "${userArguments}" + ] + }, + { + "id": "report", + "displayName": "Report", + "group": "documentation", + "scopes": [ + "workspace" + ], + "arguments": [ + "report" + ] + }, + { + "id": "start", + "displayName": "Start", + "group": "run", + "scopes": [ + "target" + ], + "targetTags": [ + "application" + ], + "arguments": [ + "start", + "${target.name}" + ] + } + ], + "dependencies": { + "source": "command", + "scopes": [ + "workspace", + "project" + ], + "arguments": [ + "dependencies" + ], + "decoder": "litheDependencies", + "executesProjectCode": false, + "mayUseNetwork": false + } + }, + { + "id": "flat", + "displayName": "Flat", + "detection": { + "markers": [ + "flat.toml" + ] + }, + "invocation": { + "executables": [ + { + "kind": "command", + "command": "flat" + } + ] + }, + "provider": { + "launch": { + "kind": "runtime", + "tool": "java", + "minimumVersion": "17", + "entry": "provider/flat.jar" + }, + "arguments": [ + "--stdio" + ], + "executesProjectCode": false, + "mayUseNetwork": false + }, + "model": { + "source": "provider" + }, + "tasks": [ + { + "id": "assemble", + "displayName": "Assemble", + "group": "build", + "scopes": [ + "project" + ], + "source": "provider", + "arguments": [] + }, + { + "id": "refresh", + "displayName": "Refresh All", + "group": "other", + "scopes": [ + "workspace" + ], + "source": "provider", + "arguments": [] + } + ], + "dependencies": { + "source": "provider", + "scopes": [ + "workspace" + ] + }, + "test": { + "source": "provider", + "scopes": [ + "workspace", + "project" + ], + "filters": [ + "suite", + "case" + ], + "arguments": [], + "discovery": true + } + } + ] + }, + "cases": [ + { + "name": "One root project's contents become the instance's; child projects nest with their own folders", + "buildSystemID": "nested", + "request": { + "model": { + "projects": [ + { + "id": "nested:app", + "path": ".", + "name": "app", + "properties": {}, + "displayName": "App" + }, + { + "id": "nested:core/core", + "path": "core", + "name": "core", + "properties": {}, + "parentID": "nested:app" + }, + { + "id": "nested:web/web", + "path": "web", + "name": "web", + "properties": {}, + "parentID": "nested:app" + }, + { + "id": "nested:core/api/api", + "path": "core/api", + "name": "api", + "properties": {}, + "parentID": "nested:core/core" + } + ], + "targets": [ + { + "id": "nested:core/library/core", + "projectID": "nested:core/core", + "name": "core-lib", + "path": "core", + "tags": [ + "library" + ], + "properties": {} + }, + { + "id": "nested:web/server/application/server", + "projectID": "nested:web/web", + "name": "example.com/app/web/server", + "path": "web/server", + "tags": [ + "application" + ], + "properties": {} + }, + { + "id": "nested:gone/application/gone", + "projectID": "nested:gone/gone", + "name": "gone", + "path": "gone", + "tags": [ + "application" + ], + "properties": {} + } + ], + "tasks": [ + { + "id": "nested:compiler:compile", + "projectID": "nested:app", + "name": "compiler:compile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ], + "description": "Compiles the sources." + }, + { + "id": "nested:core/compiler:compile", + "projectID": "nested:core/core", + "name": "compiler:compile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ] + }, + { + "id": "nested:core/compiler:testCompile", + "projectID": "nested:core/core", + "name": "compiler:testCompile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ], + "displayName": "testCompile" + }, + { + "id": "nested:web/jar:jar", + "projectID": "nested:web/web", + "name": "jar:jar", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {} + }, + { + "id": "nested:gone/jar:jar", + "projectID": "nested:gone/gone", + "name": "jar:jar", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {} + } + ], + "contentRoots": [], + "optionValues": {} + }, + "groupHeadings": { + "lifecycle": "Lifecycle", + "build": "Build", + "test": "Test", + "run": "Run", + "verification": "Verification", + "documentation": "Documentation", + "other": "Other" + } + }, + "expected": { + "project": { + "kind": "project", + "key": "p\u001fnested:app", + "label": "App", + "projectID": "nested:app" + }, + "nodes": [ + { + "kind": "folder", + "key": "p\u001fnested:app\u001fc\u001fLifecycle", + "label": "Lifecycle", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:app\u001fc\u001fLifecycle\u001ft\u001fclean", + "label": "clean", + "tooltip": "Deletes the build outputs.", + "projectID": "nested:app", + "taskID": "clean" + }, + { + "kind": "task", + "key": "p\u001fnested:app\u001fc\u001fLifecycle\u001ft\u001fpackage", + "label": "package", + "projectID": "nested:app", + "taskID": "package" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:app\u001fg\u001fverification", + "label": "Verification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:app\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:app", + "taskID": "check" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:app\u001fc\u001fPlugins", + "label": "Plugins", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:app\u001fc\u001fPlugins\u001fc\u001fcompiler", + "label": "compiler", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:app\u001fc\u001fPlugins\u001fc\u001fcompiler\u001ft\u001fnested:compiler:compile", + "label": "compiler:compile", + "tooltip": "Compiles the sources.", + "projectID": "nested:app", + "taskID": "nested:compiler:compile" + } + ] + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:app\u001fg\u001fother", + "label": "Other", + "group": "other", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:app\u001fg\u001fother\u001ft\u001fgoal", + "label": "Run Goal…", + "taskID": "goal" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:app\u001fg\u001fdocumentation", + "label": "Documentation", + "group": "documentation", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:app\u001fg\u001fdocumentation\u001ft\u001freport", + "label": "Report", + "taskID": "report" + } + ] + }, + { + "kind": "dependencies", + "key": "p\u001fnested:app\u001fdependencies", + "projectID": "nested:app" + }, + { + "kind": "project", + "key": "p\u001fnested:core/core", + "label": "core", + "detail": "core", + "projectID": "nested:core/core", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:core/core\u001fc\u001fLifecycle", + "label": "Lifecycle", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:core/core\u001fc\u001fLifecycle\u001ft\u001fclean", + "label": "clean", + "tooltip": "Deletes the build outputs.", + "projectID": "nested:core/core", + "taskID": "clean" + }, + { + "kind": "task", + "key": "p\u001fnested:core/core\u001fc\u001fLifecycle\u001ft\u001fpackage", + "label": "package", + "projectID": "nested:core/core", + "taskID": "package" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:core/core\u001fg\u001fverification", + "label": "Verification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:core/core\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:core/core", + "taskID": "check" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:core/core\u001fc\u001fPlugins", + "label": "Plugins", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:core/core\u001fc\u001fPlugins\u001fc\u001fcompiler", + "label": "compiler", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:core/core\u001fc\u001fPlugins\u001fc\u001fcompiler\u001ft\u001fnested:core/compiler:compile", + "label": "compiler:compile", + "projectID": "nested:core/core", + "taskID": "nested:core/compiler:compile" + }, + { + "kind": "task", + "key": "p\u001fnested:core/core\u001fc\u001fPlugins\u001fc\u001fcompiler\u001ft\u001fnested:core/compiler:testCompile", + "label": "testCompile", + "projectID": "nested:core/core", + "taskID": "nested:core/compiler:testCompile" + } + ] + } + ] + }, + { + "kind": "dependencies", + "key": "p\u001fnested:core/core\u001fdependencies", + "projectID": "nested:core/core" + }, + { + "kind": "targets", + "key": "p\u001fnested:core/core\u001ftargets", + "projectID": "nested:core/core", + "children": [ + { + "kind": "target", + "key": "p\u001fnested:core/core\u001ftargets\u001fnested:core/library/core", + "label": "core-lib", + "detail": "core", + "projectID": "nested:core/core", + "targetID": "nested:core/library/core" + } + ] + }, + { + "kind": "project", + "key": "p\u001fnested:core/api/api", + "label": "api", + "detail": "core/api", + "projectID": "nested:core/api/api", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:core/api/api\u001fc\u001fLifecycle", + "label": "Lifecycle", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:core/api/api\u001fc\u001fLifecycle\u001ft\u001fclean", + "label": "clean", + "tooltip": "Deletes the build outputs.", + "projectID": "nested:core/api/api", + "taskID": "clean" + }, + { + "kind": "task", + "key": "p\u001fnested:core/api/api\u001fc\u001fLifecycle\u001ft\u001fpackage", + "label": "package", + "projectID": "nested:core/api/api", + "taskID": "package" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:core/api/api\u001fg\u001fverification", + "label": "Verification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:core/api/api\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:core/api/api", + "taskID": "check" + } + ] + }, + { + "kind": "dependencies", + "key": "p\u001fnested:core/api/api\u001fdependencies", + "projectID": "nested:core/api/api" + } + ] + } + ] + }, + { + "kind": "project", + "key": "p\u001fnested:web/web", + "label": "web", + "detail": "web", + "projectID": "nested:web/web", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:web/web\u001fc\u001fLifecycle", + "label": "Lifecycle", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:web/web\u001fc\u001fLifecycle\u001ft\u001fclean", + "label": "clean", + "tooltip": "Deletes the build outputs.", + "projectID": "nested:web/web", + "taskID": "clean" + }, + { + "kind": "task", + "key": "p\u001fnested:web/web\u001fc\u001fLifecycle\u001ft\u001fpackage", + "label": "package", + "projectID": "nested:web/web", + "taskID": "package" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:web/web\u001fg\u001fverification", + "label": "Verification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:web/web\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:web/web", + "taskID": "check" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:web/web\u001fg\u001fbuild", + "label": "Build", + "group": "build", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:web/web\u001fg\u001fbuild\u001ft\u001fnested:web/jar:jar", + "label": "jar:jar", + "projectID": "nested:web/web", + "taskID": "nested:web/jar:jar" + } + ] + }, + { + "kind": "dependencies", + "key": "p\u001fnested:web/web\u001fdependencies", + "projectID": "nested:web/web" + }, + { + "kind": "targets", + "key": "p\u001fnested:web/web\u001ftargets", + "projectID": "nested:web/web", + "children": [ + { + "kind": "target", + "key": "p\u001fnested:web/web\u001ftargets\u001fnested:web/server/application/server", + "label": "web/server", + "tooltip": "example.com/app/web/server", + "projectID": "nested:web/web", + "targetID": "nested:web/server/application/server", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:web/web\u001ftargets\u001fnested:web/server/application/server\u001ft\u001fstart", + "label": "Start", + "projectID": "nested:web/web", + "targetID": "nested:web/server/application/server", + "taskID": "start" + } + ] + } + ] + } + ] + } + ] + } + }, + { + "name": "A filter keeps a matching project whole and the projects on the way to it", + "buildSystemID": "nested", + "request": { + "model": { + "projects": [ + { + "id": "nested:app", + "path": ".", + "name": "app", + "properties": {}, + "displayName": "App" + }, + { + "id": "nested:core/core", + "path": "core", + "name": "core", + "properties": {}, + "parentID": "nested:app" + }, + { + "id": "nested:web/web", + "path": "web", + "name": "web", + "properties": {}, + "parentID": "nested:app" + }, + { + "id": "nested:core/api/api", + "path": "core/api", + "name": "api", + "properties": {}, + "parentID": "nested:core/core" + } + ], + "targets": [ + { + "id": "nested:core/library/core", + "projectID": "nested:core/core", + "name": "core-lib", + "path": "core", + "tags": [ + "library" + ], + "properties": {} + }, + { + "id": "nested:web/server/application/server", + "projectID": "nested:web/web", + "name": "example.com/app/web/server", + "path": "web/server", + "tags": [ + "application" + ], + "properties": {} + }, + { + "id": "nested:gone/application/gone", + "projectID": "nested:gone/gone", + "name": "gone", + "path": "gone", + "tags": [ + "application" + ], + "properties": {} + } + ], + "tasks": [ + { + "id": "nested:compiler:compile", + "projectID": "nested:app", + "name": "compiler:compile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ], + "description": "Compiles the sources." + }, + { + "id": "nested:core/compiler:compile", + "projectID": "nested:core/core", + "name": "compiler:compile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ] + }, + { + "id": "nested:core/compiler:testCompile", + "projectID": "nested:core/core", + "name": "compiler:testCompile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ], + "displayName": "testCompile" + }, + { + "id": "nested:web/jar:jar", + "projectID": "nested:web/web", + "name": "jar:jar", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {} + }, + { + "id": "nested:gone/jar:jar", + "projectID": "nested:gone/gone", + "name": "jar:jar", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {} + } + ], + "contentRoots": [], + "optionValues": {} + }, + "groupHeadings": { + "lifecycle": "Lifecycle", + "build": "Build", + "test": "Test", + "run": "Run", + "verification": "Verification", + "documentation": "Documentation", + "other": "Other" + }, + "query": "API" + }, + "expected": { + "project": { + "kind": "project", + "key": "p\u001fnested:app", + "label": "App", + "projectID": "nested:app" + }, + "nodes": [ + { + "kind": "project", + "key": "p\u001fnested:core/core", + "label": "core", + "detail": "core", + "projectID": "nested:core/core", + "children": [ + { + "kind": "project", + "key": "p\u001fnested:core/api/api", + "label": "api", + "detail": "core/api", + "projectID": "nested:core/api/api", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:core/api/api\u001fc\u001fLifecycle", + "label": "Lifecycle", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:core/api/api\u001fc\u001fLifecycle\u001ft\u001fclean", + "label": "clean", + "tooltip": "Deletes the build outputs.", + "projectID": "nested:core/api/api", + "taskID": "clean" + }, + { + "kind": "task", + "key": "p\u001fnested:core/api/api\u001fc\u001fLifecycle\u001ft\u001fpackage", + "label": "package", + "projectID": "nested:core/api/api", + "taskID": "package" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:core/api/api\u001fg\u001fverification", + "label": "Verification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:core/api/api\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:core/api/api", + "taskID": "check" + } + ] + }, + { + "kind": "dependencies", + "key": "p\u001fnested:core/api/api\u001fdependencies", + "projectID": "nested:core/api/api" + } + ] + } + ] + } + ] + } + }, + { + "name": "A filter matches localized group headings", + "buildSystemID": "nested", + "request": { + "model": { + "projects": [ + { + "id": "nested:app", + "path": ".", + "name": "app", + "properties": {}, + "displayName": "App" + }, + { + "id": "nested:core/core", + "path": "core", + "name": "core", + "properties": {}, + "parentID": "nested:app" + }, + { + "id": "nested:web/web", + "path": "web", + "name": "web", + "properties": {}, + "parentID": "nested:app" + }, + { + "id": "nested:core/api/api", + "path": "core/api", + "name": "api", + "properties": {}, + "parentID": "nested:core/core" + } + ], + "targets": [ + { + "id": "nested:core/library/core", + "projectID": "nested:core/core", + "name": "core-lib", + "path": "core", + "tags": [ + "library" + ], + "properties": {} + }, + { + "id": "nested:web/server/application/server", + "projectID": "nested:web/web", + "name": "example.com/app/web/server", + "path": "web/server", + "tags": [ + "application" + ], + "properties": {} + }, + { + "id": "nested:gone/application/gone", + "projectID": "nested:gone/gone", + "name": "gone", + "path": "gone", + "tags": [ + "application" + ], + "properties": {} + } + ], + "tasks": [ + { + "id": "nested:compiler:compile", + "projectID": "nested:app", + "name": "compiler:compile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ], + "description": "Compiles the sources." + }, + { + "id": "nested:core/compiler:compile", + "projectID": "nested:core/core", + "name": "compiler:compile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ] + }, + { + "id": "nested:core/compiler:testCompile", + "projectID": "nested:core/core", + "name": "compiler:testCompile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ], + "displayName": "testCompile" + }, + { + "id": "nested:web/jar:jar", + "projectID": "nested:web/web", + "name": "jar:jar", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {} + }, + { + "id": "nested:gone/jar:jar", + "projectID": "nested:gone/gone", + "name": "jar:jar", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {} + } + ], + "contentRoots": [], + "optionValues": {} + }, + "groupHeadings": { + "lifecycle": "Lifecycle", + "build": "Build", + "test": "Test", + "run": "Run", + "verification": "Verification", + "documentation": "Documentation", + "other": "Other" + }, + "query": "verif" + }, + "expected": { + "project": { + "kind": "project", + "key": "p\u001fnested:app", + "label": "App", + "projectID": "nested:app" + }, + "nodes": [ + { + "kind": "folder", + "key": "p\u001fnested:app\u001fg\u001fverification", + "label": "Verification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:app\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:app", + "taskID": "check" + } + ] + }, + { + "kind": "project", + "key": "p\u001fnested:core/core", + "label": "core", + "detail": "core", + "projectID": "nested:core/core", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:core/core\u001fg\u001fverification", + "label": "Verification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:core/core\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:core/core", + "taskID": "check" + } + ] + }, + { + "kind": "project", + "key": "p\u001fnested:core/api/api", + "label": "api", + "detail": "core/api", + "projectID": "nested:core/api/api", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:core/api/api\u001fg\u001fverification", + "label": "Verification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:core/api/api\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:core/api/api", + "taskID": "check" + } + ] + } + ] + } + ] + }, + { + "kind": "project", + "key": "p\u001fnested:web/web", + "label": "web", + "detail": "web", + "projectID": "nested:web/web", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:web/web\u001fg\u001fverification", + "label": "Verification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:web/web\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:web/web", + "taskID": "check" + } + ] + } + ] + } + ] + } + }, + { + "name": "A filter matches a target's full name", + "buildSystemID": "nested", + "request": { + "model": { + "projects": [ + { + "id": "nested:app", + "path": ".", + "name": "app", + "properties": {}, + "displayName": "App" + }, + { + "id": "nested:core/core", + "path": "core", + "name": "core", + "properties": {}, + "parentID": "nested:app" + }, + { + "id": "nested:web/web", + "path": "web", + "name": "web", + "properties": {}, + "parentID": "nested:app" + }, + { + "id": "nested:core/api/api", + "path": "core/api", + "name": "api", + "properties": {}, + "parentID": "nested:core/core" + } + ], + "targets": [ + { + "id": "nested:core/library/core", + "projectID": "nested:core/core", + "name": "core-lib", + "path": "core", + "tags": [ + "library" + ], + "properties": {} + }, + { + "id": "nested:web/server/application/server", + "projectID": "nested:web/web", + "name": "example.com/app/web/server", + "path": "web/server", + "tags": [ + "application" + ], + "properties": {} + }, + { + "id": "nested:gone/application/gone", + "projectID": "nested:gone/gone", + "name": "gone", + "path": "gone", + "tags": [ + "application" + ], + "properties": {} + } + ], + "tasks": [ + { + "id": "nested:compiler:compile", + "projectID": "nested:app", + "name": "compiler:compile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ], + "description": "Compiles the sources." + }, + { + "id": "nested:core/compiler:compile", + "projectID": "nested:core/core", + "name": "compiler:compile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ] + }, + { + "id": "nested:core/compiler:testCompile", + "projectID": "nested:core/core", + "name": "compiler:testCompile", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {}, + "category": [ + "Plugins", + "compiler" + ], + "displayName": "testCompile" + }, + { + "id": "nested:web/jar:jar", + "projectID": "nested:web/web", + "name": "jar:jar", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {} + }, + { + "id": "nested:gone/jar:jar", + "projectID": "nested:gone/gone", + "name": "jar:jar", + "path": ".", + "template": "plugin-goal", + "group": "build", + "execution": "task", + "properties": {} + } + ], + "contentRoots": [], + "optionValues": {} + }, + "query": "example.com" + }, + "expected": { + "project": { + "kind": "project", + "key": "p\u001fnested:app", + "label": "App", + "projectID": "nested:app" + }, + "nodes": [ + { + "kind": "project", + "key": "p\u001fnested:web/web", + "label": "web", + "detail": "web", + "projectID": "nested:web/web", + "children": [ + { + "kind": "targets", + "key": "p\u001fnested:web/web\u001ftargets", + "projectID": "nested:web/web", + "children": [ + { + "kind": "target", + "key": "p\u001fnested:web/web\u001ftargets\u001fnested:web/server/application/server", + "label": "web/server", + "tooltip": "example.com/app/web/server", + "projectID": "nested:web/web", + "targetID": "nested:web/server/application/server", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:web/web\u001ftargets\u001fnested:web/server/application/server\u001ft\u001fstart", + "label": "Start", + "projectID": "nested:web/web", + "targetID": "nested:web/server/application/server", + "taskID": "start" + } + ] + } + ] + } + ] + } + ] + } + }, + { + "name": "An unknown parent, a cycle and a self parent make roots; a repeated project ID is dropped", + "buildSystemID": "nested", + "request": { + "model": { + "projects": [ + { + "id": "nested:a/a", + "path": "a", + "name": "a", + "properties": {}, + "parentID": "nested:missing/missing" + }, + { + "id": "nested:b/b", + "path": "b", + "name": "b", + "properties": {}, + "parentID": "nested:c/c" + }, + { + "id": "nested:c/c", + "path": "c", + "name": "c", + "properties": {}, + "parentID": "nested:b/b" + }, + { + "id": "nested:d/d", + "path": "d", + "name": "d", + "properties": {}, + "parentID": "nested:d/d" + }, + { + "id": "nested:a/a", + "path": "a2", + "name": "duplicate", + "properties": {} + } + ], + "targets": null, + "tasks": null + } + }, + "expected": { + "nodes": [ + { + "kind": "folder", + "key": "\u001fg\u001fother", + "group": "other", + "children": [ + { + "kind": "task", + "key": "\u001fg\u001fother\u001ft\u001fgoal", + "label": "Run Goal…", + "taskID": "goal" + } + ] + }, + { + "kind": "folder", + "key": "\u001fg\u001fdocumentation", + "group": "documentation", + "children": [ + { + "kind": "task", + "key": "\u001fg\u001fdocumentation\u001ft\u001freport", + "label": "Report", + "taskID": "report" + } + ] + }, + { + "kind": "project", + "key": "p\u001fnested:a/a", + "label": "a", + "detail": "a", + "projectID": "nested:a/a", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:a/a\u001fc\u001fLifecycle", + "label": "Lifecycle", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:a/a\u001fc\u001fLifecycle\u001ft\u001fclean", + "label": "clean", + "tooltip": "Deletes the build outputs.", + "projectID": "nested:a/a", + "taskID": "clean" + }, + { + "kind": "task", + "key": "p\u001fnested:a/a\u001fc\u001fLifecycle\u001ft\u001fpackage", + "label": "package", + "projectID": "nested:a/a", + "taskID": "package" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:a/a\u001fg\u001fverification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:a/a\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:a/a", + "taskID": "check" + } + ] + }, + { + "kind": "dependencies", + "key": "p\u001fnested:a/a\u001fdependencies", + "projectID": "nested:a/a" + } + ] + }, + { + "kind": "project", + "key": "p\u001fnested:d/d", + "label": "d", + "detail": "d", + "projectID": "nested:d/d", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:d/d\u001fc\u001fLifecycle", + "label": "Lifecycle", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:d/d\u001fc\u001fLifecycle\u001ft\u001fclean", + "label": "clean", + "tooltip": "Deletes the build outputs.", + "projectID": "nested:d/d", + "taskID": "clean" + }, + { + "kind": "task", + "key": "p\u001fnested:d/d\u001fc\u001fLifecycle\u001ft\u001fpackage", + "label": "package", + "projectID": "nested:d/d", + "taskID": "package" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:d/d\u001fg\u001fverification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:d/d\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:d/d", + "taskID": "check" + } + ] + }, + { + "kind": "dependencies", + "key": "p\u001fnested:d/d\u001fdependencies", + "projectID": "nested:d/d" + } + ] + }, + { + "kind": "project", + "key": "p\u001fnested:b/b", + "label": "b", + "detail": "b", + "projectID": "nested:b/b", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:b/b\u001fc\u001fLifecycle", + "label": "Lifecycle", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:b/b\u001fc\u001fLifecycle\u001ft\u001fclean", + "label": "clean", + "tooltip": "Deletes the build outputs.", + "projectID": "nested:b/b", + "taskID": "clean" + }, + { + "kind": "task", + "key": "p\u001fnested:b/b\u001fc\u001fLifecycle\u001ft\u001fpackage", + "label": "package", + "projectID": "nested:b/b", + "taskID": "package" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:b/b\u001fg\u001fverification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:b/b\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:b/b", + "taskID": "check" + } + ] + }, + { + "kind": "dependencies", + "key": "p\u001fnested:b/b\u001fdependencies", + "projectID": "nested:b/b" + }, + { + "kind": "project", + "key": "p\u001fnested:c/c", + "label": "c", + "detail": "c", + "projectID": "nested:c/c", + "children": [ + { + "kind": "folder", + "key": "p\u001fnested:c/c\u001fc\u001fLifecycle", + "label": "Lifecycle", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:c/c\u001fc\u001fLifecycle\u001ft\u001fclean", + "label": "clean", + "tooltip": "Deletes the build outputs.", + "projectID": "nested:c/c", + "taskID": "clean" + }, + { + "kind": "task", + "key": "p\u001fnested:c/c\u001fc\u001fLifecycle\u001ft\u001fpackage", + "label": "package", + "projectID": "nested:c/c", + "taskID": "package" + } + ] + }, + { + "kind": "folder", + "key": "p\u001fnested:c/c\u001fg\u001fverification", + "group": "verification", + "children": [ + { + "kind": "task", + "key": "p\u001fnested:c/c\u001fg\u001fverification\u001ft\u001fcheck", + "label": "Check", + "projectID": "nested:c/c", + "taskID": "check" + } + ] + }, + { + "kind": "dependencies", + "key": "p\u001fnested:c/c\u001fdependencies", + "projectID": "nested:c/c" + } + ] + } + ] + } + ] + } + }, + { + "name": "Without projects, every workspace task and the dependencies act on the instance", + "buildSystemID": "nested", + "request": { + "model": { + "projects": null, + "targets": null, + "tasks": null + }, + "groupHeadings": { + "lifecycle": "Lifecycle", + "build": "Build", + "test": "Test", + "run": "Run", + "verification": "Verification", + "documentation": "Documentation", + "other": "Other" + } + }, + "expected": { + "nodes": [ + { + "kind": "folder", + "key": "\u001fc\u001fLifecycle", + "label": "Lifecycle", + "children": [ + { + "kind": "task", + "key": "\u001fc\u001fLifecycle\u001ft\u001fclean", + "label": "clean", + "tooltip": "Deletes the build outputs.", + "taskID": "clean" + }, + { + "kind": "task", + "key": "\u001fc\u001fLifecycle\u001ft\u001fpackage", + "label": "package", + "taskID": "package" + } + ] + }, + { + "kind": "folder", + "key": "\u001fg\u001fother", + "label": "Other", + "group": "other", + "children": [ + { + "kind": "task", + "key": "\u001fg\u001fother\u001ft\u001fgoal", + "label": "Run Goal…", + "taskID": "goal" + } + ] + }, + { + "kind": "folder", + "key": "\u001fg\u001fdocumentation", + "label": "Documentation", + "group": "documentation", + "children": [ + { + "kind": "task", + "key": "\u001fg\u001fdocumentation\u001ft\u001freport", + "label": "Report", + "taskID": "report" + } + ] + }, + { + "kind": "dependencies", + "key": "\u001fdependencies" + } + ] + } + }, + { + "name": "Workspace-only dependencies and discovered tests sit beside the root projects", + "buildSystemID": "flat", + "request": { + "model": { + "projects": [ + { + "id": "flat:x", + "path": "x", + "name": "x", + "properties": {} + }, + { + "id": "flat:y", + "path": "y", + "name": "y", + "properties": {} + } + ], + "targets": [], + "tasks": [] + } + }, + "expected": { + "nodes": [ + { + "kind": "folder", + "key": "\u001fg\u001fother", + "group": "other", + "children": [ + { + "kind": "task", + "key": "\u001fg\u001fother\u001ft\u001frefresh", + "label": "Refresh All", + "taskID": "refresh" + } + ] + }, + { + "kind": "dependencies", + "key": "\u001fdependencies" + }, + { + "kind": "tests", + "key": "\u001ftests" + }, + { + "kind": "project", + "key": "p\u001fflat:x", + "label": "x", + "detail": "x", + "projectID": "flat:x", + "children": [ + { + "kind": "folder", + "key": "p\u001fflat:x\u001fg\u001fbuild", + "group": "build", + "children": [ + { + "kind": "task", + "key": "p\u001fflat:x\u001fg\u001fbuild\u001ft\u001fassemble", + "label": "Assemble", + "projectID": "flat:x", + "taskID": "assemble" + } + ] + } + ] + }, + { + "kind": "project", + "key": "p\u001fflat:y", + "label": "y", + "detail": "y", + "projectID": "flat:y", + "children": [ + { + "kind": "folder", + "key": "p\u001fflat:y\u001fg\u001fbuild", + "group": "build", + "children": [ + { + "kind": "task", + "key": "p\u001fflat:y\u001fg\u001fbuild\u001ft\u001fassemble", + "label": "Assemble", + "projectID": "flat:y", + "taskID": "assemble" + } + ] + } + ] + } + ] + } + }, + { + "name": "A filter drops unmatched dependencies and keeps the tests node", + "buildSystemID": "flat", + "request": { + "model": { + "projects": [ + { + "id": "flat:x", + "path": "x", + "name": "x", + "properties": {} + }, + { + "id": "flat:y", + "path": "y", + "name": "y", + "properties": {} + } + ], + "targets": [], + "tasks": [] + }, + "query": "assem", + "groupHeadings": { + "lifecycle": "Lifecycle", + "build": "Build", + "test": "Test", + "run": "Run", + "verification": "Verification", + "documentation": "Documentation", + "other": "Other" + } + }, + "expected": { + "nodes": [ + { + "kind": "tests", + "key": "\u001ftests" + }, + { + "kind": "project", + "key": "p\u001fflat:x", + "label": "x", + "detail": "x", + "projectID": "flat:x", + "children": [ + { + "kind": "folder", + "key": "p\u001fflat:x\u001fg\u001fbuild", + "label": "Build", + "group": "build", + "children": [ + { + "kind": "task", + "key": "p\u001fflat:x\u001fg\u001fbuild\u001ft\u001fassemble", + "label": "Assemble", + "projectID": "flat:x", + "taskID": "assemble" + } + ] + } + ] + }, + { + "kind": "project", + "key": "p\u001fflat:y", + "label": "y", + "detail": "y", + "projectID": "flat:y", + "children": [ + { + "kind": "folder", + "key": "p\u001fflat:y\u001fg\u001fbuild", + "label": "Build", + "group": "build", + "children": [ + { + "kind": "task", + "key": "p\u001fflat:y\u001fg\u001fbuild\u001ft\u001fassemble", + "label": "Assemble", + "projectID": "flat:y", + "taskID": "assemble" + } + ] + } + ] + } + ] + } + } + ], + "rejected": [ + { + "name": "Unknown request field", + "buildSystemID": "nested", + "request": { + "model": { + "projects": [ + { + "id": "flat:x", + "path": "x", + "name": "x", + "properties": {} + }, + { + "id": "flat:y", + "path": "y", + "name": "y", + "properties": {} + } + ], + "targets": [], + "tasks": [] + }, + "expanded": [] + } + }, + { + "name": "Control character in the query", + "buildSystemID": "nested", + "request": { + "model": { + "projects": [ + { + "id": "flat:x", + "path": "x", + "name": "x", + "properties": {} + }, + { + "id": "flat:y", + "path": "y", + "name": "y", + "properties": {} + } + ], + "targets": [], + "tasks": [] + }, + "query": "a\nb" + } + }, + { + "name": "Blank group heading", + "buildSystemID": "nested", + "request": { + "model": { + "projects": [ + { + "id": "flat:x", + "path": "x", + "name": "x", + "properties": {} + }, + { + "id": "flat:y", + "path": "y", + "name": "y", + "properties": {} + } + ], + "targets": [], + "tasks": [] + }, + "groupHeadings": { + "build": " " + } + } + }, + { + "name": "Unknown group", + "buildSystemID": "nested", + "request": { + "model": { + "projects": [ + { + "id": "flat:x", + "path": "x", + "name": "x", + "properties": {} + }, + { + "id": "flat:y", + "path": "y", + "name": "y", + "properties": {} + } + ], + "targets": [], + "tasks": [] + }, + "groupHeadings": { + "compile": "Compile" + } + } + } + ] +} diff --git a/shared/plugins/contract/v1/README.md b/shared/plugins/contract/v1/README.md index 67ef7168..ab365447 100644 --- a/shared/plugins/contract/v1/README.md +++ b/shared/plugins/contract/v1/README.md @@ -1744,6 +1744,27 @@ changes a plan. than four headings or has an empty heading falls back to the template's, so a tool that reports a bad heading still has its task filed. +Core lays out the window's tree from the model, the same way for every build +tool (`build.modelTree` in the +[Rust Core API](../../../../rust/contracts/rust-core-api.md#build-systems)): + +- Projects nest by `parentID`. A project with no parent in the model, or one + whose parent chain loops back to itself, becomes a root. +- Each project lists, in this order, its tasks in their folders, a + dependencies node when `dependencies.scopes` contains `project`, a targets + node whose targets carry their target-scoped tasks (filtered by + `targetTags`), and its child projects. +- A declared task with a `project` scope appears in every project. A task with + only a `workspace` scope, or one that `requiresUserArguments`, appears once, + beside the root projects; so do workspace dependencies and discovered + tests. When the model has no projects, every `workspace` task appears there. +- When the model has a single root project, that project's contents become + the build system's own, and its tasks still run on the root project. Guard + project-only arguments with `nestedProjectSelected` so running them on the + root builds everything. +- A filter keeps each matching node whole, together with the projects and + folders on the way to it. + A host that draws build-system windows gives each detected build system its own tool window and uses these presentation fields. The host-drawn windows share Build Output, docking, layout restoration, activation, and lifecycle with other workbench contributions. diff --git a/shared/plugins/reference/domains/build-systems.md b/shared/plugins/reference/domains/build-systems.md index 9439ea35..88b4a530 100644 --- a/shared/plugins/reference/domains/build-systems.md +++ b/shared/plugins/reference/domains/build-systems.md @@ -55,7 +55,7 @@ - **选项范围。** 选项可以声明 `scope: "instance"`,按检测到的每个根目录分别保存:改动或重置 `a` 不会影响 `b`。省略范围(或 `"workspace"`)使用工作区和构建系统存储。显式的 `false`、`""`、`[]` 仍然是用户保存的值。实例值不能覆盖工作区选项,工作区值也不能悄悄覆盖实例选项。示例:`build-instance-options`。 - **可执行文件解析。** `invocation.executables` 按偏好顺序列出来源:`projectFile`(项目里的包装脚本,总是运行项目代码)、`environment`、`command`(`PATH` 上的命令名)、`runtime`、`setting`(引用声明为 `file` 的全局设置)和 `toolchain`(工具定义 ID)。可以用 `id`、`priority`、`insertBefore`、`insertAfter` 调整同一个候选集内的顺序。用户配置的路径失败是终止性的,不会回退到后面的候选或提供者自己的查找。示例:`build-tool-path`(`setting`)、`build-toolchains`(`toolchain`)。规则见[可执行文件解析](../../contract/v1/README.md#executable-resolution)。 -- **展示。** 每个启用的构建系统有自己的工具窗口,由宿主按模型绘制;`options[].presentation` 把布尔选项放到工具栏(`toolbar`,需要 `icon`)或把多选选项放成树顶部的清单(`tree`),`tasks[].category` 给任务归类。这些字段不改变任何计划。 +- **展示。** 每个启用的构建系统有自己的工具窗口,由宿主按模型绘制;`options[].presentation` 把布尔选项放到工具栏(`toolbar`,需要 `icon`)或把多选选项放成树顶部的清单(`tree`),`tasks[].category` 给任务归类。这些字段不改变任何计划。树由 Core 统一排布:项目按 `parentID` 嵌套,每个项目下依次是它的任务文件夹、依赖、目标和子项目;只作用于整个工作区的任务、依赖和测试在根项目旁边只出现一次;只有一个根项目时,它的内容直接作为构建系统的内容,任务仍在根项目上运行。 - **项目准备任务。** 项目任务可以声明 `preparation: { purpose, sourceRoles }`,按用途(如 `run`)和内容根角色绑定运行前要执行的任务;宿主从当前模型选出最深的所属项目和内容根,要求恰好一个匹配的声明,不猜任务名,也不回退到约定的任务 ID。示例:`build-providers/build-provider-preparation`。 - **只读模型输入。** 生产者用 `modelSharing: { options: [...] }` 公开规范化的项目、目标和内容根(以及明确列出的普通选项的有效值),消费者用 `modelInputs: [{ pluginID, buildSystemID }]` 读取,最多 8 个槽位。缺失、被禁用或不公开的生产者只会让该槽位 `unavailable`,从不被自动安装或激活;一个生产者不能同时是消费者。示例:`build-model-producer`、`build-model-consumer`。 @@ -152,7 +152,7 @@ A build system's `hostIntegration` and a language server's `hostIntegration` are - **Option scope.** An option may declare `scope: "instance"`, stored separately per detected root: changing or resetting `a` cannot change `b`. Omitting the scope (or `"workspace"`) uses the workspace and build-system storage. Explicit `false`, `""`, and `[]` remain stored user values. Instance values cannot override workspace options, and workspace values cannot silently override an instance option. Example: `build-instance-options`. - **Executable resolution.** `invocation.executables` lists sources in preference order: `projectFile` (a wrapper inside the project; always runs project code), `environment`, `command` (a bare name on `PATH`), `runtime`, `setting` (references a declared global `file` setting), and `toolchain` (a tool-definition ID). `id`, `priority`, `insertBefore`, and `insertAfter` reorder candidates within one candidate set. A configured path that fails is terminal and never falls back to later candidates or to the provider's own lookup. Examples: `build-tool-path` (`setting`) and `build-toolchains` (`toolchain`). The rules are in [Executable resolution](../../contract/v1/README.md#executable-resolution). -- **Presentation.** Every enabled build system gets a tool window of its own, drawn by the host from the model; `options[].presentation` puts a boolean option on the toolbar (`toolbar`, needs an `icon`) or a multiSelect option as a checklist at the top of the tree (`tree`), and `tasks[].category` files a task under headings. None of these fields changes a plan. +- **Presentation.** Every enabled build system gets a tool window of its own, drawn by the host from the model; `options[].presentation` puts a boolean option on the toolbar (`toolbar`, needs an `icon`) or a multiSelect option as a checklist at the top of the tree (`tree`), and `tasks[].category` files a task under headings. None of these fields changes a plan. Core lays out the tree the same way for every tool: projects nest by `parentID`, and each project lists its task folders, its dependencies, its targets and then its child projects; tasks, dependencies and tests that act on the whole workspace appear once, beside the root projects. With a single root project, its contents become the build system's own, and its tasks still run on the root project. - **Project preparation tasks.** A project task may declare `preparation: { purpose, sourceRoles }`, binding the task to run first by purpose (such as `run`) and content-root role. The host selects the deepest owning project and content root from the current model, requires exactly one matching declaration, never guesses a task name, and never falls back to a conventional task ID. Example: `build-providers/build-provider-preparation`. - **Read-only model inputs.** A producer publishes normalized projects, targets, and content roots (and the effective values of explicitly listed ordinary options) with `modelSharing: { options: [...] }`; a consumer reads them with `modelInputs: [{ pluginID, buildSystemID }]`, up to 8 slots. A missing, disabled, or non-public producer only makes that slot `unavailable` and is never installed or activated automatically; a producer cannot also be a consumer. Examples: `build-model-producer` and `build-model-consumer`. diff --git a/shared/plugins/reference/protocol-changelog.md b/shared/plugins/reference/protocol-changelog.md index 922ef533..c8cdf8c2 100644 --- a/shared/plugins/reference/protocol-changelog.md +++ b/shared/plugins/reference/protocol-changelog.md @@ -137,6 +137,7 @@ | PR | 修改人 | API 编号 | 协议 / 能力 | 改了什么 | | --- | --- | --- | --- | --- | +| [#PRNUM](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/PRNUM) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-29 | `buildSystems` 0 内的补充 | Build 工具窗口的树改由 Core 统一排布,所有构建工具一样:项目按模型的 `parentID` 嵌套,每个项目依次列出按 `category`(没有时按 `group`)分好文件夹的任务、`dependencies.scopes` 含 `project` 时的依赖节点、带目标级任务(按 `targetTags` 匹配)的目标节点,然后是子项目;有 `project` 作用域的声明任务出现在每个项目里,只有 `workspace` 作用域或 `requiresUserArguments` 的任务、工作区依赖和测试发现只在根项目旁边出现一次;模型只有一个根项目时,它的内容直接作为构建系统的内容,任务仍在根项目上运行,所以只针对子项目的参数要用 `nestedProjectSelected` 保护。过滤时保留匹配的整个节点和通往它的项目与文件夹。新增宿主命令 `build.modelTree`(Core API 文档“Build model tree”),清单和模型格式不变,没有新增宿主方法、通知或能力版本。 | | [#72](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/72) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-29、API-31 | `buildSystems` 0、`vcsProviders` 0 内的补充 | 构建系统新增可选字段 `layout.hiddenDirectoryNames`([1lck/Lithe-IDEA#1856](https://github.com/1lck/Lithe-IDEA/issues/1856)):插件启用期间所有工作区在任意层级隐藏的目录名,最多 32 个。每个名字是一段路径,忽略 ASCII 大小写比较,不是 glob;是 `.` 或 `..`、有首尾空白、含 `/`、`\`、`*`、`?`、`[`、`]` 或控制字符、以 `!` 开头时,以 `plugin.path.invalid`(字段 `buildSystems[].layout.hiddenDirectoryNames[]`)拒绝。VCS 提供者的目录标记(如 `.svn`)是 VCS 元数据,插件启用期间同样隐藏。Core 不再内置 `.svn`、`.build`、`node_modules`、`target`、`build`、`.gradle`、`.venv` 等工具目录,默认只隐藏自己的 `.git`、`.worktree`、`.worktrees`;宿主用命令 `workspace.configureVisibility` 把已启用插件的清单交给 Core,项目树、搜索、文件事件、本地历史、运行发现、构建探测和 VCS、Git 仓库发现都读这份名单。Search Everywhere 在 `includeGeneratedFileNames` 时仍列出构建系统声明目录里的文件名,不列 VCS 元数据。旧宿主不认识这个字段,会拒绝带它的清单,所以插件要等包含本改动的桌面端发布后再声明。`workspace.configureVisibility` 是宿主调用 Core 的命令,不是插件方法;没有新增宿主方法、通知或能力版本。 | | [#69](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/69) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-23 | `buildSystems` 0 内的修正 | Core 不再把 `go`、`node` 当作宿主管理的运行时([1lck/Lithe-IDEA#1856](https://github.com/1lck/Lithe-IDEA/issues/1856) 第 3 项):`runtimeDependencies` 里没有 `executables` 的运行时一律按同 ID 的工具定义解析,`go`、`node` 也不例外。`build.invocationPlan` 对它们返回 `{ "kind": "toolchain", "toolchainID": , "root": }` 和 `version: null`,不再返回 `{ "kind": "runtime" }` 候选和 Core 自带的版本参数(`["version"]`、`["--version"]`);`build.checkToolVersion` 对它们以 `plugin.build.unavailable` 拒绝,版本由工具定义检查。运行时计划删掉 `hostManaged` 字段。`go`、`node` 写了自己的 `executables` 时按普通运行时校验,不再报“由宿主发现”。已发布的清单不用改:Go 插件本来就提供 `go` 工具定义。没有新增方法、字段或能力版本。 | | [#68](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/68) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-25 | `languageServers` 0 内的补充 | 语言服务器新增可选字段 `indexingExclusions`([1lck/Lithe-IDEA#1856](https://github.com/1lck/Lithe-IDEA/issues/1856)):声明工作区配置里列出排除目录的数组 `section`、一项的写法 `entry`(恰好一个 `${path}`)、根目录写法 `rootEntry?`、配置没有该数组时的 `default?`(最多 32 项)和 `pathSyntax?`(`literal` 默认或 `glob`,`glob` 时名字含通配符的目录不写入)。LSP 引擎只按这份声明把排除目录追加进服务器读到的配置,不再按 `rust`、`go` 识别 rust-analyzer 和 gopls;没有声明的服务器配置不变。启动计划的 `sessionPolicy` 带上这份声明,宿主原样交给 `lsp.startServer`。违反时以 `plugin.manifest.invalid`(字段 `languageServers[].indexingExclusions.`)拒绝。旧宿主不认识这个字段,会拒绝带它的清单,所以 Go 插件要等包含本改动的桌面端发布后再声明。没有新增宿主方法、通知或能力版本。 | From 3e39832b83f9947f1137a2f654e8423dd891fc1e Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Mon, 16 Nov 2026 21:49:24 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat(build):=20=E8=BF=87=E6=BB=A4=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E6=A0=87=E5=87=BA=E5=91=BD=E4=B8=AD=E8=8A=82=E7=82=B9?= =?UTF-8?q?=EF=BC=8C=E5=AE=BF=E4=B8=BB=E6=8D=AE=E6=AD=A4=E5=B1=95=E5=BC=80?= =?UTF-8?q?=E9=80=9A=E5=BE=80=E5=91=BD=E4=B8=AD=E7=9A=84=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rust/contracts/rust-core-api.md | 22 +++++++++------- rust/crates/build/src/tree.rs | 26 ++++++++++++++----- .../crates/core/src/tests/build_model_tree.rs | 4 ++- rust/fixtures/build/model-tree-v1.json | 12 +++++++-- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index f0f56eab..0d266286 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -4807,17 +4807,19 @@ themselves. It reads no file and starts no process. `nodes` holds the instance's nodes, then the root projects. - `query` (at most 256 bytes, no control characters) is trimmed and matched case-insensitively against `label`, `detail` and `tooltip`. A matching node - is kept whole with the nodes on the way to it, an unmatched `dependencies` - node is dropped, and a `tests` node is always kept because its entries load - later. A blank query, or one the single root project matches, keeps - everything. + is kept whole, with `matched: true`, and with the nodes on the way to it, so + a host opens those and shows the match as the user left it; an unmatched + `dependencies` node is dropped, and a `tests` node is always kept because + its entries load later. A blank query, or one the single root project + matches, keeps everything; the matching `project` then carries + `matched: true`. - A node is `{ kind, key, label?, detail?, tooltip?, group?, projectID?, - targetID?, taskID?, children? }`, `kind` one of `project`, `folder`, `task`, - `targets`, `target`, `dependencies`, `tests`. `key` is opaque, unique in the - instance and stable across reloads and filters, so hosts remember open nodes - by it. `projectID` and `targetID` are what a task runs on (absent: the whole - instance); `taskID` is a declared task's ID or a model task's ID. - `targets`, `dependencies` and `tests` nodes have no label. + targetID?, taskID?, matched?, children? }`, `kind` one of `project`, + `folder`, `task`, `targets`, `target`, `dependencies`, `tests`. `key` is + opaque, unique in the instance and stable across reloads and filters, so + hosts remember open nodes by it. `projectID` and `targetID` are what a task + runs on (absent: the whole instance); `taskID` is a declared task's ID or a + model task's ID. `targets`, `dependencies` and `tests` nodes have no label. - The model may hold at most 2,000 projects and 10,000 targets and 10,000 tasks; more is `invalid_request`, as are unknown request fields and group headings that are blank, longer than 120 bytes or contain control diff --git a/rust/crates/build/src/tree.rs b/rust/crates/build/src/tree.rs index 1f7524a5..ccd1f3ef 100644 --- a/rust/crates/build/src/tree.rs +++ b/rust/crates/build/src/tree.rs @@ -157,6 +157,10 @@ struct TreeNode { /// A declared task's ID or a model task's ID. #[serde(rename = "taskID", skip_serializing_if = "String::is_empty")] task_id: String, + /// True on a node the query matches itself, so the host opens the nodes + /// on the way to it and shows the match as the user left it. + #[serde(skip_serializing_if = "std::ops::Not::not")] + matched: bool, #[serde(skip_serializing_if = "Vec::is_empty")] children: Vec, } @@ -173,6 +177,7 @@ impl TreeNode { project_id: String::new(), target_id: String::new(), task_id: String::new(), + matched: false, children: Vec::new(), } } @@ -194,7 +199,7 @@ pub(crate) fn model_tree( left: MAX_NODES, truncated: false, }; - let (project, nodes) = match index.roots.as_slice() { + let (mut project, nodes) = match index.roots.as_slice() { &[root] => ( index.project_node(root, &mut budget), index.contents(Some(root), true, &mut budget), @@ -202,7 +207,10 @@ pub(crate) fn model_tree( _ => (None, index.contents(None, true, &mut budget)), }; let query = request.query.trim().to_lowercase(); - let unfiltered = query.is_empty() || project.as_ref().is_some_and(|node| node.matches(&query)); + if let Some(node) = project.as_mut() { + node.matched = !query.is_empty() && node.matches(&query); + } + let unfiltered = query.is_empty() || project.as_ref().is_some_and(|node| node.matched); let tree = ModelTree { project, nodes: if unfiltered { @@ -215,15 +223,19 @@ pub(crate) fn model_tree( Ok(serde_json::to_value(tree).expect("a model tree serializes")) } -/// Keeps the nodes that match `query`, each with its whole subtree, and the -/// nodes on the way to them. Dependencies are loaded by the host, so their -/// node stays only inside a match; tests are filtered by the host, so their -/// node always stays. +/// Keeps the nodes that match `query`, marked and each with its whole +/// subtree, and the nodes on the way to them. Dependencies are loaded by the +/// host, so their node stays only inside a match; tests are filtered by the +/// host, so their node always stays. fn filter(nodes: Vec, query: &str) -> Vec { nodes .into_iter() .filter_map(|mut node| { - if node.kind == NodeKind::Tests || node.matches(query) { + if node.kind == NodeKind::Tests { + return Some(node); + } + if node.matches(query) { + node.matched = true; return Some(node); } if node.kind == NodeKind::Dependencies { diff --git a/rust/crates/core/src/tests/build_model_tree.rs b/rust/crates/core/src/tests/build_model_tree.rs index 4c2bc5ae..f0e39a82 100644 --- a/rust/crates/core/src/tests/build_model_tree.rs +++ b/rust/crates/core/src/tests/build_model_tree.rs @@ -64,9 +64,11 @@ fn model_tree_keeps_every_node_when_the_root_project_matches() { let case = &fixture["cases"][0]; let mut request = case["request"].clone(); request["query"] = json!(" APP "); + let mut expected = case["expected"].clone(); + expected["project"]["matched"] = json!(true); assert_eq!( tree(&fixture["manifest"], &case["buildSystemID"], &request), - case["expected"] + expected ); } diff --git a/rust/fixtures/build/model-tree-v1.json b/rust/fixtures/build/model-tree-v1.json index 01b26211..801e7f3a 100644 --- a/rust/fixtures/build/model-tree-v1.json +++ b/rust/fixtures/build/model-tree-v1.json @@ -893,6 +893,7 @@ "label": "api", "detail": "core/api", "projectID": "nested:core/api/api", + "matched": true, "children": [ { "kind": "folder", @@ -1103,6 +1104,7 @@ "key": "p\u001fnested:app\u001fg\u001fverification", "label": "Verification", "group": "verification", + "matched": true, "children": [ { "kind": "task", @@ -1125,6 +1127,7 @@ "key": "p\u001fnested:core/core\u001fg\u001fverification", "label": "Verification", "group": "verification", + "matched": true, "children": [ { "kind": "task", @@ -1147,6 +1150,7 @@ "key": "p\u001fnested:core/api/api\u001fg\u001fverification", "label": "Verification", "group": "verification", + "matched": true, "children": [ { "kind": "task", @@ -1173,6 +1177,7 @@ "key": "p\u001fnested:web/web\u001fg\u001fverification", "label": "Verification", "group": "verification", + "matched": true, "children": [ { "kind": "task", @@ -1353,6 +1358,7 @@ "tooltip": "example.com/app/web/server", "projectID": "nested:web/web", "targetID": "nested:web/server/application/server", + "matched": true, "children": [ { "kind": "task", @@ -1875,7 +1881,8 @@ "key": "p\u001fflat:x\u001fg\u001fbuild\u001ft\u001fassemble", "label": "Assemble", "projectID": "flat:x", - "taskID": "assemble" + "taskID": "assemble", + "matched": true } ] } @@ -1899,7 +1906,8 @@ "key": "p\u001fflat:y\u001fg\u001fbuild\u001ft\u001fassemble", "label": "Assemble", "projectID": "flat:y", - "taskID": "assemble" + "taskID": "assemble", + "matched": true } ] } From f87d59c4ffc3269992a05e0fd25577db49f5eb94 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Mon, 16 Nov 2026 22:58:51 +0800 Subject: [PATCH 3/3] =?UTF-8?q?docs(plugins):=20=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AE=B0=E5=BD=95=E5=A1=AB=E4=B8=8A=20build.?= =?UTF-8?q?modelTree=20=E7=9A=84=20PR=20=E7=BC=96=E5=8F=B7=20#76?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/plugins/reference/protocol-changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/plugins/reference/protocol-changelog.md b/shared/plugins/reference/protocol-changelog.md index c8cdf8c2..200d5650 100644 --- a/shared/plugins/reference/protocol-changelog.md +++ b/shared/plugins/reference/protocol-changelog.md @@ -137,7 +137,7 @@ | PR | 修改人 | API 编号 | 协议 / 能力 | 改了什么 | | --- | --- | --- | --- | --- | -| [#PRNUM](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/PRNUM) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-29 | `buildSystems` 0 内的补充 | Build 工具窗口的树改由 Core 统一排布,所有构建工具一样:项目按模型的 `parentID` 嵌套,每个项目依次列出按 `category`(没有时按 `group`)分好文件夹的任务、`dependencies.scopes` 含 `project` 时的依赖节点、带目标级任务(按 `targetTags` 匹配)的目标节点,然后是子项目;有 `project` 作用域的声明任务出现在每个项目里,只有 `workspace` 作用域或 `requiresUserArguments` 的任务、工作区依赖和测试发现只在根项目旁边出现一次;模型只有一个根项目时,它的内容直接作为构建系统的内容,任务仍在根项目上运行,所以只针对子项目的参数要用 `nestedProjectSelected` 保护。过滤时保留匹配的整个节点和通往它的项目与文件夹。新增宿主命令 `build.modelTree`(Core API 文档“Build model tree”),清单和模型格式不变,没有新增宿主方法、通知或能力版本。 | +| [#76](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/76) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-29 | `buildSystems` 0 内的补充 | Build 工具窗口的树改由 Core 统一排布,所有构建工具一样:项目按模型的 `parentID` 嵌套,每个项目依次列出按 `category`(没有时按 `group`)分好文件夹的任务、`dependencies.scopes` 含 `project` 时的依赖节点、带目标级任务(按 `targetTags` 匹配)的目标节点,然后是子项目;有 `project` 作用域的声明任务出现在每个项目里,只有 `workspace` 作用域或 `requiresUserArguments` 的任务、工作区依赖和测试发现只在根项目旁边出现一次;模型只有一个根项目时,它的内容直接作为构建系统的内容,任务仍在根项目上运行,所以只针对子项目的参数要用 `nestedProjectSelected` 保护。过滤时保留匹配的整个节点和通往它的项目与文件夹。新增宿主命令 `build.modelTree`(Core API 文档“Build model tree”),清单和模型格式不变,没有新增宿主方法、通知或能力版本。 | | [#72](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/72) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-29、API-31 | `buildSystems` 0、`vcsProviders` 0 内的补充 | 构建系统新增可选字段 `layout.hiddenDirectoryNames`([1lck/Lithe-IDEA#1856](https://github.com/1lck/Lithe-IDEA/issues/1856)):插件启用期间所有工作区在任意层级隐藏的目录名,最多 32 个。每个名字是一段路径,忽略 ASCII 大小写比较,不是 glob;是 `.` 或 `..`、有首尾空白、含 `/`、`\`、`*`、`?`、`[`、`]` 或控制字符、以 `!` 开头时,以 `plugin.path.invalid`(字段 `buildSystems[].layout.hiddenDirectoryNames[]`)拒绝。VCS 提供者的目录标记(如 `.svn`)是 VCS 元数据,插件启用期间同样隐藏。Core 不再内置 `.svn`、`.build`、`node_modules`、`target`、`build`、`.gradle`、`.venv` 等工具目录,默认只隐藏自己的 `.git`、`.worktree`、`.worktrees`;宿主用命令 `workspace.configureVisibility` 把已启用插件的清单交给 Core,项目树、搜索、文件事件、本地历史、运行发现、构建探测和 VCS、Git 仓库发现都读这份名单。Search Everywhere 在 `includeGeneratedFileNames` 时仍列出构建系统声明目录里的文件名,不列 VCS 元数据。旧宿主不认识这个字段,会拒绝带它的清单,所以插件要等包含本改动的桌面端发布后再声明。`workspace.configureVisibility` 是宿主调用 Core 的命令,不是插件方法;没有新增宿主方法、通知或能力版本。 | | [#69](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/69) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-23 | `buildSystems` 0 内的修正 | Core 不再把 `go`、`node` 当作宿主管理的运行时([1lck/Lithe-IDEA#1856](https://github.com/1lck/Lithe-IDEA/issues/1856) 第 3 项):`runtimeDependencies` 里没有 `executables` 的运行时一律按同 ID 的工具定义解析,`go`、`node` 也不例外。`build.invocationPlan` 对它们返回 `{ "kind": "toolchain", "toolchainID": , "root": }` 和 `version: null`,不再返回 `{ "kind": "runtime" }` 候选和 Core 自带的版本参数(`["version"]`、`["--version"]`);`build.checkToolVersion` 对它们以 `plugin.build.unavailable` 拒绝,版本由工具定义检查。运行时计划删掉 `hostManaged` 字段。`go`、`node` 写了自己的 `executables` 时按普通运行时校验,不再报“由宿主发现”。已发布的清单不用改:Go 插件本来就提供 `go` 工具定义。没有新增方法、字段或能力版本。 | | [#68](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/68) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-25 | `languageServers` 0 内的补充 | 语言服务器新增可选字段 `indexingExclusions`([1lck/Lithe-IDEA#1856](https://github.com/1lck/Lithe-IDEA/issues/1856)):声明工作区配置里列出排除目录的数组 `section`、一项的写法 `entry`(恰好一个 `${path}`)、根目录写法 `rootEntry?`、配置没有该数组时的 `default?`(最多 32 项)和 `pathSyntax?`(`literal` 默认或 `glob`,`glob` 时名字含通配符的目录不写入)。LSP 引擎只按这份声明把排除目录追加进服务器读到的配置,不再按 `rust`、`go` 识别 rust-analyzer 和 gopls;没有声明的服务器配置不变。启动计划的 `sessionPolicy` 带上这份声明,宿主原样交给 `lsp.startServer`。违反时以 `plugin.manifest.invalid`(字段 `languageServers[].indexingExclusions.`)拒绝。旧宿主不认识这个字段,会拒绝带它的清单,所以 Go 插件要等包含本改动的桌面端发布后再声明。没有新增宿主方法、通知或能力版本。 |