Skip to content

Commit

Permalink
Merge pull request #704 from epage/span
Browse files Browse the repository at this point in the history
feat(edit): Make it easier to access spans
  • Loading branch information
epage committed Mar 20, 2024
2 parents 3a777b3 + ddb5bf0 commit 2dc02c0
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 20 deletions.
6 changes: 4 additions & 2 deletions crates/toml_edit/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ impl Array {
&self.decor
}

/// Returns the location within the original document
pub(crate) fn span(&self) -> Option<std::ops::Range<usize>> {
/// The location within the original document
///
/// This generally requires an [`ImDocument`][crate::ImDocument].
pub fn span(&self) -> Option<std::ops::Range<usize>> {
self.span.clone()
}

Expand Down
6 changes: 4 additions & 2 deletions crates/toml_edit/src/array_of_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ impl ArrayOfTables {
a
}

/// Returns the location within the original document
pub(crate) fn span(&self) -> Option<std::ops::Range<usize>> {
/// The location within the original document
///
/// This generally requires an [`ImDocument`][crate::ImDocument].
pub fn span(&self) -> Option<std::ops::Range<usize>> {
self.span.clone()
}

Expand Down
6 changes: 4 additions & 2 deletions crates/toml_edit/src/inline_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ impl InlineTable {
&self.preamble
}

/// Returns the location within the original document
pub(crate) fn span(&self) -> Option<std::ops::Range<usize>> {
/// The location within the original document
///
/// This generally requires an [`ImDocument`][crate::ImDocument].
pub fn span(&self) -> Option<std::ops::Range<usize>> {
self.span.clone()
}

Expand Down
6 changes: 4 additions & 2 deletions crates/toml_edit/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,10 @@ impl Item {
self.as_table_like().is_some()
}

/// Returns the location within the original document
pub(crate) fn span(&self) -> Option<std::ops::Range<usize>> {
/// The location within the original document
///
/// This generally requires an [`ImDocument`][crate::ImDocument].
pub fn span(&self) -> Option<std::ops::Range<usize>> {
match self {
Item::None => None,
Item::Value(v) => v.span(),
Expand Down
7 changes: 4 additions & 3 deletions crates/toml_edit/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ impl Key {
&self.dotted_decor
}

/// Returns the location within the original document
#[cfg(feature = "serde")]
pub(crate) fn span(&self) -> Option<std::ops::Range<usize>> {
/// The location within the original document
///
/// This generally requires an [`ImDocument`][crate::ImDocument].
pub fn span(&self) -> Option<std::ops::Range<usize>> {
self.repr.as_ref().and_then(|r| r.span())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/toml_edit/src/raw_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl RawString {
}
}

/// Access the underlying span
/// The location within the original document
///
/// This generally requires an [`ImDocument`][crate::ImDocument].
pub fn span(&self) -> Option<std::ops::Range<usize>> {
Expand Down
12 changes: 8 additions & 4 deletions crates/toml_edit/src/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ where
})
}

/// Returns the location within the original document
pub(crate) fn span(&self) -> Option<std::ops::Range<usize>> {
/// The location within the original document
///
/// This generally requires an [`ImDocument`][crate::ImDocument].
pub fn span(&self) -> Option<std::ops::Range<usize>> {
self.repr.as_ref().and_then(|r| r.span())
}

Expand Down Expand Up @@ -150,8 +152,10 @@ impl Repr {
&self.raw_value
}

/// Returns the location within the original document
pub(crate) fn span(&self) -> Option<std::ops::Range<usize>> {
/// The location within the original document
///
/// This generally requires an [`ImDocument`][crate::ImDocument].
pub fn span(&self) -> Option<std::ops::Range<usize>> {
self.raw_value.span()
}

Expand Down
6 changes: 4 additions & 2 deletions crates/toml_edit/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ impl Table {
self.items.get(key).map(|kv| kv.key.leaf_decor())
}

/// Returns the location within the original document
pub(crate) fn span(&self) -> Option<std::ops::Range<usize>> {
/// The location within the original document
///
/// This generally requires an [`ImDocument`][crate::ImDocument].
pub fn span(&self) -> Option<std::ops::Range<usize>> {
self.span.clone()
}

Expand Down
6 changes: 4 additions & 2 deletions crates/toml_edit/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ impl Value {
*decor = Decor::new(prefix, suffix);
}

/// Returns the location within the original document
pub(crate) fn span(&self) -> Option<std::ops::Range<usize>> {
/// The location within the original document
///
/// This generally requires an [`ImDocument`][crate::ImDocument].
pub fn span(&self) -> Option<std::ops::Range<usize>> {
match self {
Value::String(f) => f.span(),
Value::Integer(f) => f.span(),
Expand Down

0 comments on commit 2dc02c0

Please sign in to comment.