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

Function projection_id

atomic-core/src/pristine/span_patch_storage.rs:856–896  ·  view source on GitHub ↗
(
    file: &ExternalFile,
    domain: &[u8],
    spans: &[VisibleSpan],
)

Source from the content-addressed store, hash-verified

854}
855
856fn projection_id(
857 file: &ExternalFile,
858 domain: &[u8],
859 spans: &[VisibleSpan],
860) -> Result<SpanProjectionId> {
861 let mut normalized: Vec<(&ExternalSpan, u64, u64)> = Vec::new();
862 for span in spans {
863 let length = u64::try_from(span.output.len())?;
864 ensure!(length != 0, "empty projected authored fragment");
865 let end = span
866 .target_start
867 .checked_add(length)
868 .context("projected fragment overflow")?;
869 if let Some((target, _, previous_end)) = normalized.last_mut() {
870 if *target == &span.target && *previous_end == span.target_start {
871 *previous_end = end;
872 continue;
873 }
874 }
875 normalized.push((&span.target, span.target_start, end));
876 }
877 ensure!(
878 !normalized.is_empty(),
879 "projected semantic identity has no authored bytes"
880 );
881 let mut bytes = Vec::new();
882 bytes.extend_from_slice(b"atomic.span.semantic.projection.v1\0");
883 bytes.extend_from_slice(domain);
884 bytes.push(0);
885 bytes.extend_from_slice(file.owner.as_bytes());
886 bytes.extend_from_slice(&file.ordinal.to_be_bytes());
887 bytes.extend_from_slice(&u64::try_from(normalized.len())?.to_be_bytes());
888 for (target, start, end) in normalized {
889 bytes.extend_from_slice(target.owner.as_bytes());
890 bytes.extend_from_slice(&target.start.to_be_bytes());
891 bytes.extend_from_slice(&target.end.to_be_bytes());
892 bytes.extend_from_slice(&start.to_be_bytes());
893 bytes.extend_from_slice(&end.to_be_bytes());
894 }
895 Ok(SpanProjectionId(Hash::of(&bytes)))
896}
897
898/// One token interpreted from a span-backed file, with its exact authored
899/// byte fragments. A token may cross changes and therefore has no fabricated

Callers 2

semantic_baseline_idMethod · 0.85
semantic_linesMethod · 0.85

Calls 5

SpanProjectionIdClass · 0.85
lenMethod · 0.45
contextMethod · 0.45
pushMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected