aboutsummaryrefslogtreecommitdiff
path: root/helix-stdx
diff options
context:
space:
mode:
authorPascal Kuthe2023-11-30 23:03:27 +0000
committerBlaž Hrastnik2024-01-23 02:20:19 +0000
commit8e592a151fe7adfbf3fb35ae134b7f2a70700f09 (patch)
tree603a94042068620e52f50cb26cf881d5461d1c8d /helix-stdx
parent13ed4f6c4748019787d24c2b686d417b71604242 (diff)
refactor completion and signature help using hooks
Diffstat (limited to 'helix-stdx')
-rw-r--r--helix-stdx/Cargo.toml1
-rw-r--r--helix-stdx/src/lib.rs1
-rw-r--r--helix-stdx/src/rope.rs26
3 files changed, 28 insertions, 0 deletions
diff --git a/helix-stdx/Cargo.toml b/helix-stdx/Cargo.toml
index 216a3b40..9b4de9fe 100644
--- a/helix-stdx/Cargo.toml
+++ b/helix-stdx/Cargo.toml
@@ -14,6 +14,7 @@ homepage.workspace = true
[dependencies]
dunce = "1.0"
etcetera = "0.8"
+ropey = { version = "1.6.1", default-features = false }
[dev-dependencies]
tempfile = "3.9"
diff --git a/helix-stdx/src/lib.rs b/helix-stdx/src/lib.rs
index ae3c3a98..68fe3ec3 100644
--- a/helix-stdx/src/lib.rs
+++ b/helix-stdx/src/lib.rs
@@ -1,2 +1,3 @@
pub mod env;
pub mod path;
+pub mod rope;
diff --git a/helix-stdx/src/rope.rs b/helix-stdx/src/rope.rs
new file mode 100644
index 00000000..4ee39d4a
--- /dev/null
+++ b/helix-stdx/src/rope.rs
@@ -0,0 +1,26 @@
+use ropey::RopeSlice;
+
+pub trait RopeSliceExt: Sized {
+ fn ends_with(self, text: &str) -> bool;
+ fn starts_with(self, text: &str) -> bool;
+}
+
+impl RopeSliceExt for RopeSlice<'_> {
+ fn ends_with(self, text: &str) -> bool {
+ let len = self.len_bytes();
+ if len < text.len() {
+ return false;
+ }
+ self.get_byte_slice(len - text.len()..)
+ .map_or(false, |end| end == text)
+ }
+
+ fn starts_with(self, text: &str) -> bool {
+ let len = self.len_bytes();
+ if len < text.len() {
+ return false;
+ }
+ self.get_byte_slice(..len - text.len())
+ .map_or(false, |start| start == text)
+ }
+}