more clean up

pull/8675/merge^2
mattwparas 2023-08-24 20:01:49 -07:00
parent 69302c26ab
commit 18fa67d157
3 changed files with 27 additions and 155 deletions

View File

@ -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<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)]
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 {

View File

@ -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<scheme::SteelScriptingEngine> =
#[cfg(not(feature = "steel"))]
static PLUGIN_SYSTEM: PluginEngine<NoEngine> = 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<Cow<str>>,
_cx: &mut Context,
_name: &str,
_args: Vec<Cow<str>>,
) -> 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<String> {
fn get_doc_for_identifier(&self, _ident: &str) -> Option<String> {
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<String> {
fn engine_get_doc(&self, _ident: &str) -> Option<String> {
None
}
}

View File

@ -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! {