Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ or removing a command fails until the table changes in the same commit.
| `toolchains.discoveryPlan` | Return platform-filtered definition-owned scan declarations, layouts, probes, PATH entries, login-shell home variables, project-file candidates and budgets; never scans native directories |
| `toolchains.candidates` | List one tool's root project-file candidates, login-shell homes (declared `environment` variables and, from the optional `commandHomes`, declared commands found on the PATH) and host-scanned installations with checked executables, versions or skip reasons, and the automatic-layer choice; never starts a probe. A shell home that checks out is also an `installations` entry with provider `host:shell`, once per canonical home, so a picker can offer every home the resolver may run; `selected` remains the automatic layer's own choice |
| `toolchains.instantiateLaunch` | Expand an enabled tool definition's `launch` template for a selected executable, entry, runtime arguments and arguments; a part the template cannot carry is `plugin.toolchain.launchMismatch`; performs no I/O |
| `toolchains.settingsView` | Project the settings list of every enabled tool from host-held facts: classify each resolver reason as `error`, `warning` or `ok`, filter by text and by problems, pins or pending edits, group by definition category (plugin-only runtimes last), plugin or nothing, apply default and user folding, and return rows, the first issues and counts; performs no resolution or I/O |
| `run.decodeStart` | Validate a plugin backend's `lithe/host/run/start` params against its manifest and the workspace, and return the normalized start with temporary-file paths substituted |
| `debug.decodeBackendConfiguration` | Validate a plugin backend's `lithe/host/debug/start` params against its manifest and return the qualified adapter, request, label and configuration |
| `outputLinks.match` | Find the links plugin `outputLinkMatchers` declare in Run or Test console lines, as UTF-16 ranges with candidate paths or a backend function to resolve them, and the web addresses the lines print, as `url` links the host opens in the browser |
Expand Down Expand Up @@ -7133,11 +7134,14 @@ Names come from enabled language/build declarations, with opaque ID fallback.
section titles translated when the state is. Catalog contributor sections keep
the manifest headings.

`plugins.settings.navigation` accepts at most 576 two-level `items` (512 contributed pages plus 64 host entries) with stable
`id`, `title`, nullable `parent`, `group`, `expanded`, optional `keywords`, plus
`query` (at most 1024 bytes). It returns `rows` containing id/title/group/expanded/level.
Search retains ancestors and expands matching groups; ordering follows input.
Duplicate IDs, invalid parents and excessive input are rejected.
`plugins.settings.navigation` accepts at most 576 `items` (512 contributed pages plus 64 host entries), up to three levels
deep, with stable `id`, `title`, nullable `parent`, `group`, `expanded`, optional `keywords` and optional `limit`
(1–512), plus `query` (at most 1024 bytes). It returns `rows` containing id/title/group/expanded/level, `matched`
(the row itself matches the query) and `path` (ancestor titles, root first). Outside search, an item with `limit`
shows that many children followed by one overflow row `{id,title,level,path,overflow}` that carries the item's own
ID and the total child count, so the host can open the item's directory page. Search retains ancestors, shows every
descendant of a matched item and ignores `limit`; ordering follows input. Duplicate IDs, a parent chain that is
missing, cyclic or deeper than three levels, a zero limit and excessive input are rejected.

`plugins.settings.delivery` accepts `scope` (global/project), native equality
facts `samePreferences`, `sameWorkspace`, `sameVersion`, current `enabled`, and
Expand Down
3 changes: 3 additions & 0 deletions rust/crates/core/src/protocol/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ pub enum ToolchainsCommand {
Candidates,
/// Expands a tool definition's launch template for a selected executable.
InstantiateLaunch,
/// Projects the settings list of every enabled tool: status, filter, groups and counts.
SettingsView,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -1170,6 +1172,7 @@ impl CoreCommand {
"toolchains.instantiateLaunch" => {
Some(Self::Toolchains(ToolchainsCommand::InstantiateLaunch))
}
"toolchains.settingsView" => Some(Self::Toolchains(ToolchainsCommand::SettingsView)),
"run.decodeStart" => Some(Self::RunDecodeStart),
"debug.decodeBackendConfiguration" => {
Some(Self::Debug(DebugCommand::DecodeBackendConfiguration))
Expand Down
3 changes: 3 additions & 0 deletions rust/crates/core/src/runtime/dispatcher/toolchains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,8 @@ pub(super) fn dispatch(
lithe_plugin_manifest::validated_manifest_json,
)
}),
ToolchainsCommand::SettingsView => {
plugin_response(id, payload, crate::toolchain::settings_view_command)
}
}
}
67 changes: 67 additions & 0 deletions rust/crates/core/src/tests/plugin_settings_documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,73 @@ fn settings_navigation_reserves_capacity_for_host_rows() {
assert_eq!(response["data"]["rows"].as_array().unwrap().len(), 513);
}

