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
24 changes: 23 additions & 1 deletion rust/crates/plugin-manifest/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! same results; the host only renders.

use crate::{validate_manifest_value, DeclarativePluginManifest};
use lithe_plugin_model::{decode_payload, outcome, PluginRejection, Validation};
use lithe_plugin_model::{capabilities, decode_payload, outcome, PluginRejection, Validation};
use lithe_plugin_ui::{Context, Surface, INVALID_VIEW};
use lithe_protocol::CoreError;
use serde::Deserialize;
Expand Down Expand Up @@ -55,6 +55,7 @@ pub fn apply_result_command(payload: Value) -> Result<Value, CoreError> {
settings: &manifest.settings,
actions: &manifest.setting_actions,
tools: &tools,
ui_version: manifest.capability_version(capabilities::UI),
};
let (view, changed) =
lithe_plugin_ui::apply(&context, payload.view.as_ref(), &payload.result)?;
Expand Down Expand Up @@ -196,6 +197,27 @@ mod tests {
assert_eq!(outcome["error"]["code"], INVALID_VIEW);
}

#[test]
fn a_tool_picker_follows_the_declared_ui_version() {
let picker = json!({"view": [{"type": "tool", "tool": "node", "choose": true}]});
let outcome = apply(json!({"settingRegionID": "overview"}), None, picker.clone());
assert_eq!(outcome["status"], "rejected", "{outcome}");
assert_eq!(
outcome["error"]["field"], "result.view[0].choose",
"{outcome}"
);

let mut manifest = manifest();
manifest["requires"]["ui"] = json!(1);
let outcome = apply_result_command(json!({
"manifest": manifest,
"surface": {"settingRegionID": "overview"},
"result": picker,
}))
.expect("outcome");
assert_eq!(outcome["status"], "ok", "{outcome}");
}

#[test]
fn only_declared_view_surfaces_accept_results() {
for surface in [
Expand Down
5 changes: 3 additions & 2 deletions rust/crates/plugin-model/src/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ pub const SETTINGS: &str = "settings";
/// compiler pages and guarded native staging receipts.
pub const SOURCE_SETTINGS: &str = "sourceSettings";
/// `ui`: tool windows with text, web, or plugin view content, plugin views in
/// settings regions, and commands.
/// settings regions, and commands. Version 1 adds the tool picker: a settings
/// region's tool row with `choose`.
pub const UI: &str = "ui";
/// Declarative build detection, models, and command plans.
/// Version 1 adds command-based test discovery. Version 2 adds registry
Expand Down Expand Up @@ -150,7 +151,7 @@ pub const SUPPORTED_CAPABILITIES: &[(&str, &[u32])] = &[
(SOURCE_SETTINGS, &[0, 1]),
(TOOL_DEFINITIONS, &[0, 1]),
(TOOLCHAIN_PROVIDERS, &[0]),
(UI, &[0]),
(UI, &[0, 1]),
(VCS_PROVIDERS, &[0]),
];

Expand Down
31 changes: 31 additions & 0 deletions rust/crates/plugin-ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ pub struct Context<'a> {
pub actions: &'a [SettingAction],
/// Tools the plugin defines or requires; tool rows name them.
pub tools: &'a BTreeSet<String>,
/// The `ui` capability version the manifest declares (`requires.ui`); a
/// tool row with `choose` needs version 1.
pub ui_version: u32,
}

/// Checks a complete view against the vocabulary, the budgets and the
Expand Down Expand Up @@ -163,6 +166,7 @@ mod tests {
settings: &self.settings,
actions: &self.actions,
tools: &self.tools,
ui_version: 0,
}
}
}
Expand Down Expand Up @@ -305,6 +309,33 @@ mod tests {
);
}

#[test]
fn a_tool_picker_needs_ui_1() {
let fixture = Fixture::new();
let picker = json!([{"type":"tool","tool":"maven","choose":true}]);
assert_eq!(
field(&fixture.context(Surface::Settings), picker.clone()),
"view[0].choose"
);
let settings = Context {
ui_version: 1,
..fixture.context(Surface::Settings)
};
check(&settings, &picker).expect("tool picker with ui 1");
assert_eq!(
field(
&settings,
json!([{"type":"tool","tool":"maven","choose":"yes"}])
),
"view[0].choose"
);
let tool_window = Context {
ui_version: 1,
..fixture.context(Surface::ToolWindow)
};
assert_eq!(field(&tool_window, picker), "view[0]");
}

#[test]
fn host_control_nodes_refuse_unknown_and_malformed_fields() {
let fixture = Fixture::new();
Expand Down
9 changes: 8 additions & 1 deletion rust/crates/plugin-ui/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<'c> Walk<'c> {
}
"tool" => {
self.settings_only(path, kind)?;
let map = object(value, path, &["type", "id", "tool"])?;
let map = object(value, path, &["type", "id", "tool", "choose"])?;
self.id(map, path, false)?;
let tool = string(map, path, "tool", true)?.unwrap_or_default();
if !self.context.tools.contains(tool) {
Expand All @@ -170,6 +170,13 @@ impl<'c> Walk<'c> {
"A tool row names a tool this plugin defines or requires.",
));
}
boolean(map, path, "choose")?;
if map.contains_key("choose") && self.context.ui_version < 1 {
return Err(fail(
at(path, "choose"),
"A tool row with choose needs ui 1 in requires.",
));
}
Ok(())
}
"tree" => self.tree(value, path),
Expand Down
33 changes: 30 additions & 3 deletions shared/plugins/contract/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5501,7 +5501,8 @@ holds golden `plugins.ui.applyResult` cases.
`view: {function}` names a private [plugin function](#plugin-functions) of the
plugin's own [backend](#plugin-backend) (letters and digits in dot-separated
segments, at most 128 characters). A manifest with a view needs `backend`,
`requires.ui: 0`, the `ui.contribute` permission, and, for a settings region,
`requires.ui` (0, or 1 for a [tool picker](#tool-rows-and-pickers)), the
`ui.contribute` permission, and, for a settings region,
`requires.settings: 0`. A tool window still declares `onView:<id>`; a settings
region starts the backend when its page opens. Results are described by
[`plugin-ui.schema.json`](plugin-ui.schema.json); the rules JSON Schema cannot
Expand All @@ -5510,7 +5511,12 @@ express are listed below and enforced by Core.
#### Events

The host calls the view function through `lithe/function/invoke` once per
event, with these params:
event, with these params. A view shown for a workspace, such as a tool window
or a settings page opened from a project window, is called with that window's
[workspace context](#workspace-contexts-and-capability-discovery) as
`params.context` of the invoke, so the backend can use it for host methods that
take one, such as [`run/start`](#run-and-debug-sessions) in answer to a
`click`; a view shown without a workspace is called without one.

| Field | Meaning |
| --- | --- |
Expand Down Expand Up @@ -5587,7 +5593,7 @@ view must pass every rule a whole view does.
| `table` | 1–16 `columns` `{title, align}`, up to 256 `rows` | Read-only; each row has one single-line cell per column |
| `banner` | `text`, `tone` | A message across the view |
| `setting` | `setting` | The host's own row for a declared setting, exactly as the page draws it |
| `tool` | `tool` | The host's row for a tool the plugin defines (`toolDefinitions`) or requires (`requiresTools`), as the toolchain pages draw it |
| `tool` | `tool`, `choose` | The host's row for a tool the plugin defines (`toolDefinitions`) or requires (`requiresTools`), as the toolchain pages draw it; with `choose`, also its [picker](#tool-rows-and-pickers) |
| `tree` | `id`, `label`, `items` `{id, label, icon, detail, expanded, children}` | An outline; sends `select` and `activate` |
| `canvas` | Below | A vector scene |

Expand All @@ -5608,6 +5614,27 @@ declared rows; a region never stores values of its own. Writing a tool's own
configuration, such as a build file, stays a setting action of the plugin and
follows [source-backed settings](#source-backed-settings-editors).

#### Tool rows and pickers

A `tool` row shows what the host resolves the tool to in the settings page's
scope (the global settings, or the project of a project window): the version,
the home, and the reason when nothing resolves. Pressing it opens the tool on
the host's toolchain page.

With `choose: true`, which needs `requires.ui: 1`, the row is also the tool's
picker, like an interpreter menu: pressing it opens the host's choices for the
tool in that scope, the same choices the toolchain page lists. They are the
automatic choice, every installation the host found or the user added, with
its version and source, and adding an installation directory, plus a way to
the toolchain page. Choosing one edits the settings window's draft for the
tool, which Apply commits and Cancel discards, as on the toolchain page; the
row shows the pending choice until then. A region never stores the choice
itself; once applied, the plugin's launches and runs receive the chosen
installation as they receive any resolved tool (see
[Tool references](#tool-references)). A plugin that writes `choose`
with `requires.ui: 0` has the whole result refused with `plugin.ui.invalidView`
at `choose`.

#### Canvas

```json
Expand Down
6 changes: 6 additions & 0 deletions shared/plugins/contract/v1/fixtures/ui/view-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@
"result": {"view": [{"type": "tree", "id": "modules", "items": []}]},
"expected": {"status": "rejected", "field": "result.view[0]"}
},
{
"name": "a tool picker needs ui 1, which this manifest does not declare",
"surface": {"settingRegionID": "overview"},
"result": {"view": [{"type": "tool", "tool": "node", "choose": true}]},
"expected": {"status": "rejected", "field": "result.view[0].choose"}
},
{
"name": "a patch that misses refuses the whole result",
"surface": {"toolWindowID": "dev.lithe.fixture.view-panel.explorer"},
Expand Down
2 changes: 1 addition & 1 deletion shared/plugins/contract/v1/plugin-manifest.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"toolchainProviders": { "enum": [0] },
"keymapImportProviders": { "enum": [0] },
"pluginFunctions": { "description": "Required exactly when pluginFunctions is present: functions this plugin's backend exports to other plugins, and exported functions it calls. Needs backend.", "enum": [0] },
"ui": { "description": "Required exactly when ui is present or a settings region declares a view. Covers tool windows with text, web content, or a plugin view, settings-region views, and backend-only commands.", "enum": [0] },
"ui": { "description": "Required exactly when ui is present or a settings region declares a view. Covers tool windows with text, web content, or a plugin view, settings-region views, and backend-only commands. Version 1 adds the tool picker (choose on a settings region's tool row).", "enum": [0, 1] },
"vcsProviders": { "description": "Required exactly when vcsProviders is non-empty. The provider protocol itself is negotiated in initialize (https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/rust/contracts/vcs-provider-v1.md).", "enum": [0] }
}
},
Expand Down
5 changes: 3 additions & 2 deletions shared/plugins/contract/v1/plugin-ui.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,15 @@
}
},
"toolRow": {
"description": "settings only: the host's row for a tool this plugin defines (toolDefinitions) or requires (requiresTools): its resolved version and path, as the toolchain pages draw it.",
"description": "settings only: the host's row for a tool this plugin defines (toolDefinitions) or requires (requiresTools): its resolved version and path, as the toolchain pages draw it. With choose (requires.ui 1) the row is also the tool's picker.",
"type": "object",
"additionalProperties": false,
"required": ["type", "tool"],
"properties": {
"type": { "const": "tool" },
"id": { "$ref": "#/$defs/id" },
"tool": { "type": "string", "minLength": 1, "maxLength": 128 }
"tool": { "type": "string", "minLength": 1, "maxLength": 128 },
"choose": { "description": "requires.ui 1: the row opens the host's choices for the tool in the settings page's scope: the automatic choice, every installation the host found or the user added, and adding a directory. A choice edits the settings window's draft, which Apply commits and Cancel discards, as on the toolchain page.", "type": "boolean" }
}
},
"tree": {
Expand Down
2 changes: 2 additions & 0 deletions shared/plugins/reference/capabilities-and-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Core 列以本仓库 `main` 上的 Core 源码为准([`capabilities.rs`](https
| `sourceSettings` `0` | 真实配置来源表单、编译器页、私有暂存与显式保存 | ✅ | ✅ | [Source-backed settings editors](../contract/v1/README.md#source-backed-settings-editors) |
| `sourceSettings` `1` | 在 `0` 之上加:模块列表布局 `sidebar`(来源可用 `parent` 嵌套)、字段 `section`(标签页或小标题)、有序类型化条目列表 `entryList`(添加菜单、文件/目录选择器、可选项、按条目的属性列) | ✅ | ✅ | [Entry lists](../contract/v1/README.md#source-backed-settings-editors) |
| `ui` `0` | [`ui`](../contract/v1/README.md#host-owned-workbench-ui):文本、[包内网页](../contract/v1/README.md#web-content)和[插件视图](../contract/v1/README.md#plugin-views)的工具窗口、设置区域里的插件视图、命令,以及[不打开工具窗口的后端命令](../contract/v1/README.md#backend-only-commands);视图函数的结果由 Core 命令 `plugins.ui.applyResult` 校验,形状见 [`plugin-ui.schema.json`](../contract/v1/plugin-ui.schema.json) | ✅ | ✅¹ | [界面](domains/ui.md) |
| `ui` `1` | 在 `0` 之上加[工具选择器](../contract/v1/README.md#tool-rows-and-pickers):设置区域的 `tool` 行写 `choose: true` 时,按下打开宿主为该工具列出的选项(自动、已发现或已添加的安装、添加目录),选择写入设置窗口草稿,按“应用”生效 | ✅ | 配套宿主接入后声明 | [Tool rows and pickers](../contract/v1/README.md#tool-rows-and-pickers) |
| `buildSystems` `0` | 不带 `provider` 的 [`buildSystems[]`](../contract/v1/README.md#build-systems):检测、选项、项目模型、任务、运行入口、测试、诊断、依赖、同步和[声明式项目准备](../contract/v1/README.md#declarative-project-preparation) | ✅ | ✅¹ | [声明式构建系统](domains/build-systems.md) |
| `buildSystems` `1` | 新增 [命令式测试发现](../contract/v1/README.md#test-discovery),复用声明的构建工具和测试选择器 | ✅ | 待宿主声明 | [声明式构建系统](domains/build-systems.md) |
| `buildSystems` `2` | 构建提供者的应用运行声明可使用 `debug.configurationType`,包括按源文件发现的入口 | ✅ | 待宿主接入 | [构建提供者](domains/build-providers.md) |
Expand Down Expand Up @@ -167,6 +168,7 @@ Each row is one capability. `requires` lists **exactly** the capabilities a mani
| `sourceSettings` `0` | Native source forms, compiler pages, private staging and explicit Save | ✅ | ✅ | [Source-backed settings editors](../contract/v1/README.md#source-backed-settings-editors) |
| `sourceSettings` `1` | Adds to `0`: the `sidebar` module-list layout with sources nested by `parent`, field `section`s shown as tabs or subheadings, and ordered typed `entryList`s with an add menu, file and folder pickers, offered choices and per-entry attribute columns | ✅ | ✅ | [Entry lists](../contract/v1/README.md#source-backed-settings-editors) |
| `ui` `0` | [`ui`](../contract/v1/README.md#host-owned-workbench-ui): text, [web](../contract/v1/README.md#web-content), and [plugin view](../contract/v1/README.md#plugin-views) tool windows, plugin views in settings regions, commands, and [backend-only commands](../contract/v1/README.md#backend-only-commands) without a tool window; the Core command `plugins.ui.applyResult` checks view function results, shaped as in [`plugin-ui.schema.json`](../contract/v1/plugin-ui.schema.json) | ✅ | ✅¹ | [UI](domains/ui.md) |
| `ui` `1` | Extends `0` with the [tool picker](../contract/v1/README.md#tool-rows-and-pickers): a settings region's `tool` row with `choose: true` opens the host's choices for the tool (automatic, found or added installations, adding a directory); a choice edits the settings window's draft, which Apply commits | ✅ | Declared with companion host integration | [Tool rows and pickers](../contract/v1/README.md#tool-rows-and-pickers) |
| `buildSystems` `0` | [`buildSystems[]`](../contract/v1/README.md#build-systems) without `provider`: detection, options, project model, tasks, run entries, tests, diagnostics, dependencies, sync, and [declarative preparation](../contract/v1/README.md#declarative-project-preparation) | ✅ | ✅¹ | [Declarative build systems](domains/build-systems.md) |
| `buildSystems` `1` | Adds [command test discovery](../contract/v1/README.md#test-discovery) using the declared build tool and the existing test selectors | ✅ | Pending host declaration | [Declarative build systems](domains/build-systems.md) |
| `buildSystems` `2` | Allows build provider application runs to declare `debug.configurationType`, including source entrypoints | ✅ | Pending host integration | [Build providers](domains/build-providers.md) |
Expand Down
Loading
Loading