addressing more comments

pull/8675/merge^2
mattwparas 9 months ago
parent eb20adbaad
commit cf967ed71e

@ -208,7 +208,7 @@ impl MappableCommand {
cx.editor.set_error(format!("{}", e)); cx.editor.set_error(format!("{}", e));
} }
} else { } else {
ScriptingEngine::call_function_if_global_exists(cx, name, args); ScriptingEngine::call_function_by_name(cx, name, args);
} }
} }
Self::Static { fun, .. } => (fun)(cx), Self::Static { fun, .. } => (fun)(cx),

@ -16,7 +16,7 @@ use super::{Context, MappableCommand, TYPABLE_COMMAND_LIST};
mod components; mod components;
#[cfg(feature = "steel")] #[cfg(feature = "steel")]
pub mod scheme; pub mod steel;
pub enum PluginSystemKind { pub enum PluginSystemKind {
None, None,
@ -27,14 +27,14 @@ pub enum PluginSystemKind {
pub enum PluginSystemTypes { pub enum PluginSystemTypes {
None(NoEngine), None(NoEngine),
#[cfg(feature = "steel")] #[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`, // 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? // we would have to order the precedence for searching for exported commands, or somehow merge them?
const PLUGIN_PRECEDENCE: &[PluginSystemTypes] = &[ const PLUGIN_PRECEDENCE: &[PluginSystemTypes] = &[
#[cfg(feature = "steel")] #[cfg(feature = "steel")]
PluginSystemTypes::Steel(scheme::SteelScriptingEngine), PluginSystemTypes::Steel(steel::SteelScriptingEngine),
PluginSystemTypes::None(NoEngine), PluginSystemTypes::None(NoEngine),
]; ];
@ -87,13 +87,9 @@ impl ScriptingEngine {
None None
} }
pub fn call_function_if_global_exists( pub fn call_function_by_name(cx: &mut Context, name: &str, args: Vec<Cow<str>>) -> bool {
cx: &mut Context,
name: &str,
args: Vec<Cow<str>>,
) -> bool {
for kind in PLUGIN_PRECEDENCE { 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; return true;
} }
} }
@ -101,17 +97,14 @@ impl ScriptingEngine {
false false
} }
pub fn call_typed_command_if_global_exists<'a>( pub fn call_typed_command<'a>(
cx: &mut compositor::Context, cx: &mut compositor::Context,
input: &'a str, input: &'a str,
parts: &'a [&'a str], parts: &'a [&'a str],
event: PromptEvent, event: PromptEvent,
) -> bool { ) -> bool {
for kind in PLUGIN_PRECEDENCE { for kind in PLUGIN_PRECEDENCE {
if manual_dispatch!( if manual_dispatch!(kind, call_typed_command(cx, input, parts, event)) {
kind,
call_typed_command_if_global_exists(cx, input, parts, event)
) {
return true; 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 /// 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. /// is available here. Returns a bool indicating whether the function exists or not.
#[inline(always)] #[inline(always)]
fn call_function_if_global_exists( fn call_function_by_name(&self, _cx: &mut Context, _name: &str, _args: &[Cow<str>]) -> bool {
&self,
_cx: &mut Context,
_name: &str,
_args: &[Cow<str>],
) -> bool {
false 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 /// 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`. /// gives the ability to handle in progress commands with `PromptEvent`.
#[inline(always)] #[inline(always)]
fn call_typed_command_if_global_exists<'a>( fn call_typed_command<'a>(
&self, &self,
_cx: &mut compositor::Context, _cx: &mut compositor::Context,
_input: &'a str, _input: &'a str,

@ -8,7 +8,7 @@ use steel::{
}; };
use crate::{ use crate::{
commands::{engine::scheme::ENGINE, Context}, commands::{engine::steel::ENGINE, Context},
compositor::{self, Component}, compositor::{self, Component},
ui::{Popup, Prompt, PromptEvent}, ui::{Popup, Prompt, PromptEvent},
}; };

@ -329,7 +329,10 @@ fn load_typed_commands(engine: &mut Engine, generate_sources: bool) {
(helix.{} *helix.cx* args)) (helix.{} *helix.cx* args))
"#, "#,
command.name, command.name,
command {
// Ugly hack to drop the extra newline from
// the docstring
let mut docstring = command
.doc .doc
.lines() .lines()
.map(|x| { .map(|x| {
@ -338,7 +341,12 @@ fn load_typed_commands(engine: &mut Engine, generate_sources: bool) {
line.push_str("\n"); line.push_str("\n");
line line
}) })
.collect::<String>(), .collect::<String>();
docstring.pop();
docstring
},
command.name, command.name,
command.name command.name
)); ));
@ -359,6 +367,7 @@ fn load_typed_commands(engine: &mut Engine, generate_sources: bool) {
engine.register_module(module); engine.register_module(module);
} }
// File picker configurations
fn fp_hidden(config: &mut FilePickerConfig, option: bool) { fn fp_hidden(config: &mut FilePickerConfig, option: bool) {
config.hidden = option; config.hidden = option;
} }
@ -395,6 +404,7 @@ fn fp_max_depth(config: &mut FilePickerConfig, option: Option<usize>) {
config.max_depth = option; config.max_depth = option;
} }
// Soft wrap configurations
fn sw_enable(config: &mut SoftWrap, option: Option<bool>) { fn sw_enable(config: &mut SoftWrap, option: Option<bool>) {
config.enable = option; config.enable = option;
} }
@ -646,7 +656,6 @@ fn load_configuration_api(engine: &mut Engine, generate_sources: bool) {
"insert-final-newline", "insert-final-newline",
"color-modes", "color-modes",
"gutters", "gutters",
// "file-picker",
"statusline", "statusline",
"undercurl", "undercurl",
"search", "search",
@ -656,7 +665,6 @@ fn load_configuration_api(engine: &mut Engine, generate_sources: bool) {
"whitespace", "whitespace",
"bufferline", "bufferline",
"indent-guides", "indent-guides",
// "soft-wrap",
"workspace-lsp-roots", "workspace-lsp-roots",
"default-line-ending", "default-line-ending",
"smart-tab", "smart-tab",
@ -809,12 +817,7 @@ impl super::PluginSystem for SteelScriptingEngine {
}) })
} }
fn call_function_if_global_exists( fn call_function_by_name(&self, cx: &mut Context, name: &str, args: &[Cow<str>]) -> bool {
&self,
cx: &mut Context,
name: &str,
args: &[Cow<str>],
) -> bool {
if ENGINE.with(|x| x.borrow().global_exists(name)) { if ENGINE.with(|x| x.borrow().global_exists(name)) {
let args = args let args = args
.iter() .iter()
@ -844,7 +847,7 @@ impl super::PluginSystem for SteelScriptingEngine {
} }
} }
fn call_typed_command_if_global_exists<'a>( fn call_typed_command<'a>(
&self, &self,
cx: &mut compositor::Context, cx: &mut compositor::Context,
input: &'a str, input: &'a str,
@ -1525,7 +1528,6 @@ fn get_themes(cx: &mut Context) -> Vec<String> {
} }
/// A dynamic component, used for rendering thing /// A dynamic component, used for rendering thing
impl Custom for compositor::EventResult {} impl Custom for compositor::EventResult {}
impl FromSteelVal for compositor::EventResult { impl FromSteelVal for compositor::EventResult {
fn from_steelval(val: &SteelVal) -> steel::rvals::Result<Self> { fn from_steelval(val: &SteelVal) -> steel::rvals::Result<Self> {

@ -3167,8 +3167,7 @@ pub(super) fn command_mode(cx: &mut Context) {
if let Err(e) = (cmd.fun)(cx, &args[1..], event) { if let Err(e) = (cmd.fun)(cx, &args[1..], event) {
cx.editor.set_error(format!("{}", e)); 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 // Engine handles the other cases
} else if event == PromptEvent::Validate { } else if event == PromptEvent::Validate {
cx.editor cx.editor

Loading…
Cancel
Save