Skip to content

Fix Ruby indexer keyword parameter offset to exclude trailing colon#706

Merged
soutaro merged 1 commit intomainfrom
soutaro/fix-keyword-param-offset
Mar 30, 2026
Merged

Fix Ruby indexer keyword parameter offset to exclude trailing colon#706
soutaro merged 1 commit intomainfrom
soutaro/fix-keyword-param-offset

Conversation

@soutaro
Copy link
Copy Markdown
Contributor

@soutaro soutaro commented Mar 27, 2026

Summary

  • Fix keyword parameter offsets in Ruby indexer to exclude the trailing colon (e.g. offset covers name instead of name:)
  • Add Offset::shrink_end helper with invariant checking
  • Add RubyIndexer::offset_to_string to derive parameter name from the adjusted offset

Addresses feedback from #694 — Vini pointed out the Ruby indexer was incorrectly including the colon, and the RBS indexer had it right.

Test plan

  • Updated existing index_def_node_with_parameters test to assert keyword parameter offsets point to the identifier without the colon
  • All 480 lib tests pass

🤖 Generated with Claude Code

@soutaro soutaro requested a review from a team as a code owner March 27, 2026 06:20
@soutaro soutaro self-assigned this Mar 27, 2026
/// # Panics
///
/// Panics if shrinking would make `end` less than `start`.
pub fn shrink_end(&mut self, bytes: u32) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for not allowing the offsets to be mutated and instead doing this inline:

let loc = required.name_loc();
let offset = Offset::new(loc.start_offset(), loc.end_offset() - 1);

@vinistock vinistock added the bugfix A change that fixes an existing bug label Mar 27, 2026
Prism's name_loc for keyword parameters includes the trailing colon
(e.g. "name:"), but the offset should only cover the identifier. This
aligns Ruby indexer behavior with the RBS indexer, which already
excludes the colon.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@soutaro soutaro force-pushed the soutaro/fix-keyword-param-offset branch from 6359bdd to ede6d74 Compare March 30, 2026 00:55
@soutaro soutaro enabled auto-merge March 30, 2026 00:56
@soutaro soutaro merged commit 3228302 into main Mar 30, 2026
31 checks passed
@soutaro soutaro deleted the soutaro/fix-keyword-param-offset branch March 30, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix A change that fixes an existing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants