Skip to content

Expose the location range of a constant's assigned value #844

Description

@alexcrocha

A constant definition's location spans only the constant's name, not its
assigned value. For a multi-line literal there is no way to know where the
value ends without re-reading and parsing the source.

VALUES = [
  "a",
  "b",
]

graph["VALUES"].definitions.first.location covers the VALUES token only;
the array value's location is unavailable.

Why it matters

A consumer that reads a constant's value from source (for example, to compare a
checked-in list against the graph and point diagnostics at entries) must
re-open the file and scan for the closing delimiter. That breaks across literal
forms ([ ... ], %w( ... ), %i[ ... ], { ... }, method calls) and
formatting, and every consumer reimplements it.

Proposed

Add a #value_location (a Location) on constant definitions that covers the
assigned value. For VALUES above it would span lines 1 through 4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions