mirror of https://github.com/helix-editor/helix
cleanup
parent
18fa67d157
commit
7d63468b83
|
@ -545,7 +545,7 @@ impl std::str::FromStr for MappableCommand {
|
|||
args: args.clone(),
|
||||
})
|
||||
.or_else(|| {
|
||||
if let Some(doc) = self::engine::ScriptingEngine::engine_get_doc(name) {
|
||||
if let Some(doc) = self::engine::ScriptingEngine::get_doc_for_identifier(name) {
|
||||
Some(MappableCommand::Typable {
|
||||
name: name.to_owned(),
|
||||
args,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use helix_view::{document::Mode, input::KeyEvent};
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::{borrow::Cow, collections::HashMap};
|
||||
|
||||
use crate::{
|
||||
compositor,
|
||||
keymap::KeymapResult,
|
||||
keymap::{KeyTrie, KeymapResult},
|
||||
ui::{self, PromptEvent},
|
||||
};
|
||||
|
||||
|
@ -13,9 +13,6 @@ use super::{shell_impl, Context, MappableCommand, TYPABLE_COMMAND_LIST};
|
|||
#[cfg(feature = "steel")]
|
||||
mod components;
|
||||
|
||||
// TODO: Change this visibility to pub(crate) probably, and adjust the status line message to not refer to the one
|
||||
// in the scheme module directly. Probably create some kind of object here to refer to instead
|
||||
|
||||
#[cfg(feature = "steel")]
|
||||
pub mod scheme;
|
||||
|
||||
|
@ -30,6 +27,7 @@ static PLUGIN_SYSTEM: PluginEngine<scheme::SteelScriptingEngine> =
|
|||
PluginEngine(scheme::SteelScriptingEngine);
|
||||
|
||||
#[cfg(not(feature = "steel"))]
|
||||
/// The default plugin system used ends up with no ops for all of the behavior.
|
||||
static PLUGIN_SYSTEM: PluginEngine<NoEngine> = PluginEngine(NoEngine);
|
||||
|
||||
// enum PluginSystemTypes {
|
||||
|
@ -55,6 +53,10 @@ impl ScriptingEngine {
|
|||
PLUGIN_SYSTEM.0.run_initialization_script(cx);
|
||||
}
|
||||
|
||||
pub fn get_keybindings() -> Option<HashMap<Mode, KeyTrie>> {
|
||||
PLUGIN_SYSTEM.0.get_keybindings()
|
||||
}
|
||||
|
||||
pub fn handle_keymap_event(
|
||||
editor: &mut ui::EditorView,
|
||||
mode: Mode,
|
||||
|
@ -101,10 +103,6 @@ impl ScriptingEngine {
|
|||
pub fn is_exported(ident: &str) -> bool {
|
||||
PLUGIN_SYSTEM.0.is_exported(ident)
|
||||
}
|
||||
|
||||
pub fn engine_get_doc(ident: &str) -> Option<String> {
|
||||
PLUGIN_SYSTEM.0.engine_get_doc(ident)
|
||||
}
|
||||
}
|
||||
|
||||
impl PluginSystem for NoEngine {}
|
||||
|
@ -112,10 +110,23 @@ impl PluginSystem for NoEngine {}
|
|||
/// These methods are the main entry point for interaction with the rest of
|
||||
/// the editor system.
|
||||
pub trait PluginSystem {
|
||||
/// If any initialization needs to happen prior to the initialization script being run,
|
||||
/// this is done here. This is run before the context is available.
|
||||
fn initialize(&self) {}
|
||||
|
||||
/// Post initialization, once the context is available. This means you should be able to
|
||||
/// run anything here that could modify the context before the main editor is available.
|
||||
fn run_initialization_script(&self, _cx: &mut Context) {}
|
||||
|
||||
/// Fetch the keybindings so that these can be loaded in to the keybinding map. These are
|
||||
/// keybindings that overwrite the default ones.
|
||||
fn get_keybindings(&self) -> Option<HashMap<Mode, KeyTrie>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Allow the engine to directly handle a keymap event. This is some of the tightest integration
|
||||
/// with the engine, directly intercepting any keymap events. By default, this just delegates to the
|
||||
/// editors default keybindings.
|
||||
fn handle_keymap_event(
|
||||
&self,
|
||||
editor: &mut ui::EditorView,
|
||||
|
@ -126,6 +137,8 @@ pub trait PluginSystem {
|
|||
editor.keymaps.get(mode, event)
|
||||
}
|
||||
|
||||
/// 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.
|
||||
fn call_function_if_global_exists(
|
||||
&self,
|
||||
_cx: &mut Context,
|
||||
|
@ -135,6 +148,9 @@ pub trait PluginSystem {
|
|||
false
|
||||
}
|
||||
|
||||
/// This is explicitly for calling a function via the typed command interface, e.g. `:vsplit`. The context here
|
||||
/// 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`.
|
||||
fn call_typed_command_if_global_exists<'a>(
|
||||
&self,
|
||||
_cx: &mut compositor::Context,
|
||||
|
@ -145,10 +161,12 @@ pub trait PluginSystem {
|
|||
false
|
||||
}
|
||||
|
||||
/// Given an identifier, extract the documentation from the engine.
|
||||
fn get_doc_for_identifier(&self, _ident: &str) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Fuzzy match the input against the fuzzy matcher, used for handling completions on typed commands
|
||||
fn fuzzy_match<'a>(
|
||||
&self,
|
||||
_fuzzy_matcher: &'a fuzzy_matcher::skim::SkimMatcherV2,
|
||||
|
@ -157,11 +175,8 @@ pub trait PluginSystem {
|
|||
Vec::new()
|
||||
}
|
||||
|
||||
/// Checks if this identifier is available in the global environment in the engine.
|
||||
fn is_exported(&self, _ident: &str) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn engine_get_doc(&self, _ident: &str) -> Option<String> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,6 +187,10 @@ impl super::PluginSystem for SteelScriptingEngine {
|
|||
run_initialization_script(cx);
|
||||
}
|
||||
|
||||
fn get_keybindings(&self) -> Option<HashMap<Mode, KeyTrie>> {
|
||||
crate::commands::engine::scheme::SharedKeyBindingsEventQueue::get()
|
||||
}
|
||||
|
||||
fn handle_keymap_event(
|
||||
&self,
|
||||
editor: &mut ui::EditorView,
|
||||
|
@ -312,16 +316,16 @@ impl super::PluginSystem for SteelScriptingEngine {
|
|||
}
|
||||
|
||||
fn get_doc_for_identifier(&self, ident: &str) -> Option<String> {
|
||||
if ENGINE.with(|x| x.borrow().global_exists(ident)) {
|
||||
if let Some(v) = ExportedIdentifiers::engine_get_doc(ident) {
|
||||
return Some(v.into());
|
||||
}
|
||||
|
||||
return Some("Run this plugin command!".into());
|
||||
}
|
||||
|
||||
ExportedIdentifiers::engine_get_doc(ident)
|
||||
.map(|v| v.into())
|
||||
.or_else(|| {
|
||||
if Self::is_exported(self, ident) {
|
||||
Some("Run this plugin command!".into())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn fuzzy_match<'a>(
|
||||
&self,
|
||||
|
@ -349,15 +353,6 @@ impl super::PluginSystem for SteelScriptingEngine {
|
|||
.unwrap()
|
||||
.contains(ident)
|
||||
}
|
||||
|
||||
fn engine_get_doc(&self, ident: &str) -> Option<String> {
|
||||
EXPORTED_IDENTIFIERS
|
||||
.docs
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(ident)
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
|
||||
impl SteelScriptingEngine {
|
||||
|
|
|
@ -134,11 +134,7 @@ impl Config {
|
|||
let local_config = fs::read_to_string(helix_loader::workspace_config_file())
|
||||
.map_err(ConfigLoadError::Error);
|
||||
|
||||
#[cfg(feature = "steel")]
|
||||
let bindings = crate::commands::engine::scheme::SharedKeyBindingsEventQueue::get();
|
||||
|
||||
#[cfg(not(feature = "steel"))]
|
||||
let bindings = None;
|
||||
let bindings = crate::commands::engine::ScriptingEngine::get_keybindings();
|
||||
|
||||
Config::load(global_config, local_config, bindings)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue