From 18fa67d1575eabe38a752690f51ca729168b5c4f Mon Sep 17 00:00:00 2001 From: mattwparas Date: Thu, 24 Aug 2023 20:01:49 -0700 Subject: [PATCH] more clean up --- helix-core/src/extensions.rs | 120 ----------------------- helix-term/src/commands/engine.rs | 42 ++++---- helix-term/src/commands/engine/scheme.rs | 20 ++-- 3 files changed, 27 insertions(+), 155 deletions(-) diff --git a/helix-core/src/extensions.rs b/helix-core/src/extensions.rs index 242a9c7c5..5f14dae3c 100644 --- a/helix-core/src/extensions.rs +++ b/helix-core/src/extensions.rs @@ -16,107 +16,6 @@ pub mod steel_implementations { impl steel::rvals::Custom for crate::Position {} 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 { - 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::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)] enum SliceKind { Normal(usize, usize), @@ -130,26 +29,7 @@ pub mod steel_implementations { 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 SteelRopeString {} impl SteelRopeSlice { pub fn from_string(string: SteelString) -> Self { diff --git a/helix-term/src/commands/engine.rs b/helix-term/src/commands/engine.rs index 80c49b401..104f65f50 100644 --- a/helix-term/src/commands/engine.rs +++ b/helix-term/src/commands/engine.rs @@ -8,7 +8,7 @@ use crate::{ 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")] mod components; @@ -32,14 +32,14 @@ static PLUGIN_SYSTEM: PluginEngine = #[cfg(not(feature = "steel"))] static PLUGIN_SYSTEM: PluginEngine = PluginEngine(NoEngine); -enum PluginSystemTypes { - None, - Steel, -} +// enum PluginSystemTypes { +// None, +// Steel, +// } // The order in which the plugins will be evaluated against - if we wanted to include, lets say `rhai`, -// we would have to -static PLUGIN_PRECEDENCE: &[PluginSystemTypes] = &[PluginSystemTypes::Steel]; +// we would have to order the precedence for searching for exported commands, or somehow merge them? +// static PLUGIN_PRECEDENCE: &[PluginSystemTypes] = &[PluginSystemTypes::Steel]; pub struct NoEngine; @@ -114,13 +114,13 @@ impl PluginSystem for NoEngine {} pub trait PluginSystem { fn initialize(&self) {} - fn run_initialization_script(&self, cx: &mut Context) {} + fn run_initialization_script(&self, _cx: &mut Context) {} fn handle_keymap_event( &self, editor: &mut ui::EditorView, mode: Mode, - cxt: &mut Context, + _cxt: &mut Context, event: KeyEvent, ) -> KeymapResult { editor.keymaps.get(mode, event) @@ -128,40 +128,40 @@ pub trait PluginSystem { fn call_function_if_global_exists( &self, - cx: &mut Context, - name: &str, - args: Vec>, + _cx: &mut Context, + _name: &str, + _args: Vec>, ) -> bool { false } fn call_typed_command_if_global_exists<'a>( &self, - cx: &mut compositor::Context, - input: &'a str, - parts: &'a [&'a str], - event: PromptEvent, + _cx: &mut compositor::Context, + _input: &'a str, + _parts: &'a [&'a str], + _event: PromptEvent, ) -> bool { false } - fn get_doc_for_identifier(&self, ident: &str) -> Option { + fn get_doc_for_identifier(&self, _ident: &str) -> Option { None } fn fuzzy_match<'a>( &self, - fuzzy_matcher: &'a fuzzy_matcher::skim::SkimMatcherV2, - input: &'a str, + _fuzzy_matcher: &'a fuzzy_matcher::skim::SkimMatcherV2, + _input: &'a str, ) -> Vec<(String, i64)> { Vec::new() } - fn is_exported(&self, ident: &str) -> bool { + fn is_exported(&self, _ident: &str) -> bool { false } - fn engine_get_doc(&self, ident: &str) -> Option { + fn engine_get_doc(&self, _ident: &str) -> Option { None } } diff --git a/helix-term/src/commands/engine/scheme.rs b/helix-term/src/commands/engine/scheme.rs index a59a46e19..63e650d0d 100644 --- a/helix-term/src/commands/engine/scheme.rs +++ b/helix-term/src/commands/engine/scheme.rs @@ -1,8 +1,6 @@ use fuzzy_matcher::FuzzyMatcher; use helix_core::{ - extensions::steel_implementations::{ - rope_module, rope_slice_module, SRopeSlice, SteelRopeSlice, - }, + extensions::steel_implementations::{rope_module, SteelRopeSlice}, graphemes, shellwords::Shellwords, Range, Selection, Tendril, @@ -19,20 +17,14 @@ use serde_json::Value; use steel::{ gc::unsafe_erased_pointers::CustomReference, rerrs::ErrorKind, - rvals::{ - as_underlying_type, AsRefMutSteelValFromRef, AsRefSteelVal, FromSteelVal, IntoSteelVal, - }, - steel_vm::{ - engine::Engine, - register_fn::{RegisterFn, RegisterFnBorrowed}, - }, + rvals::{as_underlying_type, AsRefMutSteelValFromRef, FromSteelVal, IntoSteelVal}, + steel_vm::{engine::Engine, register_fn::RegisterFn}, SteelErr, SteelVal, }; use std::{ borrow::Cow, collections::{HashMap, VecDeque}, - marker::PhantomData, ops::Deref, path::PathBuf, sync::Mutex, @@ -49,13 +41,13 @@ use crate::{ compositor::{self, Component, Compositor}, config::Config, job::{self, Callback}, - keymap::{self, merge_keys, KeyTrie, KeymapResult, Keymaps}, - ui::{self, menu::Item, overlay::overlaid, Popup, Prompt, PromptEvent}, + keymap::{self, merge_keys, KeyTrie, KeymapResult}, + ui::{self, menu::Item, Popup, Prompt, PromptEvent}, }; 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}; thread_local! {