From ddb5bf010f2dc1ff3d3001e5c7bf2b3386f6d3fd Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 20 Mar 2024 10:23:14 -0500 Subject: [PATCH] feat(edit): Make it easier to access spans --- crates/toml_edit/src/array.rs | 6 ++++-- crates/toml_edit/src/array_of_tables.rs | 6 ++++-- crates/toml_edit/src/inline_table.rs | 6 ++++-- crates/toml_edit/src/item.rs | 6 ++++-- crates/toml_edit/src/key.rs | 7 ++++--- crates/toml_edit/src/raw_string.rs | 2 +- crates/toml_edit/src/repr.rs | 12 ++++++++---- crates/toml_edit/src/table.rs | 6 ++++-- crates/toml_edit/src/value.rs | 6 ++++-- 9 files changed, 37 insertions(+), 20 deletions(-) diff --git a/crates/toml_edit/src/array.rs b/crates/toml_edit/src/array.rs index 377f6765..4e3d4704 100644 --- a/crates/toml_edit/src/array.rs +++ b/crates/toml_edit/src/array.rs @@ -87,8 +87,10 @@ impl Array { &self.decor } - /// Returns the location within the original document - pub(crate) fn span(&self) -> Option> { + /// The location within the original document + /// + /// This generally requires an [`ImDocument`][crate::ImDocument]. + pub fn span(&self) -> Option> { self.span.clone() } diff --git a/crates/toml_edit/src/array_of_tables.rs b/crates/toml_edit/src/array_of_tables.rs index 2e602a2c..bbc4c7d5 100644 --- a/crates/toml_edit/src/array_of_tables.rs +++ b/crates/toml_edit/src/array_of_tables.rs @@ -32,8 +32,10 @@ impl ArrayOfTables { a } - /// Returns the location within the original document - pub(crate) fn span(&self) -> Option> { + /// The location within the original document + /// + /// This generally requires an [`ImDocument`][crate::ImDocument]. + pub fn span(&self) -> Option> { self.span.clone() } diff --git a/crates/toml_edit/src/inline_table.rs b/crates/toml_edit/src/inline_table.rs index 705c6679..f7f6465b 100644 --- a/crates/toml_edit/src/inline_table.rs +++ b/crates/toml_edit/src/inline_table.rs @@ -219,8 +219,10 @@ impl InlineTable { &self.preamble } - /// Returns the location within the original document - pub(crate) fn span(&self) -> Option> { + /// The location within the original document + /// + /// This generally requires an [`ImDocument`][crate::ImDocument]. + pub fn span(&self) -> Option> { self.span.clone() } diff --git a/crates/toml_edit/src/item.rs b/crates/toml_edit/src/item.rs index 6ca227ef..2d30655f 100644 --- a/crates/toml_edit/src/item.rs +++ b/crates/toml_edit/src/item.rs @@ -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> { + /// The location within the original document + /// + /// This generally requires an [`ImDocument`][crate::ImDocument]. + pub fn span(&self) -> Option> { match self { Item::None => None, Item::Value(v) => v.span(), diff --git a/crates/toml_edit/src/key.rs b/crates/toml_edit/src/key.rs index f531890e..64a9f2a6 100644 --- a/crates/toml_edit/src/key.rs +++ b/crates/toml_edit/src/key.rs @@ -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> { + /// The location within the original document + /// + /// This generally requires an [`ImDocument`][crate::ImDocument]. + pub fn span(&self) -> Option> { self.repr.as_ref().and_then(|r| r.span()) } diff --git a/crates/toml_edit/src/raw_string.rs b/crates/toml_edit/src/raw_string.rs index 86b70c3e..1db73c3d 100644 --- a/crates/toml_edit/src/raw_string.rs +++ b/crates/toml_edit/src/raw_string.rs @@ -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> { diff --git a/crates/toml_edit/src/repr.rs b/crates/toml_edit/src/repr.rs index ad41bbfe..3ae18b48 100644 --- a/crates/toml_edit/src/repr.rs +++ b/crates/toml_edit/src/repr.rs @@ -60,8 +60,10 @@ where }) } - /// Returns the location within the original document - pub(crate) fn span(&self) -> Option> { + /// The location within the original document + /// + /// This generally requires an [`ImDocument`][crate::ImDocument]. + pub fn span(&self) -> Option> { self.repr.as_ref().and_then(|r| r.span()) } @@ -150,8 +152,10 @@ impl Repr { &self.raw_value } - /// Returns the location within the original document - pub(crate) fn span(&self) -> Option> { + /// The location within the original document + /// + /// This generally requires an [`ImDocument`][crate::ImDocument]. + pub fn span(&self) -> Option> { self.raw_value.span() } diff --git a/crates/toml_edit/src/table.rs b/crates/toml_edit/src/table.rs index 02c8b312..8c890e29 100644 --- a/crates/toml_edit/src/table.rs +++ b/crates/toml_edit/src/table.rs @@ -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> { + /// The location within the original document + /// + /// This generally requires an [`ImDocument`][crate::ImDocument]. + pub fn span(&self) -> Option> { self.span.clone() } diff --git a/crates/toml_edit/src/value.rs b/crates/toml_edit/src/value.rs index 5797574e..07d4ab63 100644 --- a/crates/toml_edit/src/value.rs +++ b/crates/toml_edit/src/value.rs @@ -206,8 +206,10 @@ impl Value { *decor = Decor::new(prefix, suffix); } - /// Returns the location within the original document - pub(crate) fn span(&self) -> Option> { + /// The location within the original document + /// + /// This generally requires an [`ImDocument`][crate::ImDocument]. + pub fn span(&self) -> Option> { match self { Value::String(f) => f.span(), Value::Integer(f) => f.span(),