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

Method authored_anchor

atomic-core/src/pristine/span_patch_storage.rs:1126–1150  ·  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

1124 /// Boundaries between spans use the preceding byte; empty files use their
1125 /// original root. The offset is relative to the returned span.
1126 pub fn authored_anchor(&self, position: usize) -> Result<(ExternalSpan, u64)> {
1127 ensure!(
1128 position <= self.content.len(),
1129 "rendered span anchor is out of bounds"
1130 );
1131 if self.content.is_empty() {
1132 ensure!(
1133 self.root.start <= self.root.end,
1134 "invalid authored root range"
1135 );
1136 return Ok((self.root.clone(), 0));
1137 }
1138 let (range, after) = if position == 0 {
1139 (0..1, false)
1140 } else {
1141 (position - 1..position, true)
1142 };
1143 let segment = self
1144 .authored_ranges(range)?
1145 .into_iter()
1146 .next()
1147 .context("authored anchor missing")?;
1148 let offset = segment.target_start + u64::from(after);
1149 Ok((segment.target, offset))
1150 }
1151
1152 /// Return the exact authored ranges covering a rendered byte interval.
1153 /// 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