mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-08 08:52:12 +00:00
A plugin system built on WebAssembly components (wasmtime, WASI p2), with a typed WIT API (`openidea:[email protected]`) and a Rust SDK, shipped as a preview. - Extension points declared in `plugin.toml` (commands, languages, themes, icon themes, menus, key bindings, status items, settings, views, custom editors, file icons and templates, run detectors, editor providers), validated before anything takes effect and projected onto the workbench's own registries: plugin themes and file icon themes are chosen in Settings › Appearance and Quick Switch, plugin shortcuts are edited in Settings › Keymap, plugin problems are grouped in Settings › Inspections. - Capabilities with risk levels and consent at install, pinned `process:` programs, secrets in the OS keychain. - Runtime: one thread per active plugin, fuel/time/memory budgets, soft and hard deadlines on the editing path, cancellation, crash backoff, idle reclaim, a precompiled-component cache; remote projects run code plugins on `openidea-server`. - Web views and custom editors with a sandboxed page, a document bridge joined to the text editor's undo history, and split or preview layouts. - Distribution: signed `.oiplugin` packages, a static marketplace index with revocation, versioned installs with rollback, install from a `.zip` or a folder. The release workflow signs and publishes the official plugins and their index, which released builds use as the default marketplace. - Official plugins: String Tools, Key Promoter, Git Toolbox, AI Completion, Checkstyle, MyBatis Navigator, CSV Editor, Solidity, Material Icons, Harbor Night, Excalidraw, Graphviz, Regex Tester, License Header. Closes #732 Co-authored-by: Deng Liu <[email protected]> Co-authored-by: florentvdry <[email protected]>
94 lines
3.6 KiB
Rust
94 lines
3.6 KiB
Rust
//! Run configurations detected outside this crate: plugins' `runDetectors`.
|
|
//! Their ids start with [`EXTERNAL_PREFIX`]; before
|
|
//! one is started the provider names the program to run (the file approved
|
|
//! for the plugin's `process:` capability) or refuses.
|
|
|
|
use crate::RunConfig;
|
|
use parking_lot::RwLock;
|
|
use std::path::{Path, PathBuf};
|
|
use std::sync::Arc;
|
|
|
|
/// Id prefix of externally detected configurations (`plugin:<plugin>:<id>`).
|
|
pub const EXTERNAL_PREFIX: &str = "plugin:";
|
|
|
|
pub trait ExternalDetection: Send + Sync {
|
|
/// Configurations for the project at `root`; ids start with [`EXTERNAL_PREFIX`].
|
|
fn detect(&self, root: &Path) -> Vec<RunConfig>;
|
|
/// The program to start for `config` (one this provider detected), or why
|
|
/// it may not start.
|
|
fn launch(&self, config: &RunConfig) -> Result<PathBuf, String>;
|
|
}
|
|
|
|
static PROVIDER: RwLock<Option<Arc<dyn ExternalDetection>>> = RwLock::new(None);
|
|
|
|
/// Installs (or removes) the provider [`crate::detect`] and runs consult.
|
|
pub fn set_external_detection(provider: Option<Arc<dyn ExternalDetection>>) {
|
|
*PROVIDER.write() = provider;
|
|
}
|
|
|
|
pub(crate) fn detect(root: &Path, out: &mut Vec<RunConfig>) {
|
|
let provider = PROVIDER.read().clone();
|
|
if let Some(p) = provider {
|
|
out.extend(p.detect(root).into_iter().filter(|c| c.id.starts_with(EXTERNAL_PREFIX)));
|
|
}
|
|
}
|
|
|
|
/// `config` with the program its provider approved, for an externally
|
|
/// detected configuration; `None` for every other one.
|
|
pub(crate) fn approved(config: &RunConfig) -> Option<Result<RunConfig, String>> {
|
|
if !config.detected || !config.id.starts_with(EXTERNAL_PREFIX) {
|
|
return None;
|
|
}
|
|
let provider = PROVIDER.read().clone();
|
|
Some(match provider {
|
|
Some(p) => p
|
|
.launch(config)
|
|
.map(|program| RunConfig { command: program.to_string_lossy().into_owned(), ..config.clone() }),
|
|
None => Err("the plugin that detected this configuration is not loaded".into()),
|
|
})
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use crate::{ProcessManager, StartOptions};
|
|
|
|
/// Answers only for projects with its own marker (tests share the provider).
|
|
struct Fake;
|
|
|
|
const MARKER: &str = "fake-external-detection.marker";
|
|
|
|
impl ExternalDetection for Fake {
|
|
fn detect(&self, root: &Path) -> Vec<RunConfig> {
|
|
if !root.join(MARKER).exists() {
|
|
return Vec::new();
|
|
}
|
|
let mut c: RunConfig = serde_json::from_value(serde_json::json!({
|
|
"id": "plugin:acme:x", "name": "x", "kind": "plugin", "command": "x", "args": ["a"],
|
|
"cwd": null, "env": {}, "detected": true, "isTest": false, "debugAdapter": null
|
|
}))
|
|
.unwrap();
|
|
c.detected = true;
|
|
let other = RunConfig { id: "not-prefixed".into(), ..c.clone() };
|
|
vec![c, other]
|
|
}
|
|
fn launch(&self, _: &RunConfig) -> Result<PathBuf, String> {
|
|
Err("not allowed".into())
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn external_configs_join_detection_and_launch_only_when_approved() {
|
|
set_external_detection(Some(Arc::new(Fake)));
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
std::fs::write(tmp.path().join(MARKER), "").unwrap();
|
|
let configs = crate::detect(tmp.path());
|
|
assert_eq!(configs.iter().map(|c| c.id.as_str()).collect::<Vec<_>>(), ["plugin:acme:x"]);
|
|
let err = ProcessManager::new()
|
|
.start(tmp.path(), &configs[0], &StartOptions::default(), Arc::new(ide_core::NullSink), Box::new(|_| {}))
|
|
.unwrap_err();
|
|
assert_eq!(err.kind, ide_core::error::ErrorKind::PermissionDenied);
|
|
assert!(err.message.contains("not allowed"));
|
|
}
|
|
}
|