mirror of https://github.com/helix-editor/helix
addressing more comments
parent
eb20adbaad
commit
cf967ed71e
|
@ -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),
|
||||
|
|
|
@ -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<Cow<str>>,
|
||||
) -> bool {
|
||||
pub fn call_function_by_name(cx: &mut Context, name: &str, args: Vec<Cow<str>>) -> 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<str>],
|
||||
) -> bool {
|
||||
fn call_function_by_name(&self, _cx: &mut Context, _name: &str, _args: &[Cow<str>]) -> 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,
|
||||
|
|
|
@ -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},
|
||||
};
|
||||
|
|
|
@ -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::<String>(),
|
||||
{
|
||||
// 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::<String>();
|
||||
|
||||
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<usize>) {
|
|||
config.max_depth = option;
|
||||
}
|
||||
|
||||
// Soft wrap configurations
|
||||
fn sw_enable(config: &mut SoftWrap, option: Option<bool>) {
|
||||
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<str>],
|
||||
) -> bool {
|
||||
fn call_function_by_name(&self, cx: &mut Context, name: &str, args: &[Cow<str>]) -> 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<String> {
|
|||
}
|
||||
|
||||
/// 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<Self> {
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue