Skip to content

[Compiler] Support related/secondary spans in conflict diagnostics #297

@cssbruno

Description

@cssbruno

Problem

Diagnostics carry exactly one span. Diagnostic and ValidationError both have
a single Span/Pos, so conflict diagnostics — duplicate routes, contract
route conflicts, duplicate endpoints — can only point at one location. They
cannot say "first declared here, also declared here," which is exactly the
information a user needs to resolve a conflict.

This is timely: recent M2 work hardened contract-route conflict validation, and
those messages would be materially clearer with a related location.

Relevant code:

  • internal/lang/diagnostic.go: Diagnostic (single Pos/Range)
  • internal/compiler/validate.go: ValidationError (single Span)
  • internal/compiler/routes.go, route_bindings.go, validate_contract_refs.go:
    route / endpoint / contract conflict validators

Scope

Add a related-locations field (e.g. Related []source.NamedSpan) to the
diagnostic contract, thread the first-declaration span through the conflict
validators, and surface related locations in check --json and LSP
relatedInformation.

Acceptance Criteria

  • Conflict diagnostics include the primary span plus at least one related span
    pointing at the other declaration.
  • check --json adds related locations additively; existing shape stays
    backward compatible.
  • LSP maps related locations to relatedInformation.
  • Tests cover duplicate routes and contract route conflicts with two locations.

Verification

go test ./internal/compiler ./internal/lang ./internal/lsp

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerCompiler internals, pipeline, and generated metadatadiagnosticsDiagnostic codes, spans, and messages

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions