Skip to content

Add the missing source locations to the owned AST - #3044

Open
soutaro wants to merge 3 commits into
masterfrom
owned-ast-locations
Open

Add the missing source locations to the owned AST#3044
soutaro wants to merge 3 commits into
masterfrom
owned-ast-locations

Conversation

@soutaro

@soutaro soutaro commented Jul 29, 2026

Copy link
Copy Markdown
Member

Fills the source-location gaps in the owned AST (rust/ruby-rbs/src/ast/), so keyword parameters, record fields, and overloads can be located without keeping a side table of positions next to the AST. One commit each:

  • KeywordParam — new KeywordParamLocation: range = name: String, name_range = name
  • RecordField — new RecordFieldLocation: range = "id" => Integer, key_range = "id"
  • MethodDefinitionOverload — new LocationRange, the C overload node's range verbatim, which starts at the leading : or |

🤖 Generated with Claude Code

soutaro and others added 3 commits July 29, 2026 17:44
`KeywordParam` carried only a name and a `FunctionParam`, so the owned AST
could not answer where a keyword parameter or its key is in the source. A
consumer wanting to highlight `name:` in `(name: String) -> void` had to
keep a side table of keyword locations next to the AST.

The C AST has no single node for a keyword parameter -- it is a hash entry
pairing a key symbol with a function param node -- so `KeywordParamLocation`
spans the two: `range` runs from the start of the key to the end of the
param, and `name_range` covers the key.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`RecordField` had no location at all, so `{ name: String }` in the owned
AST could not say where the field or its key sits in the source.

As with keyword parameters, the C AST spreads a record field over a key
node and a field type node, so `RecordFieldLocation` spans the two: `range`
runs from the start of the key to the end of the field, and `key_range`
covers the key.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`MethodDefinitionOverload` had no location, so a method definition with
several overloads could not say which source range each overload occupies
without reaching into its `MethodType`.

The C AST does have an overload node, so this is its range verbatim. Note
that the range starts at the `:` or `|` separator preceding the overload,
which is worth knowing before slicing the source with it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant