mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
Plugins can now bundle `SKILL.md` folders with a manifest-only `[[contributes.skills]]` extension point (API 1.15, no WIT change). They appear under Plugins in Settings › Agents › Skills and the Composer Skills picker while the plugin is enabled, and are staged into each CLI's per-session skill folder from the plugin's package directory; disabling or uninstalling the plugin removes them right away. Load-time validation keeps `path` inside the package (no `..` or escaping symlinks), requires `<dir>/SKILL.md` with the usual folder-name and frontmatter rules, and caps a skill folder at 2 MiB / 256 files; an invalid entry becomes a plugin load warning without failing the rest of the plugin. Every file of a valid skill folder is part of the package files, so versioned installs and remote sync copy supporting scripts and references. Workspace and user skills win on a name clash. Includes a declarative fixture plugin and docs. Closes #5114 Co-authored-by: dengliu <5108773+dengliu@users.noreply.github.com>
106 lines
5.8 KiB
Rust
106 lines
5.8 KiB
Rust
//! First-party extension points registered by the host, plus
|
||
//! [`register_builtin_points`], the one place that lists them. Feature crates
|
||
//! own their points (`ide_language::plugin_point`); adding a contribution type
|
||
//! means adding a point here or in its crate, and a `defineUiPoint` projection
|
||
//! on the client for `Ui` points — nothing else.
|
||
|
||
use ide_extension::{ExtensionRegistry, Package, UiDecl, UiPoint, UiStore, decode, validate_item_id, validate_when};
|
||
use ide_language::plugin_point::{LanguagesPoint, PluginLanguages};
|
||
use serde::{Deserialize, Serialize};
|
||
use std::sync::Arc;
|
||
|
||
pub const COMMANDS: &str = "commands";
|
||
const MAX_TITLE: usize = 256;
|
||
|
||
/// `[[contributes.commands]]`: an action `plugin.<plugin-id>.<id>` in Search
|
||
/// Everywhere and the keymap editor; shown before the plugin's code runs.
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, specta::Type)]
|
||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||
pub struct CommandDecl {
|
||
pub id: String,
|
||
pub title: String,
|
||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||
pub icon: Option<String>,
|
||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||
pub category: Option<String>,
|
||
/// Enablement, evaluated by the client against context keys (`editorLang == rust`).
|
||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||
pub when: Option<String>,
|
||
}
|
||
|
||
fn command(pkg: &Package, decl: toml::Value) -> Result<UiDecl, String> {
|
||
let c: CommandDecl = decode(COMMANDS, decl)?;
|
||
validate_item_id(&c.id, "command id")?;
|
||
if let Some(icon) = &c.icon {
|
||
pkg.manifest.needs_api("contributes.commands.icon", 4)?;
|
||
if icon.is_empty() || icon.len() > 256 {
|
||
return Err("command icon: expected 1–256 bytes".into());
|
||
}
|
||
}
|
||
if c.title.trim().is_empty() {
|
||
return Err(format!("command {:?} has an empty title", c.id));
|
||
}
|
||
if c.title.len() > MAX_TITLE || c.category.as_ref().is_some_and(|x| x.len() > MAX_TITLE) {
|
||
return Err(format!("command {:?}: title or category longer than {MAX_TITLE} bytes", c.id));
|
||
}
|
||
if let Some(when) = &c.when {
|
||
validate_when(when).map_err(|e| format!("command {:?}: {e}", c.id))?;
|
||
}
|
||
let c = CommandDecl { category: c.category.filter(|x| !x.trim().is_empty()), ..c };
|
||
let json = serde_json::to_value(&c).map_err(|e| e.to_string())?;
|
||
let mut out = UiDecl::new(c.id.clone(), c.title, json);
|
||
if let Some(icon) = c.icon.filter(|s| s.ends_with(".svg")) {
|
||
let path = std::path::PathBuf::from(icon);
|
||
let svg = super::icons::read_icon(pkg, &path, super::icons::MAX_SVG)?;
|
||
out.files.push(path);
|
||
out.assets.push((format!("commandIcon/{}", c.id), svg));
|
||
}
|
||
Ok(out)
|
||
}
|
||
|
||
/// Registers every first-party extension point.
|
||
pub fn register_builtin_points(
|
||
registry: &ExtensionRegistry,
|
||
ui: &Arc<UiStore>,
|
||
languages: &Arc<PluginLanguages>,
|
||
run_detectors: &Arc<super::run_detectors::RunDetectors>,
|
||
java_agents: &Arc<super::java_agents::JavaAgents>,
|
||
providers: &Arc<super::providers::Providers>,
|
||
skills: &Arc<super::skills::PluginSkills>,
|
||
) -> Result<(), String> {
|
||
registry.register(Arc::new(UiPoint::new(COMMANDS, ui.clone(), command)))?;
|
||
registry.register(Arc::new(super::theme::ThemesPoint::new(ui.clone())))?;
|
||
registry.register(Arc::new(LanguagesPoint::new(languages.clone())))?;
|
||
registry.register(Arc::new(UiPoint::new(super::icons::POINT_ID, ui.clone(), super::icons::icon_theme)))?;
|
||
registry.register(Arc::new(super::run_detectors::RunDetectorsPoint::new(run_detectors.clone())))?;
|
||
registry.register(Arc::new(super::java_agents::JavaAgentsPoint::new(java_agents.clone())))?;
|
||
registry.register(Arc::new(super::skills::SkillsPoint::new(skills.clone())))?;
|
||
registry.register(Arc::new(super::navigation::IndexersPoint))?;
|
||
registry.register(Arc::new(super::providers::ProvidersPoint::new(providers.clone())))?;
|
||
registry.register(Arc::new(UiPoint::new(super::providers::SECRETS_POINT, ui.clone(), super::providers::secret)))?;
|
||
registry.register(Arc::new(UiPoint::new(super::search::POINT, ui.clone(), super::search::declaration)))?;
|
||
registry.register(Arc::new(UiPoint::new(super::endpoints::POINT, ui.clone(), super::endpoints::declaration)))?;
|
||
registry.register(Arc::new(UiPoint::new(
|
||
"runConfigurations",
|
||
ui.clone(),
|
||
super::execution::configurations_declaration,
|
||
)))?;
|
||
registry.register(Arc::new(UiPoint::new("snippets", ui.clone(), super::snippets::declaration)))?;
|
||
registry.register(Arc::new(UiPoint::new(super::mcp::POINT, ui.clone(), super::mcp::declaration)))?;
|
||
use super::ui_points as p;
|
||
registry.register(Arc::new(UiPoint::new(p::MENUS, ui.clone(), p::menu)))?;
|
||
registry.register(Arc::new(UiPoint::new(p::KEYMAPS, ui.clone(), p::keymap)))?;
|
||
registry.register(Arc::new(UiPoint::new(p::STATUS_BAR, ui.clone(), p::status_item)))?;
|
||
registry.register(Arc::new(UiPoint::new(p::SETTINGS, ui.clone(), p::settings)))?;
|
||
registry.register(Arc::new(UiPoint::new(p::VIEWS, ui.clone(), p::view)))?;
|
||
registry.register(Arc::new(UiPoint::new(p::CUSTOM_EDITORS, ui.clone(), p::custom_editor)))?;
|
||
registry.register(Arc::new(UiPoint::new(p::EDITOR_PANELS, ui.clone(), p::editor_panel)))?;
|
||
registry.register(Arc::new(UiPoint::new(p::MARKER_ICONS, ui.clone(), p::marker_icon)))?;
|
||
registry.register(Arc::new(UiPoint::new(p::FILE_ICONS, ui.clone(), p::file_icon)))?;
|
||
registry.register(Arc::new(UiPoint::new(p::FILE_TEMPLATES, ui.clone(), p::file_template)))?;
|
||
registry.register(Arc::new(UiPoint::new(p::COMMIT_CHECKS, ui.clone(), p::commit_check)))?;
|
||
registry.register(Arc::new(UiPoint::new(p::SERVER_COMMANDS, ui.clone(), p::server_command)))?;
|
||
registry.register(Arc::new(UiPoint::new(ide_extension::LOCALES_POINT, ui.clone(), p::locales)))?;
|
||
Ok(())
|
||
}
|