pub struct JsonSection<'a> { /* private fields */ }Expand description
One top-level section’s direct properties, indexed by name.
Opaque handle returned by JsonAst::section, keeping jsonc-parser’s own AST types out
of every downstream crate’s public API and direct dependency graph.
Implementations§
Source§impl JsonSection<'_>
impl JsonSection<'_>
Sourcepub fn position(
&self,
name: &str,
content: &str,
table: &LineOffsetTable,
) -> Option<(Range, Option<Range>)>
pub fn position( &self, name: &str, content: &str, table: &LineOffsetTable, ) -> Option<(Range, Option<Range>)>
Looks up name’s (name_range, version_range) LSP position pair within this section.
version_range is Some only when the property’s value is itself a plain string
literal (an object/array/number/bool/null value has no meaningful “version span”,
matching each caller’s own value.as_str() gate on version_req). None if name
isn’t a direct property of this section.
§Examples
use deps_core::json_ast::JsonAst;
use deps_core::lsp_helpers::LineOffsetTable;
let content = r#"{"require": {"vendor/pkg": {"nested": true}}}"#;
let table = LineOffsetTable::new(content);
let ast = JsonAst::parse(content).unwrap();
let section = ast.section("require").unwrap();
let (_, version_range) = section.position("vendor/pkg", content, &table).unwrap();
assert!(version_range.is_none(), "a non-string value has no version span");
assert!(section.position("missing", content, &table).is_none());Auto Trait Implementations§
impl<'a> Freeze for JsonSection<'a>
impl<'a> RefUnwindSafe for JsonSection<'a>
impl<'a> Send for JsonSection<'a>
impl<'a> Sync for JsonSection<'a>
impl<'a> Unpin for JsonSection<'a>
impl<'a> UnsafeUnpin for JsonSection<'a>
impl<'a> UnwindSafe for JsonSection<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more