Skip to content

Commit 260cba3

Browse files
committed
fix(link): report parent spans against parent_source, not self.source_id
#450 added `ValidationContext::parent_source` because a referenced definition's body is validated under its own source, so a parent node's range can live in a different file than `self.source_id`. The child-admissibility, child-under-leaf, and negated-required-field diagnostics still reported their parent `related_to` span against `self.source_id` — correct only because those checks are always rooted at the current node's own context (co-located), but inconsistent with `emit_field_not_on_node` and the documented convention. Thread `parent_source` through and report against it. Behavior-preserving single-file (snapshots unchanged); correct under cross-file references.
1 parent 7b7c8c1 commit 260cba3

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

  • crates/plotnik-compiler/src/analyze

‎crates/plotnik-compiler/src/analyze/link.rs‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl<'a, 'q> Linker<'a, 'q> {
434434
)
435435
.message(field_name)
436436
.related_to(
437-
self.source_id,
437+
ctx.parent_source,
438438
ctx.parent_range,
439439
format!("on `{}`", parent_name),
440440
)
@@ -582,6 +582,7 @@ impl<'a, 'q> Linker<'a, 'q> {
582582
node.text_range(),
583583
ctx.parent_id,
584584
ctx.parent_range,
585+
ctx.parent_source,
585586
);
586587
}
587588
return;
@@ -600,6 +601,7 @@ impl<'a, 'q> Linker<'a, 'q> {
600601
type_token.text_range(),
601602
ctx.parent_id,
602603
ctx.parent_range,
604+
ctx.parent_source,
603605
);
604606
return;
605607
}
@@ -611,6 +613,7 @@ impl<'a, 'q> Linker<'a, 'q> {
611613
child_id,
612614
ctx.parent_id,
613615
ctx.parent_range,
616+
ctx.parent_source,
614617
);
615618
}
616619
}
@@ -886,6 +889,7 @@ impl<'a, 'q> Linker<'a, 'q> {
886889
child_id: NodeTypeId,
887890
parent_id: NodeTypeId,
888891
parent_range: TextRange,
892+
parent_source: SourceId,
889893
) {
890894
let child_name = self
891895
.grammar
@@ -902,11 +906,7 @@ impl<'a, 'q> Linker<'a, 'q> {
902906
self.diagnostics
903907
.report(self.source_id, DiagnosticKind::InvalidChildType, range)
904908
.message(child_name)
905-
.related_to(
906-
self.source_id,
907-
parent_range,
908-
format!("on `{}`", parent_name),
909-
)
909+
.related_to(parent_source, parent_range, format!("on `{}`", parent_name))
910910
.hint(hint)
911911
.emit();
912912
}
@@ -917,6 +917,7 @@ impl<'a, 'q> Linker<'a, 'q> {
917917
range: TextRange,
918918
parent_id: NodeTypeId,
919919
parent_range: TextRange,
920+
parent_source: SourceId,
920921
) {
921922
let parent_name = self
922923
.grammar
@@ -927,7 +928,7 @@ impl<'a, 'q> Linker<'a, 'q> {
927928
self.diagnostics
928929
.report(self.source_id, DiagnosticKind::ChildUnderLeafToken, range)
929930
.message(&parent_name)
930-
.related_to(self.source_id, parent_range, format!("`{}`", parent_name))
931+
.related_to(parent_source, parent_range, format!("`{}`", parent_name))
931932
.hint(format!(
932933
"a leaf token's content is its text — match it directly `({0})` or by value `({0} == \"foo\")`",
933934
parent_name

0 commit comments

Comments
 (0)