mirror of https://github.com/helix-editor/helix
address comments on rope library
parent
cf967ed71e
commit
fd4c689369
|
@ -2309,7 +2309,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "steel-core"
|
name = "steel-core"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/mattwparas/steel.git#1fb88e561474c723a4fd2675553d6091a380aef1"
|
source = "git+https://github.com/mattwparas/steel.git#01e42f435de3f6ca8cf083fdfc422d2a445d5bc9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"abi_stable",
|
"abi_stable",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
@ -2345,7 +2345,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "steel-derive"
|
name = "steel-derive"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
source = "git+https://github.com/mattwparas/steel.git#1fb88e561474c723a4fd2675553d6091a380aef1"
|
source = "git+https://github.com/mattwparas/steel.git#01e42f435de3f6ca8cf083fdfc422d2a445d5bc9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -2355,7 +2355,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "steel-gen"
|
name = "steel-gen"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/mattwparas/steel.git#1fb88e561474c723a4fd2675553d6091a380aef1"
|
source = "git+https://github.com/mattwparas/steel.git#01e42f435de3f6ca8cf083fdfc422d2a445d5bc9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"codegen",
|
"codegen",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -2365,7 +2365,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "steel-parser"
|
name = "steel-parser"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/mattwparas/steel.git#1fb88e561474c723a4fd2675553d6091a380aef1"
|
source = "git+https://github.com/mattwparas/steel.git#01e42f435de3f6ca8cf083fdfc422d2a445d5bc9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fxhash",
|
"fxhash",
|
||||||
"lasso",
|
"lasso",
|
||||||
|
|
|
@ -5,10 +5,13 @@ pub mod steel_implementations {
|
||||||
|
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use steel::{
|
use steel::{
|
||||||
rvals::{Custom, SteelString},
|
rvals::{as_underlying_type, Custom, SteelString},
|
||||||
steel_vm::{builtin::BuiltInModule, register_fn::RegisterFn},
|
steel_vm::{builtin::BuiltInModule, register_fn::RegisterFn},
|
||||||
|
SteelVal,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use helix_stdx::rope::RopeSliceExt;
|
||||||
|
|
||||||
use crate::syntax::{AutoPairConfig, SoftWrap};
|
use crate::syntax::{AutoPairConfig, SoftWrap};
|
||||||
|
|
||||||
impl steel::rvals::Custom for crate::Position {}
|
impl steel::rvals::Custom for crate::Position {}
|
||||||
|
@ -16,20 +19,38 @@ pub mod steel_implementations {
|
||||||
impl steel::rvals::Custom for AutoPairConfig {}
|
impl steel::rvals::Custom for AutoPairConfig {}
|
||||||
impl steel::rvals::Custom for SoftWrap {}
|
impl steel::rvals::Custom for SoftWrap {}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
enum SliceKind {
|
enum SliceKind {
|
||||||
Normal(usize, usize),
|
Normal(usize, usize),
|
||||||
Byte(usize, usize),
|
Byte(usize, usize),
|
||||||
Line(usize),
|
Line(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct SteelRopeSlice {
|
pub struct SteelRopeSlice {
|
||||||
text: crate::Rope,
|
text: crate::Rope,
|
||||||
ranges: SmallVec<[SliceKind; 5]>,
|
ranges: SmallVec<[SliceKind; 5]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Custom for SteelRopeSlice {}
|
impl Custom for SteelRopeSlice {
|
||||||
|
// `equal?` on two ropes should return true if they are the same
|
||||||
|
fn equality_hint(&self, other: &dyn steel::rvals::CustomType) -> bool {
|
||||||
|
if let Some(other) = as_underlying_type::<SteelRopeSlice>(other) {
|
||||||
|
self == other
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn equality_hint_general(&self, other: &steel::SteelVal) -> bool {
|
||||||
|
match other {
|
||||||
|
SteelVal::StringV(s) => self.to_slice() == s.as_str(),
|
||||||
|
SteelVal::Custom(c) => Self::equality_hint(&self, c.borrow().as_ref()),
|
||||||
|
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SteelRopeSlice {
|
impl SteelRopeSlice {
|
||||||
pub fn from_string(string: SteelString) -> Self {
|
pub fn from_string(string: SteelString) -> Self {
|
||||||
|
@ -95,30 +116,48 @@ pub mod steel_implementations {
|
||||||
self.to_slice().len_lines()
|
self.to_slice().len_lines()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn trim_start(mut self) -> Self {
|
||||||
|
for (idx, c) in self.to_slice().chars().enumerate() {
|
||||||
|
if !c.is_whitespace() {
|
||||||
|
self.ranges.push(SliceKind::Normal(0, idx));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn trimmed_starts_with(&self, pat: SteelString) -> bool {
|
pub fn trimmed_starts_with(&self, pat: SteelString) -> bool {
|
||||||
let maybe_owned = Cow::from(self.to_slice());
|
let maybe_owned = Cow::from(self.to_slice());
|
||||||
|
|
||||||
maybe_owned.trim_start().starts_with(pat.as_str())
|
maybe_owned.trim_start().starts_with(pat.as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn starts_with(&self, pat: SteelString) -> bool {
|
||||||
|
self.to_slice().starts_with(pat.as_str())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ends_with(&self, pat: SteelString) -> bool {
|
||||||
|
self.to_slice().ends_with(pat.as_str())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rope_module() -> BuiltInModule {
|
pub fn rope_module() -> BuiltInModule {
|
||||||
let mut module = BuiltInModule::new("helix/core/text");
|
let mut module = BuiltInModule::new("helix/core/text");
|
||||||
|
|
||||||
module
|
module
|
||||||
.register_fn("string->slice", SteelRopeSlice::from_string)
|
.register_fn("string->rope", SteelRopeSlice::from_string)
|
||||||
.register_fn("slice->slice", SteelRopeSlice::slice)
|
.register_fn("rope->slice", SteelRopeSlice::slice)
|
||||||
.register_fn("slice-char->byte", SteelRopeSlice::char_to_byte)
|
.register_fn("rope-char->byte", SteelRopeSlice::char_to_byte)
|
||||||
.register_fn("slice->byte-slice", SteelRopeSlice::byte_slice)
|
.register_fn("rope->byte-slice", SteelRopeSlice::byte_slice)
|
||||||
.register_fn("slice->line", SteelRopeSlice::line)
|
.register_fn("rope->line", SteelRopeSlice::line)
|
||||||
.register_fn("slice->string", SteelRopeSlice::to_string)
|
.register_fn("rope->string", SteelRopeSlice::to_string)
|
||||||
.register_fn("slice-len-chars", SteelRopeSlice::len_chars)
|
.register_fn("rope-len-chars", SteelRopeSlice::len_chars)
|
||||||
.register_fn("slice-char-ref", SteelRopeSlice::get_char)
|
.register_fn("rope-char-ref", SteelRopeSlice::get_char)
|
||||||
.register_fn("slice-len-lines", SteelRopeSlice::len_lines)
|
.register_fn("rope-len-lines", SteelRopeSlice::len_lines)
|
||||||
.register_fn(
|
.register_fn("rope-starts-with?", SteelRopeSlice::starts_with)
|
||||||
"slice-trim-and-starts-with?",
|
.register_fn("rope-ends-with?", SteelRopeSlice::ends_with)
|
||||||
SteelRopeSlice::trimmed_starts_with,
|
.register_fn("rope-trim-start", SteelRopeSlice::trim_start);
|
||||||
);
|
|
||||||
|
|
||||||
module
|
module
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue