mirror of https://github.com/helix-editor/helix
add feature flag
parent
81243247c6
commit
279f5eddb3
@ -1,243 +1,249 @@
|
|||||||
use std::{borrow::Cow, cell::Cell, rc::Rc};
|
#[cfg(feature = "steel")]
|
||||||
|
pub mod steel_implementations {
|
||||||
|
|
||||||
use ropey::iter::Chars;
|
use std::{borrow::Cow, cell::Cell, rc::Rc};
|
||||||
use smallvec::SmallVec;
|
|
||||||
use steel::{
|
|
||||||
gc::unsafe_erased_pointers::CustomReference,
|
|
||||||
rvals::{Custom, SteelString},
|
|
||||||
steel_vm::{builtin::BuiltInModule, register_fn::RegisterFn, register_fn::RegisterFnBorrowed},
|
|
||||||
};
|
|
||||||
|
|
||||||
impl steel::rvals::Custom for crate::Position {}
|
use ropey::iter::Chars;
|
||||||
impl steel::rvals::Custom for crate::Selection {}
|
use smallvec::SmallVec;
|
||||||
|
use steel::{
|
||||||
|
gc::unsafe_erased_pointers::CustomReference,
|
||||||
|
rvals::{Custom, SteelString},
|
||||||
|
steel_vm::{
|
||||||
|
builtin::BuiltInModule, register_fn::RegisterFn, register_fn::RegisterFnBorrowed,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
pub struct SRopeSlice<'a> {
|
impl steel::rvals::Custom for crate::Position {}
|
||||||
slice: crate::RopeSlice<'a>,
|
impl steel::rvals::Custom for crate::Selection {}
|
||||||
}
|
|
||||||
|
|
||||||
steel::custom_reference!(SRopeSlice<'a>);
|
pub struct SRopeSlice<'a> {
|
||||||
impl<'a> CustomReference for SRopeSlice<'a> {}
|
slice: crate::RopeSlice<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
// impl Custom for SRopeSlice<'static> {}
|
steel::custom_reference!(SRopeSlice<'a>);
|
||||||
|
impl<'a> CustomReference for SRopeSlice<'a> {}
|
||||||
|
|
||||||
pub struct SRopeSliceCowStr<'a>(Cow<'a, str>);
|
// impl Custom for SRopeSlice<'static> {}
|
||||||
steel::custom_reference!(SRopeSliceCowStr<'a>);
|
|
||||||
impl<'a> CustomReference for SRopeSliceCowStr<'a> {}
|
|
||||||
|
|
||||||
struct CharIter<'a>(Chars<'a>);
|
pub struct SRopeSliceCowStr<'a>(Cow<'a, str>);
|
||||||
|
steel::custom_reference!(SRopeSliceCowStr<'a>);
|
||||||
|
impl<'a> CustomReference for SRopeSliceCowStr<'a> {}
|
||||||
|
|
||||||
impl<'a> SRopeSlice<'a> {
|
struct CharIter<'a>(Chars<'a>);
|
||||||
pub fn new(slice: crate::RopeSlice<'a>) -> Self {
|
|
||||||
Self { slice }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn char_to_byte(&self, pos: usize) -> usize {
|
impl<'a> SRopeSlice<'a> {
|
||||||
self.slice.char_to_byte(pos)
|
pub fn new(slice: crate::RopeSlice<'a>) -> Self {
|
||||||
}
|
Self { slice }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn byte_slice(&'a self, lower: usize, upper: usize) -> SRopeSlice<'a> {
|
pub fn char_to_byte(&self, pos: usize) -> usize {
|
||||||
SRopeSlice {
|
self.slice.char_to_byte(pos)
|
||||||
slice: self.slice.byte_slice(lower..upper),
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn line(&'a self, cursor: usize) -> SRopeSlice<'a> {
|
pub fn byte_slice(&'a self, lower: usize, upper: usize) -> SRopeSlice<'a> {
|
||||||
SRopeSlice {
|
SRopeSlice {
|
||||||
slice: self.slice.line(cursor),
|
slice: self.slice.byte_slice(lower..upper),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_cow(&'a self) -> SRopeSliceCowStr<'a> {
|
pub fn line(&'a self, cursor: usize) -> SRopeSlice<'a> {
|
||||||
SRopeSliceCowStr(std::borrow::Cow::from(self.slice))
|
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 to_string(&self) -> String {
|
pub fn get_char(&'a self, index: usize) -> Option<char> {
|
||||||
self.slice.to_string()
|
self.slice.get_char(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len_chars(&'a self) -> usize {
|
// RegisterFn::<
|
||||||
self.slice.len_chars()
|
// _,
|
||||||
|
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn slice(&'a self, lower: usize, upper: usize) -> SRopeSlice<'a> {
|
#[derive(Clone, Copy, Debug)]
|
||||||
SRopeSlice {
|
enum SliceKind {
|
||||||
slice: self.slice.slice(lower..upper),
|
Normal(usize, usize),
|
||||||
}
|
Byte(usize, usize),
|
||||||
|
Line(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_char(&'a self, index: usize) -> Option<char> {
|
#[derive(Clone)]
|
||||||
self.slice.get_char(index)
|
pub struct SteelRopeSlice {
|
||||||
|
text: crate::Rope,
|
||||||
|
ranges: SmallVec<[SliceKind; 5]>,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterFn::<
|
// #[derive(Clone)]
|
||||||
// _,
|
// pub struct SteelRopeString {
|
||||||
// steel::steel_vm::register_fn::MarkerWrapper7<(
|
// slice: SteelRopeSlice,
|
||||||
// Context<'_>,
|
// operations: SmallVec<[StringOperation; 5]>,
|
||||||
// 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)]
|
||||||
enum SliceKind {
|
// enum StringOperation {
|
||||||
Normal(usize, usize),
|
// TrimStart,
|
||||||
Byte(usize, usize),
|
// StartsWith(SteelString),
|
||||||
Line(usize),
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
// impl SteelRopeString {
|
||||||
pub struct SteelRopeSlice {
|
// pub fn evaluate(&self) -> SteelVal {
|
||||||
text: crate::Rope,
|
// todo!()
|
||||||
ranges: SmallVec<[SliceKind; 5]>,
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// #[derive(Clone)]
|
impl Custom for SteelRopeSlice {}
|
||||||
// pub struct SteelRopeString {
|
// impl Custom for SteelRopeString {}
|
||||||
// slice: SteelRopeSlice,
|
|
||||||
// operations: SmallVec<[StringOperation; 5]>,
|
impl SteelRopeSlice {
|
||||||
// }
|
pub fn from_string(string: SteelString) -> Self {
|
||||||
|
Self {
|
||||||
// #[derive(Clone)]
|
text: crate::Rope::from_str(string.as_str()),
|
||||||
// enum StringOperation {
|
ranges: SmallVec::default(),
|
||||||
// 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 {
|
|
||||||
Self {
|
|
||||||
text: crate::Rope::from_str(string.as_str()),
|
|
||||||
ranges: SmallVec::default(),
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(rope: crate::Rope) -> Self {
|
pub fn new(rope: crate::Rope) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: rope,
|
text: rope,
|
||||||
ranges: SmallVec::default(),
|
ranges: SmallVec::default(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn to_slice(&self) -> crate::RopeSlice<'_> {
|
fn to_slice(&self) -> crate::RopeSlice<'_> {
|
||||||
let mut slice = self.text.slice(..);
|
let mut slice = self.text.slice(..);
|
||||||
|
|
||||||
for range in &self.ranges {
|
for range in &self.ranges {
|
||||||
match range {
|
match range {
|
||||||
SliceKind::Normal(l, r) => slice = slice.slice(l..r),
|
SliceKind::Normal(l, r) => slice = slice.slice(l..r),
|
||||||
SliceKind::Byte(l, r) => slice = slice.byte_slice(l..r),
|
SliceKind::Byte(l, r) => slice = slice.byte_slice(l..r),
|
||||||
SliceKind::Line(index) => slice = slice.line(*index),
|
SliceKind::Line(index) => slice = slice.line(*index),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slice
|
||||||
}
|
}
|
||||||
|
|
||||||
slice
|
pub fn slice(mut self, lower: usize, upper: usize) -> Self {
|
||||||
}
|
self.ranges.push(SliceKind::Normal(lower, upper));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn slice(mut self, lower: usize, upper: usize) -> Self {
|
pub fn char_to_byte(&self, pos: usize) -> usize {
|
||||||
self.ranges.push(SliceKind::Normal(lower, upper));
|
self.to_slice().char_to_byte(pos)
|
||||||
self
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn char_to_byte(&self, pos: usize) -> usize {
|
pub fn byte_slice(mut self, lower: usize, upper: usize) -> Self {
|
||||||
self.to_slice().char_to_byte(pos)
|
self.ranges.push(SliceKind::Byte(lower, upper));
|
||||||
}
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn byte_slice(mut self, lower: usize, upper: usize) -> Self {
|
pub fn line(mut self, cursor: usize) -> Self {
|
||||||
self.ranges.push(SliceKind::Byte(lower, upper));
|
self.ranges.push(SliceKind::Line(cursor));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn line(mut self, cursor: usize) -> Self {
|
pub fn to_string(&self) -> String {
|
||||||
self.ranges.push(SliceKind::Line(cursor));
|
self.to_slice().to_string()
|
||||||
self
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_string(&self) -> String {
|
pub fn len_chars(&self) -> usize {
|
||||||
self.to_slice().to_string()
|
self.to_slice().len_chars()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len_chars(&self) -> usize {
|
pub fn get_char(&self, index: usize) -> Option<char> {
|
||||||
self.to_slice().len_chars()
|
self.to_slice().get_char(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_char(&self, index: usize) -> Option<char> {
|
pub fn len_lines(&self) -> usize {
|
||||||
self.to_slice().get_char(index)
|
self.to_slice().len_lines()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len_lines(&self) -> usize {
|
pub fn trimmed_starts_with(&self, pat: SteelString) -> bool {
|
||||||
self.to_slice().len_lines()
|
let maybe_owned = Cow::from(self.to_slice());
|
||||||
}
|
|
||||||
|
|
||||||
pub fn trimmed_starts_with(&self, pat: SteelString) -> bool {
|
maybe_owned.trim_start().starts_with(pat.as_str())
|
||||||
let maybe_owned = Cow::from(self.to_slice());
|
}
|
||||||
|
|
||||||
maybe_owned.trim_start().starts_with(pat.as_str())
|
// pub fn as_cow(&'a self) -> SRopeSliceCowStr<'a> {
|
||||||
|
// SRopeSliceCowStr(std::borrow::Cow::from(self.slice))
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn as_cow(&'a self) -> SRopeSliceCowStr<'a> {
|
pub fn rope_module() -> BuiltInModule {
|
||||||
// SRopeSliceCowStr(std::borrow::Cow::from(self.slice))
|
let mut module = BuiltInModule::new("helix/core/text");
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn rope_module() -> BuiltInModule {
|
module
|
||||||
let mut module = BuiltInModule::new("helix/core/text");
|
.register_fn("string->slice", SteelRopeSlice::from_string)
|
||||||
|
.register_fn("slice->slice", SteelRopeSlice::slice)
|
||||||
module
|
.register_fn("slice-char->byte", SteelRopeSlice::char_to_byte)
|
||||||
.register_fn("string->slice", SteelRopeSlice::from_string)
|
.register_fn("slice->byte-slice", SteelRopeSlice::byte_slice)
|
||||||
.register_fn("slice->slice", SteelRopeSlice::slice)
|
.register_fn("slice->line", SteelRopeSlice::line)
|
||||||
.register_fn("slice-char->byte", SteelRopeSlice::char_to_byte)
|
.register_fn("slice->string", SteelRopeSlice::to_string)
|
||||||
.register_fn("slice->byte-slice", SteelRopeSlice::byte_slice)
|
.register_fn("slice-len-chars", SteelRopeSlice::len_chars)
|
||||||
.register_fn("slice->line", SteelRopeSlice::line)
|
.register_fn("slice-char-ref", SteelRopeSlice::get_char)
|
||||||
.register_fn("slice->string", SteelRopeSlice::to_string)
|
.register_fn("slice-len-lines", SteelRopeSlice::len_lines)
|
||||||
.register_fn("slice-len-chars", SteelRopeSlice::len_chars)
|
.register_fn(
|
||||||
.register_fn("slice-char-ref", SteelRopeSlice::get_char)
|
"slice-trim-and-starts-with?",
|
||||||
.register_fn("slice-len-lines", SteelRopeSlice::len_lines)
|
SteelRopeSlice::trimmed_starts_with,
|
||||||
.register_fn(
|
);
|
||||||
"slice-trim-and-starts-with?",
|
|
||||||
SteelRopeSlice::trimmed_starts_with,
|
module
|
||||||
);
|
}
|
||||||
|
|
||||||
module
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,11 @@
|
|||||||
|
#[cfg(feature = "steel")]
|
||||||
|
mod steel_implementations {
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
compositor::Component,
|
||||||
|
ui::{Popup, Text},
|
||||||
|
};
|
||||||
|
|
||||||
|
impl steel::rvals::Custom for Text {}
|
||||||
|
impl<T: steel::rvals::IntoSteelVal + Component> steel::rvals::Custom for Popup<T> {}
|
||||||
|
}
|
@ -1,7 +1,11 @@
|
|||||||
use crate::{buffer::Buffer, widgets::Widget};
|
#[cfg(feature = "steel")]
|
||||||
|
mod steel_implementations {
|
||||||
|
|
||||||
use steel::{gc::unsafe_erased_pointers::CustomReference, rvals::Custom};
|
use crate::{buffer::Buffer, widgets::Widget};
|
||||||
|
|
||||||
impl CustomReference for Buffer {}
|
use steel::{gc::unsafe_erased_pointers::CustomReference, rvals::Custom};
|
||||||
|
|
||||||
steel::custom_reference!(Buffer);
|
impl CustomReference for Buffer {}
|
||||||
|
|
||||||
|
steel::custom_reference!(Buffer);
|
||||||
|
}
|
||||||
|
@ -1,15 +1,29 @@
|
|||||||
use steel::{gc::unsafe_erased_pointers::CustomReference, rvals::Custom};
|
use crate::DocumentId;
|
||||||
|
|
||||||
use crate::{graphics::Rect, input::Event, Document, DocumentId, ViewId};
|
|
||||||
|
|
||||||
// Reference types along with value types - This should allow for having users
|
|
||||||
impl CustomReference for Event {}
|
|
||||||
impl Custom for Rect {}
|
|
||||||
impl Custom for crate::graphics::CursorKind {}
|
|
||||||
impl Custom for DocumentId {}
|
|
||||||
impl Custom for ViewId {}
|
|
||||||
impl CustomReference for Document {}
|
|
||||||
|
|
||||||
pub fn document_id_to_usize(doc_id: &DocumentId) -> usize {
|
pub fn document_id_to_usize(doc_id: &DocumentId) -> usize {
|
||||||
doc_id.0.into()
|
doc_id.0.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "steel")]
|
||||||
|
mod steel_implementations {
|
||||||
|
|
||||||
|
use steel::{gc::unsafe_erased_pointers::CustomReference, rvals::Custom};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
document::Mode, graphics::Rect, input::Event, Document, DocumentId, Editor, ViewId,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl steel::gc::unsafe_erased_pointers::CustomReference for Editor {}
|
||||||
|
steel::custom_reference!(Editor);
|
||||||
|
|
||||||
|
impl steel::rvals::Custom for Mode {}
|
||||||
|
impl steel::rvals::Custom for Event {}
|
||||||
|
|
||||||
|
// Reference types along with value types - This should allow for having users
|
||||||
|
impl CustomReference for Event {}
|
||||||
|
impl Custom for Rect {}
|
||||||
|
impl Custom for crate::graphics::CursorKind {}
|
||||||
|
impl Custom for DocumentId {}
|
||||||
|
impl Custom for ViewId {}
|
||||||
|
impl CustomReference for Document {}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue