From cf967ed71efa5c9bff7a04e17cc2516fe54044ff Mon Sep 17 00:00:00 2001 From: mattwparas Date: Wed, 14 Feb 2024 16:59:35 -0800 Subject: [PATCH] addressing more comments --- helix-term/src/commands.rs | 2 +- helix-term/src/commands/engine.rs | 30 ++++--------- helix-term/src/commands/engine/components.rs | 2 +- .../commands/engine/{scheme.rs => steel.rs} | 42 ++++++++++--------- helix-term/src/commands/typed.rs | 3 +- 5 files changed, 34 insertions(+), 45 deletions(-) rename helix-term/src/commands/engine/{scheme.rs => steel.rs} (99%) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index b0b354e17..6254b8228 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -208,7 +208,7 @@ impl MappableCommand { cx.editor.set_error(format!("{}", e)); } } else { - ScriptingEngine::call_function_if_global_exists(cx, name, args); + ScriptingEngine::call_function_by_name(cx, name, args); } } Self::Static { fun, .. } => (fun)(cx), diff --git a/helix-term/src/commands/engine.rs b/helix-term/src/commands/engine.rs index a910b46a8..5c7528458 100644 --- a/helix-term/src/commands/engine.rs +++ b/helix-term/src/commands/engine.rs @@ -16,7 +16,7 @@ use super::{Context, MappableCommand, TYPABLE_COMMAND_LIST}; mod components; #[cfg(feature = "steel")] -pub mod scheme; +pub mod steel; pub enum PluginSystemKind { None, @@ -27,14 +27,14 @@ pub enum PluginSystemKind { pub enum PluginSystemTypes { None(NoEngine), #[cfg(feature = "steel")] - Steel(scheme::SteelScriptingEngine), + Steel(steel::SteelScriptingEngine), } // The order in which the plugins will be evaluated against - if we wanted to include, lets say `rhai`, // we would have to order the precedence for searching for exported commands, or somehow merge them? const PLUGIN_PRECEDENCE: &[PluginSystemTypes] = &[ #[cfg(feature = "steel")] - PluginSystemTypes::Steel(scheme::SteelScriptingEngine), + PluginSystemTypes::Steel(steel::SteelScriptingEngine), PluginSystemTypes::None(NoEngine), ]; @@ -87,13 +87,9 @@ impl ScriptingEngine { None } - pub fn call_function_if_global_exists( - cx: &mut Context, - name: &str, - args: Vec>, - ) -> bool { + pub fn call_function_by_name(cx: &mut Context, name: &str, args: Vec>) -> bool { for kind in PLUGIN_PRECEDENCE { - if manual_dispatch!(kind, call_function_if_global_exists(cx, name, &args)) { + if manual_dispatch!(kind, call_function_by_name(cx, name, &args)) { return true; } } @@ -101,17 +97,14 @@ impl ScriptingEngine { false } - pub fn call_typed_command_if_global_exists<'a>( + pub fn call_typed_command<'a>( cx: &mut compositor::Context, input: &'a str, parts: &'a [&'a str], event: PromptEvent, ) -> bool { for kind in PLUGIN_PRECEDENCE { - if manual_dispatch!( - kind, - call_typed_command_if_global_exists(cx, input, parts, event) - ) { + if manual_dispatch!(kind, call_typed_command(cx, input, parts, event)) { return true; } } @@ -186,12 +179,7 @@ pub trait PluginSystem { /// This attempts to call a function in the engine with the name `name` using the args `args`. The context /// is available here. Returns a bool indicating whether the function exists or not. #[inline(always)] - fn call_function_if_global_exists( - &self, - _cx: &mut Context, - _name: &str, - _args: &[Cow], - ) -> bool { + fn call_function_by_name(&self, _cx: &mut Context, _name: &str, _args: &[Cow]) -> bool { false } @@ -199,7 +187,7 @@ pub trait PluginSystem { /// that is available is more limited than the context available in `call_function_if_global_exists`. This also /// gives the ability to handle in progress commands with `PromptEvent`. #[inline(always)] - fn call_typed_command_if_global_exists<'a>( + fn call_typed_command<'a>( &self, _cx: &mut compositor::Context, _input: &'a str, diff --git a/helix-term/src/commands/engine/components.rs b/helix-term/src/commands/engine/components.rs index 48a69a6f4..0e668c66e 100644 --- a/helix-term/src/commands/engine/components.rs +++ b/helix-term/src/commands/engine/components.rs @@ -8,7 +8,7 @@ use steel::{ }; use crate::{ - commands::{engine::scheme::ENGINE, Context}, + commands::{engine::steel::ENGINE, Context}, compositor::{self, Component}, ui::{Popup, Prompt, PromptEvent}, }; diff --git a/helix-term/src/commands/engine/scheme.rs b/helix-term/src/commands/engine/steel.rs similarity index 99% rename from helix-term/src/commands/engine/scheme.rs rename to helix-term/src/commands/engine/steel.rs index e8aa26fa0..ed5caf8c4 100644 --- a/helix-term/src/commands/engine/scheme.rs +++ b/helix-term/src/commands/engine/steel.rs @@ -329,16 +329,24 @@ fn load_typed_commands(engine: &mut Engine, generate_sources: bool) { (helix.{} *helix.cx* args)) "#, command.name, - command - .doc - .lines() - .map(|x| { - let mut line = ";;".to_string(); - line.push_str(x); - line.push_str("\n"); - line - }) - .collect::(), + { + // Ugly hack to drop the extra newline from + // the docstring + let mut docstring = command + .doc + .lines() + .map(|x| { + let mut line = ";;".to_string(); + line.push_str(x); + line.push_str("\n"); + line + }) + .collect::(); + + docstring.pop(); + + docstring + }, command.name, command.name )); @@ -359,6 +367,7 @@ fn load_typed_commands(engine: &mut Engine, generate_sources: bool) { engine.register_module(module); } +// File picker configurations fn fp_hidden(config: &mut FilePickerConfig, option: bool) { config.hidden = option; } @@ -395,6 +404,7 @@ fn fp_max_depth(config: &mut FilePickerConfig, option: Option) { config.max_depth = option; } +// Soft wrap configurations fn sw_enable(config: &mut SoftWrap, option: Option) { config.enable = option; } @@ -646,7 +656,6 @@ fn load_configuration_api(engine: &mut Engine, generate_sources: bool) { "insert-final-newline", "color-modes", "gutters", - // "file-picker", "statusline", "undercurl", "search", @@ -656,7 +665,6 @@ fn load_configuration_api(engine: &mut Engine, generate_sources: bool) { "whitespace", "bufferline", "indent-guides", - // "soft-wrap", "workspace-lsp-roots", "default-line-ending", "smart-tab", @@ -809,12 +817,7 @@ impl super::PluginSystem for SteelScriptingEngine { }) } - fn call_function_if_global_exists( - &self, - cx: &mut Context, - name: &str, - args: &[Cow], - ) -> bool { + fn call_function_by_name(&self, cx: &mut Context, name: &str, args: &[Cow]) -> bool { if ENGINE.with(|x| x.borrow().global_exists(name)) { let args = args .iter() @@ -844,7 +847,7 @@ impl super::PluginSystem for SteelScriptingEngine { } } - fn call_typed_command_if_global_exists<'a>( + fn call_typed_command<'a>( &self, cx: &mut compositor::Context, input: &'a str, @@ -1525,7 +1528,6 @@ fn get_themes(cx: &mut Context) -> Vec { } /// A dynamic component, used for rendering thing - impl Custom for compositor::EventResult {} impl FromSteelVal for compositor::EventResult { fn from_steelval(val: &SteelVal) -> steel::rvals::Result { diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 803d42685..413f9dc8c 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -3167,8 +3167,7 @@ pub(super) fn command_mode(cx: &mut Context) { if let Err(e) = (cmd.fun)(cx, &args[1..], event) { cx.editor.set_error(format!("{}", e)); } - } else if ScriptingEngine::call_typed_command_if_global_exists(cx, input, &parts, event) - { + } else if ScriptingEngine::call_typed_command(cx, input, &parts, event) { // Engine handles the other cases } else if event == PromptEvent::Validate { cx.editor