mirror of https://github.com/helix-editor/helix
more clean up
parent
69302c26ab
commit
18fa67d157
|
@ -16,107 +16,6 @@ pub mod steel_implementations {
|
||||||
impl steel::rvals::Custom for crate::Position {}
|
impl steel::rvals::Custom for crate::Position {}
|
||||||
impl steel::rvals::Custom for crate::Selection {}
|
impl steel::rvals::Custom for crate::Selection {}
|
||||||
|
|
||||||
pub struct SRopeSlice<'a> {
|
|
||||||
slice: crate::RopeSlice<'a>,
|
|
||||||
}
|
|
||||||
|
|
||||||
steel::custom_reference!(SRopeSlice<'a>);
|
|
||||||
impl<'a> CustomReference for SRopeSlice<'a> {}
|
|
||||||
|
|
||||||
// impl Custom for SRopeSlice<'static> {}
|
|
||||||
|
|
||||||
pub struct SRopeSliceCowStr<'a>(Cow<'a, str>);
|
|
||||||
steel::custom_reference!(SRopeSliceCowStr<'a>);
|
|
||||||
impl<'a> CustomReference for SRopeSliceCowStr<'a> {}
|
|
||||||
|
|
||||||
struct CharIter<'a>(Chars<'a>);
|
|
||||||
|
|
||||||
impl<'a> SRopeSlice<'a> {
|
|
||||||
pub fn new(slice: crate::RopeSlice<'a>) -> Self {
|
|
||||||
Self { slice }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn char_to_byte(&self, pos: usize) -> usize {
|
|
||||||
self.slice.char_to_byte(pos)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn byte_slice(&'a self, lower: usize, upper: usize) -> SRopeSlice<'a> {
|
|
||||||
SRopeSlice {
|
|
||||||
slice: self.slice.byte_slice(lower..upper),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn line(&'a self, cursor: usize) -> SRopeSlice<'a> {
|
|
||||||
SRopeSlice {
|
|
||||||
slice: self.slice.line(cursor),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_cow(&'a self) -> SRopeSliceCowStr<'a> {
|
|
||||||
SRopeSliceCowStr(std::borrow::Cow::from(self.slice))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_string(&self) -> String {
|
|
||||||
self.slice.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn len_chars(&'a self) -> usize {
|
|
||||||
self.slice.len_chars()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn slice(&'a self, lower: usize, upper: usize) -> SRopeSlice<'a> {
|
|
||||||
SRopeSlice {
|
|
||||||
slice: self.slice.slice(lower..upper),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_char(&'a self, index: usize) -> Option<char> {
|
|
||||||
self.slice.get_char(index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
pub fn rope_slice_module() -> BuiltInModule {
|
|
||||||
let mut module = BuiltInModule::new("helix/core/text");
|
|
||||||
|
|
||||||
// (SELF, ARG, SELFSTAT, RET, RETSTAT)
|
|
||||||
|
|
||||||
RegisterFnBorrowed::<
|
|
||||||
_,
|
|
||||||
steel::steel_vm::register_fn::MarkerWrapper9<(
|
|
||||||
SRopeSlice<'_>,
|
|
||||||
usize,
|
|
||||||
SRopeSlice<'static>,
|
|
||||||
SRopeSlice<'_>,
|
|
||||||
SRopeSlice<'static>,
|
|
||||||
)>,
|
|
||||||
SRopeSlice,
|
|
||||||
>::register_fn_borrowed(&mut module, "slice->line", SRopeSlice::line);
|
|
||||||
|
|
||||||
// TODO: Note the difficulty of the lifetime params here
|
|
||||||
module.register_fn("slice->string", SRopeSlice::to_string);
|
|
||||||
module.register_fn("slice-char->byte", SRopeSlice::char_to_byte);
|
|
||||||
|
|
||||||
// module
|
|
||||||
// .register_fn("slice-char->byte", SRopeSlice::char_to_byte)
|
|
||||||
// .register_fn_borrowed::<S("slice->line", SRopeSlice::line);
|
|
||||||
// .register_fn("slice->byte-slice", SRopeSlice::byte_slice);
|
|
||||||
|
|
||||||
// module.register_fn("slice-len-chars", SRopeSlice::len_chars);
|
|
||||||
|
|
||||||
module
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
enum SliceKind {
|
enum SliceKind {
|
||||||
Normal(usize, usize),
|
Normal(usize, usize),
|
||||||
|
@ -130,26 +29,7 @@ pub mod steel_implementations {
|
||||||
ranges: SmallVec<[SliceKind; 5]>,
|
ranges: SmallVec<[SliceKind; 5]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[derive(Clone)]
|
|
||||||
// pub struct SteelRopeString {
|
|
||||||
// slice: SteelRopeSlice,
|
|
||||||
// operations: SmallVec<[StringOperation; 5]>,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[derive(Clone)]
|
|
||||||
// enum StringOperation {
|
|
||||||
// TrimStart,
|
|
||||||
// StartsWith(SteelString),
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl SteelRopeString {
|
|
||||||
// pub fn evaluate(&self) -> SteelVal {
|
|
||||||
// todo!()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
impl Custom for SteelRopeSlice {}
|
impl Custom for SteelRopeSlice {}
|
||||||
// impl Custom for SteelRopeString {}
|
|
||||||
|
|
||||||
impl SteelRopeSlice {
|
impl SteelRopeSlice {
|
||||||
pub fn from_string(string: SteelString) -> Self {
|
pub fn from_string(string: SteelString) -> Self {
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
ui::{self, PromptEvent},
|
ui::{self, PromptEvent},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{indent, shell_impl, Context, MappableCommand, TYPABLE_COMMAND_LIST};
|
use super::{shell_impl, Context, MappableCommand, TYPABLE_COMMAND_LIST};
|
||||||
|
|
||||||
#[cfg(feature = "steel")]
|
#[cfg(feature = "steel")]
|
||||||
mod components;
|
mod components;
|
||||||
|
@ -32,14 +32,14 @@ static PLUGIN_SYSTEM: PluginEngine<scheme::SteelScriptingEngine> =
|
||||||
#[cfg(not(feature = "steel"))]
|
#[cfg(not(feature = "steel"))]
|
||||||
static PLUGIN_SYSTEM: PluginEngine<NoEngine> = PluginEngine(NoEngine);
|
static PLUGIN_SYSTEM: PluginEngine<NoEngine> = PluginEngine(NoEngine);
|
||||||
|
|
||||||
enum PluginSystemTypes {
|
// enum PluginSystemTypes {
|
||||||
None,
|
// None,
|
||||||
Steel,
|
// Steel,
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 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
|
// we would have to order the precedence for searching for exported commands, or somehow merge them?
|
||||||
static PLUGIN_PRECEDENCE: &[PluginSystemTypes] = &[PluginSystemTypes::Steel];
|
// static PLUGIN_PRECEDENCE: &[PluginSystemTypes] = &[PluginSystemTypes::Steel];
|
||||||
|
|
||||||
pub struct NoEngine;
|
pub struct NoEngine;
|
||||||
|
|
||||||
|
@ -114,13 +114,13 @@ impl PluginSystem for NoEngine {}
|
||||||
pub trait PluginSystem {
|
pub trait PluginSystem {
|
||||||
fn initialize(&self) {}
|
fn initialize(&self) {}
|
||||||
|
|
||||||
fn run_initialization_script(&self, cx: &mut Context) {}
|
fn run_initialization_script(&self, _cx: &mut Context) {}
|
||||||
|
|
||||||
fn handle_keymap_event(
|
fn handle_keymap_event(
|
||||||
&self,
|
&self,
|
||||||
editor: &mut ui::EditorView,
|
editor: &mut ui::EditorView,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
cxt: &mut Context,
|
_cxt: &mut Context,
|
||||||
event: KeyEvent,
|
event: KeyEvent,
|
||||||
) -> KeymapResult {
|
) -> KeymapResult {
|
||||||
editor.keymaps.get(mode, event)
|
editor.keymaps.get(mode, event)
|
||||||
|
@ -128,40 +128,40 @@ pub trait PluginSystem {
|
||||||
|
|
||||||
fn call_function_if_global_exists(
|
fn call_function_if_global_exists(
|
||||||
&self,
|
&self,
|
||||||
cx: &mut Context,
|
_cx: &mut Context,
|
||||||
name: &str,
|
_name: &str,
|
||||||
args: Vec<Cow<str>>,
|
_args: Vec<Cow<str>>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_typed_command_if_global_exists<'a>(
|
fn call_typed_command_if_global_exists<'a>(
|
||||||
&self,
|
&self,
|
||||||
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 {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_doc_for_identifier(&self, ident: &str) -> Option<String> {
|
fn get_doc_for_identifier(&self, _ident: &str) -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fuzzy_match<'a>(
|
fn fuzzy_match<'a>(
|
||||||
&self,
|
&self,
|
||||||
fuzzy_matcher: &'a fuzzy_matcher::skim::SkimMatcherV2,
|
_fuzzy_matcher: &'a fuzzy_matcher::skim::SkimMatcherV2,
|
||||||
input: &'a str,
|
_input: &'a str,
|
||||||
) -> Vec<(String, i64)> {
|
) -> Vec<(String, i64)> {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_exported(&self, ident: &str) -> bool {
|
fn is_exported(&self, _ident: &str) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn engine_get_doc(&self, ident: &str) -> Option<String> {
|
fn engine_get_doc(&self, _ident: &str) -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use fuzzy_matcher::FuzzyMatcher;
|
use fuzzy_matcher::FuzzyMatcher;
|
||||||
use helix_core::{
|
use helix_core::{
|
||||||
extensions::steel_implementations::{
|
extensions::steel_implementations::{rope_module, SteelRopeSlice},
|
||||||
rope_module, rope_slice_module, SRopeSlice, SteelRopeSlice,
|
|
||||||
},
|
|
||||||
graphemes,
|
graphemes,
|
||||||
shellwords::Shellwords,
|
shellwords::Shellwords,
|
||||||
Range, Selection, Tendril,
|
Range, Selection, Tendril,
|
||||||
|
@ -19,20 +17,14 @@ use serde_json::Value;
|
||||||
use steel::{
|
use steel::{
|
||||||
gc::unsafe_erased_pointers::CustomReference,
|
gc::unsafe_erased_pointers::CustomReference,
|
||||||
rerrs::ErrorKind,
|
rerrs::ErrorKind,
|
||||||
rvals::{
|
rvals::{as_underlying_type, AsRefMutSteelValFromRef, FromSteelVal, IntoSteelVal},
|
||||||
as_underlying_type, AsRefMutSteelValFromRef, AsRefSteelVal, FromSteelVal, IntoSteelVal,
|
steel_vm::{engine::Engine, register_fn::RegisterFn},
|
||||||
},
|
|
||||||
steel_vm::{
|
|
||||||
engine::Engine,
|
|
||||||
register_fn::{RegisterFn, RegisterFnBorrowed},
|
|
||||||
},
|
|
||||||
SteelErr, SteelVal,
|
SteelErr, SteelVal,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
collections::{HashMap, VecDeque},
|
collections::{HashMap, VecDeque},
|
||||||
marker::PhantomData,
|
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::Mutex,
|
sync::Mutex,
|
||||||
|
@ -49,13 +41,13 @@ use crate::{
|
||||||
compositor::{self, Component, Compositor},
|
compositor::{self, Component, Compositor},
|
||||||
config::Config,
|
config::Config,
|
||||||
job::{self, Callback},
|
job::{self, Callback},
|
||||||
keymap::{self, merge_keys, KeyTrie, KeymapResult, Keymaps},
|
keymap::{self, merge_keys, KeyTrie, KeymapResult},
|
||||||
ui::{self, menu::Item, overlay::overlaid, Popup, Prompt, PromptEvent},
|
ui::{self, menu::Item, Popup, Prompt, PromptEvent},
|
||||||
};
|
};
|
||||||
|
|
||||||
use components::SteelDynamicComponent;
|
use components::SteelDynamicComponent;
|
||||||
|
|
||||||
use super::{components, indent, shell_impl, Context, MappableCommand, TYPABLE_COMMAND_LIST};
|
use super::{components, shell_impl, Context, MappableCommand, TYPABLE_COMMAND_LIST};
|
||||||
use insert::{insert_char, insert_string};
|
use insert::{insert_char, insert_string};
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
|
|
Loading…
Reference in New Issue