diff --git a/Cargo.lock b/Cargo.lock index fc57a4fee..655a51685 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1557,6 +1557,7 @@ dependencies = [ "serde", "serde_json", "slotmap", + "steel-core", "tokio", "tokio-stream", "toml", diff --git a/helix-term/src/commands/engine.rs b/helix-term/src/commands/engine.rs index 324c7d8af..ce559d3fa 100644 --- a/helix-term/src/commands/engine.rs +++ b/helix-term/src/commands/engine.rs @@ -91,12 +91,27 @@ impl Custom for PromptEvent {} impl<'a> CustomReference for Context<'a> {} +fn get_editor<'a>(cx: &'a mut Context<'a>) -> &'a mut Editor { + cx.editor +} + fn configure_engine() -> std::rc::Rc> { let mut engine = steel::steel_vm::engine::Engine::new(); let mut module = BuiltInModule::new("helix/core/keybindings".to_string()); module.register_fn("set-keybindings!", SharedKeyBindingsEventQueue::merge); + RegisterFn::< + _, + steel::steel_vm::register_fn::MarkerWrapper7<( + Context<'_>, + helix_view::Editor, + helix_view::Editor, + Context<'static>, + )>, + helix_view::Editor, + >::register_fn(&mut engine, "cx-editor!", get_editor); + engine.register_module(module); let mut module = BuiltInModule::new("helix/core/typable".to_string()); @@ -163,6 +178,10 @@ fn configure_engine() -> std::rc::Rc std::rc::Rc>(); - *EXPORTED_IDENTIFIERS.identifiers.write().unwrap() = exported; - - let docs = m + let docs = exported .iter() - .filter_map(|(k, v)| { - if let steel::rvals::SteelVal::SymbolV(s) = k { - if s.ends_with("__doc__") { - if let steel::rvals::SteelVal::StringV(d) = v { - return Some(( - s.strip_suffix("__doc__").unwrap().to_string(), - d.to_string(), - )); - } - } + .filter_map(|x| { + if let Ok(steel::rvals::SteelVal::StringV(d)) = + engine.extract_value(&(module_prefix.to_string() + x.as_str() + "__doc__")) + { + Some((x.to_string(), d.to_string())) + } else { + None } - - None }) .collect::>(); + *EXPORTED_IDENTIFIERS.identifiers.write().unwrap() = exported; *EXPORTED_IDENTIFIERS.docs.write().unwrap() = docs; } else { panic!("Unable to parse exported identifiers from helix module!") diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index 049705956..28d419bdf 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -45,6 +45,9 @@ log = "~0.4" which = "4.4" parking_lot = "0.12.1" +# plugin support +steel-core = { path = "../../../steel/crates/steel-core", version = "0.2.0", features = ["modules", "anyhow"] } + [target.'cfg(windows)'.dependencies] clipboard-win = { version = "4.5", features = ["std"] } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 005c66674..7cb36a883 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -799,6 +799,8 @@ pub struct Breakpoint { use futures_util::stream::{Flatten, Once}; +impl steel::gc::unsafe_erased_pointers::CustomReference for Editor {} + pub struct Editor { /// Current editing mode. pub mode: Mode,