MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / authored_anchor

Method authored_anchor

atomic-core/src/pristine/span_patch_storage.rs:945–969  ·  view source on GitHub ↗

Resolve an insertion boundary to a verified authored span and offset. Boundaries between spans use the preceding byte; empty files use their original root. The offset is relative to the returned span.

(&self, position: usize)

Source from the content-addressed store, hash-verified

943 /// Boundaries between spans use the preceding byte; empty files use their
944 /// original root. The offset is relative to the returned span.
945 pub fn authored_anchor(&self, position: usize) -> Result<(ExternalSpan, u64)> {
946 ensure!(
947 position <= self.content.len(),
948 "rendered span anchor is out of bounds"
949 );
950 if self.content.is_empty() {
951 ensure!(
952 self.root.start <= self.root.end,
953 "invalid authored root range"
954 );
955 return Ok((self.root.clone(), 0));
956 }
957 let (range, after) = if position == 0 {
958 (0..1, false)
959 } else {
960 (position - 1..position, true)
961 };
962 let segment = self
963 .authored_ranges(range)?
964 .into_iter()
965 .next()
966 .context("authored anchor missing")?;
967 let offset = segment.target_start + u64::from(after);
968 Ok((segment.target, offset))
969 }
970
971 /// Return the exact authored ranges covering a rendered byte interval.
972 /// A line or token can cross multiple spans; each result keeps its actual

Calls 6

authored_rangesMethod · 0.80
is_emptyMethod · 0.45
cloneMethod · 0.45
contextMethod · 0.45
nextMethod · 0.45
into_iterMethod · 0.45