MCPcopy Create free account
hub / github.com/hashintel/hash / absolute_impl

Method absolute_impl

libs/@local/hashql/core/src/span/table.rs:332–369  ·  view source on GitHub ↗
(&self, span: SpanId, depth: usize)

Source from the content-addressed store, hash-verified

330 }
331
332 fn absolute_impl(&self, span: SpanId, depth: usize) -> Option<SourceSpan>
333 where
334 S: Span,
335 {
336 assert!(
337 depth <= Self::MAX_SPAN_DEPTH,
338 "Cannot resolve excessively deep span of {depth}, likely due to a circular dependency"
339 );
340
341 // Special case synthetic spans, which have no source location
342 if span == SpanId::SYNTHETIC {
343 return Some(SourceSpan::from_parts(
344 self.source_id,
345 TextRange::empty(TextSize::new(0)),
346 ));
347 }
348
349 let entry = self.get_entry(span)?;
350 let ancestors = &self.ancestors[entry.ancestors.clone()];
351
352 let (base, rest) = match ancestors {
353 [] => return Some(SourceSpan::from_parts(span.source_id(), entry.span.range())),
354 [base, rest @ ..] => (*base, rest),
355 };
356
357 let mut base = self.absolute_impl(base, depth + 1)?.range();
358 for &ancestor in rest {
359 let ancestor = self.absolute_impl(ancestor, depth + 1)?.range();
360
361 base = match entry.mode {
362 SpanResolutionMode::Intersection => base.intersect(ancestor)?,
363 SpanResolutionMode::Union => base.cover(ancestor),
364 };
365 }
366
367 let range = entry.span.range() + base.start();
368 Some(SourceSpan::from_parts(span.source_id(), range))
369 }
370
371 /// Resolves a span to its absolute source position.
372 ///

Callers 1

absoluteMethod · 0.80

Calls 8

source_idMethod · 0.80
coverMethod · 0.80
startMethod · 0.65
emptyFunction · 0.50
get_entryMethod · 0.45
cloneMethod · 0.45
rangeMethod · 0.45
intersectMethod · 0.45

Tested by

no test coverage detected