Skip to content

Commit 293560f

Browse files
committed
feat: introduce mago-text-edit crate!
ref #762 Signed-off-by: azjezz <[email protected]>
1 parent 85ba225 commit 293560f

File tree

6 files changed

+412
-0
lines changed

6 files changed

+412
-0
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ mago-casing = { path = "crates/casing", version = "1.0.0-rc.13" }
3434
mago-composer = { path = "crates/composer", version = "1.0.0-rc.13" }
3535
mago-docblock = { path = "crates/docblock", version = "1.0.0-rc.13" }
3636
mago-fixer = { path = "crates/fixer", version = "1.0.0-rc.13" }
37+
mago-text-edit = { path = "crates/text-edit", version = "1.0.0-rc.13" }
3738
mago-formatter = { path = "crates/formatter", version = "1.0.0-rc.13" }
3839
mago-fingerprint = { path = "crates/fingerprint", version = "1.0.0-rc.13" }
3940
mago-atom = { path = "crates/atom", version = "1.0.0-rc.13" }

Justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ publish:
5454
cargo publish -p mago-casing
5555
cargo publish -p mago-php-version
5656
cargo publish -p mago-fixer
57+
cargo publish -p mago-text-edit
5758
cargo publish -p mago-atom
5859
cargo publish -p mago-database
5960
cargo publish -p mago-span

crates/span/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
//! the generic traits [`HasPosition`] and [`HasSpan`] to abstract over any syntax
66
//! tree node or token that has a location.
77
8+
use std::ops::Bound;
89
use std::ops::Range;
10+
use std::ops::RangeBounds;
911

1012
use serde::Deserialize;
1113
use serde::Serialize;
@@ -238,6 +240,16 @@ impl HasSpan for Span {
238240
}
239241
}
240242

243+
impl RangeBounds<u32> for Span {
244+
fn start_bound(&self) -> Bound<&u32> {
245+
Bound::Included(&self.start.offset)
246+
}
247+
248+
fn end_bound(&self) -> Bound<&u32> {
249+
Bound::Excluded(&self.end.offset)
250+
}
251+
}
252+
241253
/// A blanket implementation that allows any `HasSpan` type to also be treated
242254
/// as a `HasPosition` type, using the span's start as its position.
243255
impl<T: HasSpan> HasPosition for T {

crates/text-edit/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "mago-text-edit"
3+
description = "A text editing library for Mago"
4+
version.workspace = true
5+
edition.workspace = true
6+
authors.workspace = true
7+
license.workspace = true
8+
homepage.workspace = true
9+
repository.workspace = true
10+
rust-version.workspace = true
11+
12+
[lints]
13+
workspace = true
14+
15+
[dependencies]
16+
strum = { workspace = true }
17+
serde = { workspace = true }
18+
tracing = { workspace = true }
19+
20+
[dev-dependencies]
21+
pretty_assertions = { workspace = true }

0 commit comments

Comments
 (0)