fn build_tree(languages: usize) -> Vec<Value> {
let mut items = vec![
json!({"id":"build","title":"Build","parent":null,"group":true,"expanded":true}),
json!({"id":"toolchains","title":"Toolchains","parent":"build","group":false,"expanded":false}),
json!({"id":"kind:language","title":"Languages","parent":"build","group":true,"expanded":true,"limit":6}),
];
for index in 0..languages {
items.push(json!({"id":format!("language:{index}"),"title":format!("Language {index}"),"parent":"kind:language","group":false,"expanded":false,"keywords":if index == 9 {"cargo"} else {""}}));
}
items
}

fn navigation_rows(items: Vec<Value>, query: &str) -> Vec<Value> {
let response = execute(
"plugins.settings.navigation",
json!({"items":items,"query":query}),
);
assert_eq!(response["data"]["status"], "ok", "{response}");
response["data"]["rows"].as_array().unwrap().clone()
}

/// A kind fold under a group shows its first `limit` pages and one overflow row
/// that counts every page; search ignores the limit and lists hits with their path.
#[test]
fn settings_navigation_folds_a_third_level_behind_an_overflow_row() {
let rows = navigation_rows(build_tree(12), "");
assert_eq!(rows.len(), 3 + 6 + 1);
assert_eq!(rows[2]["level"], 1);
assert_eq!(rows[3]["level"], 2);
let overflow = &rows[9];
assert_eq!(overflow["id"], "kind:language");
assert_eq!(overflow["overflow"], 12);
assert_eq!(overflow["level"], 2);
assert_eq!(overflow["path"], json!(["Build", "Languages"]));
assert!(rows.iter().all(|row| row["matched"] == false));

let rows = navigation_rows(build_tree(12), "CARGO");
let ids: Vec<_> = rows.iter().map(|row| row["id"].clone()).collect();
assert_eq!(ids, ["build", "kind:language", "language:9"]);
assert_eq!(rows[2]["matched"], true);
assert_eq!(rows[2]["path"], json!(["Build", "Languages"]));
assert_eq!(rows[0]["matched"], false);

// A matched fold shows every page below it, still without the limit.
let rows = navigation_rows(build_tree(12), "languages");
assert_eq!(rows.len(), 2 + 12);
assert!(rows.iter().all(|row| row.get("overflow").is_none()));
}

#[test]
fn settings_navigation_rejects_a_fourth_level_cycles_and_empty_limits() {
let mut deep = build_tree(1);
deep.push(json!({"id":"too-deep","title":"Deep","parent":"language:0","group":false,"expanded":false}));
let mut cycle = build_tree(0);
cycle.push(json!({"id":"a","title":"A","parent":"b","group":false,"expanded":false}));
cycle.push(json!({"id":"b","title":"B","parent":"a","group":false,"expanded":false}));
let mut empty = build_tree(1);
empty[2]["limit"] = json!(0);
for items in [deep, cycle, empty] {
let response = execute(
"plugins.settings.navigation",
json!({"items":items,"query":""}),
);
assert_eq!(response["data"]["status"], "rejected", "{response}");
}
}

fn contract_settings_file(name: &str) -> String {
std::fs::read_to_string(format!(
"{}/../../../shared/plugins/contract/v1/fixtures/settings/{name}",
Expand Down
37 changes: 37 additions & 0 deletions rust/crates/core/src/tests/toolchain_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,43 @@ fn tool_definitions_second_tool_needs_only_plugin_data() {
}
}

/// `category` and `audience` only group a tool on the settings page, so they pass
/// through the registry unchanged and accept only the fixed display values.
#[test]
fn tool_definitions_declare_settings_category_and_audience() {
let mut tagged = definition("dev.lithe.fixture.compiler:compiler");
tagged["category"] = json!("build");
tagged["audience"] = json!("plugin");
let mut plugin = manifest("dev.lithe.fixture.compiler", tagged);
// The fields are toolDefinitions 1, so a host that supports only 0 never installs it.
let rejected = validate_manifest_value(plugin.clone())
.err()
.expect("version 0 refuses settings categories");
assert_eq!(rejected.field.as_deref(), Some("requires.toolDefinitions"));
plugin["requires"]["toolDefinitions"] = json!(1);
assert!(validate_manifest_value(plugin.clone()).is_ok());
let result = registry(
&json!({"plugins":[{"manifest":plugin}]}),
validated_manifest_json,
)
.unwrap();
let registered = &result["definitions"][0]["definition"];
assert_eq!(registered["category"], "build");
assert_eq!(registered["audience"], "plugin");
for (field, value) in [
("category", json!("compiler")),
("category", json!(1)),
("audience", json!("system")),
] {
let mut changed = definition("dev.lithe.fixture.compiler:compiler");
changed[field] = value;
assert!(
validate_declarations("dev.lithe.fixture.compiler", &[changed], &[]).is_err(),
"{field}"
);
}
}

/// No plugin needs a host-attested origin for a short ID.
#[test]
fn registry_accepts_short_ids_from_any_enabled_plugin() {
Expand Down
5 changes: 5 additions & 0 deletions rust/crates/core/src/tests/toolchain_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ fn toolchain_commands_cross_the_json_dispatch_boundary() {
),
("toolchains.resolve", input(), "resolution"),
("toolchains.candidates", listing(&input()), "candidates"),
(
"toolchains.settingsView",
json!({"tools":[{"id":"java","displayName":"JDK","pluginID":"dev.lithe.fixture","reason":"notFound"}],"query":{"filter":"problems"}}),
"view",
),
] {
let response: Value = serde_json::from_str(&crate::execute_json(
&json!({"id":"toolchains","command":command,"payload":payload}).to_string(),
Expand Down
134 changes: 97 additions & 37 deletions rust/crates/plugin-manifest/src/settings_surfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn settings_catalog_command(payload: Value) -> Result<Value, CoreError> {
}

/// Native static page labels and stable identifiers. Hierarchy is supplied once;
/// search, expansion and ancestor retention are shared projection rules.
/// search, expansion, folding and ancestor retention are shared projection rules.
#[derive(Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
struct NavigationItem {
Expand All @@ -115,6 +115,10 @@ struct NavigationItem {
expanded: bool,
#[serde(default)]
keywords: String,
/// Shows at most this many children outside search; the rest fold into one
/// overflow row that opens the group's own directory page.
#[serde(default)]
limit: Option<usize>,
}

#[derive(Deserialize)]
Expand All @@ -124,64 +128,120 @@ struct NavigationRequest {
query: String,
}

/// Projects a bounded two-level settings tree; matched descendants retain their
/// parent and a matched parent shows its children, including dynamic surfaces.
/// The deepest level a row may sit at: group, kind fold, page.
const MAX_LEVEL: usize = 2;

struct Navigation<'a> {
items: &'a [NavigationItem],
query: String,
rows: Vec<Value>,
}

impl<'a> Navigation<'a> {
fn matches(&self, item: &NavigationItem) -> bool {
!self.query.is_empty()
&& (item.title.to_lowercase().contains(&self.query)
|| item.keywords.to_lowercase().contains(&self.query))
}

fn children(&self, id: &str) -> Vec<&'a NavigationItem> {
self.items
.iter()
.filter(|item| item.parent.as_deref() == Some(id))
.collect()
}

/// Whether the item, or any item below it, matches the search.
fn hit(&self, item: &NavigationItem) -> bool {
self.matches(item) || self.children(&item.id).iter().any(|child| self.hit(child))
}

fn emit(&mut self, item: &'a NavigationItem, level: usize, path: &[&'a str], shown: bool) {
let searching = !self.query.is_empty();
let own = self.matches(item);
// A matched item shows everything below it; otherwise only matching branches.
if searching && !shown && !self.hit(item) {
return;
}
self.rows.push(json!({
"id":item.id,"title":item.title,"group":item.group,
"expanded":searching || item.expanded,"level":level,
"matched":own,"path":path,
}));
if item.group && !item.expanded && !searching {
return;
}
let children = self.children(&item.id);
let limit = match item.limit {
Some(limit) if !searching => limit,
_ => children.len(),
};
let mut below = path.to_vec();
below.push(&item.title);
for child in children.iter().take(limit) {
self.emit(child, level + 1, &below, shown || own);
}
if children.len() > limit {
self.rows.push(json!({
"id":item.id,"title":item.title,"group":false,"expanded":false,
"level":level + 1,"matched":false,"path":below,"overflow":children.len(),
}));
}
}
}

/// Projects a bounded settings tree of up to three levels: a matched item keeps its
/// ancestors and shows its descendants, including dynamic surfaces. Each row carries
/// `matched` and the ancestor `path`, so a host can list search hits flat with their
/// location.
pub fn settings_navigation_command(payload: Value) -> Result<Value, CoreError> {
let request: NavigationRequest = decode_payload(payload, "plugins.settings.navigation")?;
Ok(outcome((|| {
if request.items.len() > MAX_PAGES + 64 || request.query.len() > 1024 {
return Err(rejected("navigation"));
}
let query = request.query.trim().to_lowercase();
let mut ids = BTreeSet::new();
for item in &request.items {
if item.id.is_empty()
|| item.id.len() > 256
|| item.title.len() > 1024
|| item.keywords.len() > 16384
|| item
.limit
.is_some_and(|limit| limit == 0 || limit > MAX_PAGES)
|| !ids.insert(&item.id)
{
return Err(rejected("items"));
}
}
let parent_of = |id: &str| {
request
.items
.iter()
.find(|candidate| candidate.id == id)
.map(|candidate| candidate.parent.as_deref())
};
for item in &request.items {
if let Some(parent) = &item.parent {
if !request
.items
.iter()
.any(|candidate| &candidate.id == parent && candidate.parent.is_none())
{
return Err(rejected("parent"));
}
// Walking up must reach a root within MAX_LEVEL steps; this also rules out cycles.
let mut current = item.parent.as_deref();
let mut depth = 0;
while let Some(parent) = current {
depth += 1;
current = match parent_of(parent) {
Some(next) if depth <= MAX_LEVEL => next,
_ => return Err(rejected("parent")),
};
}
}
let matches = |item: &NavigationItem| {
item.title.to_lowercase().contains(&query)
|| item.keywords.to_lowercase().contains(&query)
let mut navigation = Navigation {
items: &request.items,
query: request.query.trim().to_lowercase(),
rows: Vec::new(),
};
let row = |item: &NavigationItem, level: usize| json!({"id":item.id,"title":item.title,"group":item.group,"expanded":!query.is_empty() || item.expanded,"level":level});
let mut result = Vec::new();
for parent in request.items.iter().filter(|item| item.parent.is_none()) {
let children: Vec<_> = request
.items
.iter()
.filter(|item| item.parent.as_ref() == Some(&parent.id))
.collect();
let own = matches(parent);
if !own && !children.iter().any(|child| matches(child)) {
continue;
}
result.push(row(parent, 0));
if !parent.group || parent.expanded || !query.is_empty() {
result.extend(
children
.into_iter()
.filter(|child| own || matches(child))
.map(|child| row(child, 1)),
);
}
for root in request.items.iter().filter(|item| item.parent.is_none()) {
navigation.emit(root, 0, &[], false);
}
Ok(("rows", json!(result)))
Ok(("rows", json!(navigation.rows)))
})()))
}

Expand Down
12 changes: 12 additions & 0 deletions rust/crates/plugin-manifest/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ impl DeclarativePluginManifest {
"Entrypoint runs need buildProviders 1.",
));
}
if self.tool_definitions.iter().any(|definition| {
definition.get("category").is_some() || definition.get("audience").is_some()
}) && self
.requires
.get(capabilities::TOOL_DEFINITIONS)
.is_none_or(|version| *version < 1)
{
return Err(invalid(
"requires.toolDefinitions",
"Settings categories and audiences need toolDefinitions 1.",
));
}
if self.languages.is_empty()
&& self.ui.is_none()
&& self.build_systems.is_empty()
Expand Down
Loading
Loading