From f6590e6a78b52eb9922b78d404fdc62ff62010d5 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Tue, 1 Dec 2026 03:25:56 +0800 Subject: [PATCH] fix(plugins): let capabilities.reasons explain capabilities a contribution brings A plugin with [[contributes.javaAgents]] gets java.agent without listing it under [capabilities] (listing it is an error), so the manifest check rejected a reason for it and the install dialog and Permissions showed only the IDE's description. Reasons may now also name the capabilities contributions bring: java.agent from javaAgents and project.read from documentIndexers. Fixes #7088 --- crates/ide-extension/src/manifest.rs | 29 ++++++++++++++++++++++++++-- docs/en/plugins/capabilities.mdx | 2 +- docs/zh/plugins/capabilities.mdx | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/crates/ide-extension/src/manifest.rs b/crates/ide-extension/src/manifest.rs index f70dcc1b8..6f84a6557 100644 --- a/crates/ide-extension/src/manifest.rs +++ b/crates/ide-extension/src/manifest.rs @@ -391,9 +391,12 @@ impl Manifest { if !self.capabilities.reasons.is_empty() { self.needs_api("`capabilities.reasons`", 19)?; } + let derived = self.derived_capabilities(); for (key, text) in &self.capabilities.reasons { - if !self.capabilities.all().any(|c| c.to_string() == *key) { - return Err(format!("capabilities.reasons: {key:?} is not under `required` or `optional`")); + if !self.capabilities.all().chain(&derived).any(|c| c.to_string() == *key) { + return Err(format!( + "capabilities.reasons: {key:?} is not under `required` or `optional`, nor comes from a contribution" + )); } if text.trim().is_empty() || text.chars().count() > MAX_CAPABILITY_REASON { return Err(format!( @@ -522,6 +525,17 @@ impl Manifest { Ok(()) } + /// Capabilities the plugin's contributions bring without being listed under `[capabilities]`: + /// `java.agent` from `[[contributes.javaAgents]]`, `project.read` from + /// `[[contributes.documentIndexers]]` (the extension points in `ide-host` add them to the grant). + pub fn derived_capabilities(&self) -> Vec { + [("javaAgents", Capability::JavaAgent), ("documentIndexers", Capability::ProjectRead)] + .into_iter() + .filter(|(point, _)| self.contributes.contains_key(*point)) + .map(|(_, cap)| cap) + .collect() + } + /// The declarations of one extension point: `[[contributes.x]]` gives /// several, `[contributes.x]` one. pub fn declarations(&self, point: &str) -> Vec { @@ -843,6 +857,17 @@ required = [\"lsp:phoxite\"] assert!(err(&src(&long)).contains("1 to 500 characters")); } + #[test] + fn capability_reasons_explain_capabilities_that_contributions_bring() { + let src = |rest: &str| format!("{}{rest}", BASE.replace("^1.2", "^1.19")); + let reason = "[capabilities.reasons]\n\"java.agent\" = \"Captures the SQL MyBatis runs.\"\n"; + let agent = "[[contributes.javaAgents]]\npath = \"agent.jar\"\n"; + let m = Manifest::parse(&src(&format!("{reason}{agent}"))).unwrap(); + assert_eq!(m.derived_capabilities(), [Capability::JavaAgent]); + assert_eq!(m.capabilities.reason(&Capability::JavaAgent), Some("Captures the SQL MyBatis runs.")); + assert!(err(&src(reason)).contains("nor comes from a contribution"), "no javaAgents declaration"); + } + #[test] fn the_clipboard_read_capability_needs_api_1_11() { let caps = "[capabilities]\noptional = [\"clipboard.read\"]\n"; diff --git a/docs/en/plugins/capabilities.mdx b/docs/en/plugins/capabilities.mdx index 9da68cdcf..92f9f3249 100644 --- a/docs/en/plugins/capabilities.mdx +++ b/docs/en/plugins/capabilities.mdx @@ -35,7 +35,7 @@ optional = ["net:127.0.0.1", "clipboard.read"] "clipboard.read" = "Imports a log you copied, on the Log to SQL tab only." ``` -The dialog and the plugin's details in **Settings › Plugins** show it below the IDE's description, marked as the plugin's own words; it never replaces that description. Keys must be capabilities listed under `required` or `optional`, and each reason is 1 to 500 characters. Translate it like the plugin's other strings, with the English text as the key in `locales/.json`. +The dialog and the plugin's details in **Settings › Plugins** show it below the IDE's description, marked as the plugin's own words; it never replaces that description. Keys must be capabilities listed under `required` or `optional`, or ones a contribution brings (`java.agent` from `[[contributes.javaAgents]]`, `project.read` from `[[contributes.documentIndexers]]`), and each reason is 1 to 500 characters. Translate it like the plugin's other strings, with the English text as the key in `locales/.json`. When code finds an optional capability refused, `host::open_permissions()` opens **Settings › Plugins** at the plugin's permissions, so a notice can offer a button that goes straight there (from a command or event only). diff --git a/docs/zh/plugins/capabilities.mdx b/docs/zh/plugins/capabilities.mdx index 35ede6de4..33bdf3bce 100644 --- a/docs/zh/plugins/capabilities.mdx +++ b/docs/zh/plugins/capabilities.mdx @@ -35,7 +35,7 @@ optional = ["net:127.0.0.1", "clipboard.read"] "clipboard.read" = "Imports a log you copied, on the Log to SQL tab only." ``` -授权对话框和 **设置 › 插件** 的插件详情会把这句话显示在 IDE 说明的下方,并标明是插件自己的说法;它不会替换 IDE 的说明。键必须是 `required` 或 `optional` 里列出的能力,每条 1 到 500 个字符。翻译方式与插件的其他字符串相同:在 `locales/.json` 里以英文原文为键。 +授权对话框和 **设置 › 插件** 的插件详情会把这句话显示在 IDE 说明的下方,并标明是插件自己的说法;它不会替换 IDE 的说明。键必须是 `required` 或 `optional` 里列出的能力,或者由贡献点带来的能力(`[[contributes.javaAgents]]` 带来的 `java.agent`、`[[contributes.documentIndexers]]` 带来的 `project.read`),每条 1 到 500 个字符。翻译方式与插件的其他字符串相同:在 `locales/.json` 里以英文原文为键。 代码发现某个 optional 能力被拒绝时,可以调用 `host::open_permissions()` 打开 **设置 › 插件** 并定位到本插件的权限,这样通知里可以放一个直接跳过去的按钮(仅限命令或事件中调用)。