Skip to content

Commit 9306948

Browse files
soutaroclaude
andcommitted
Include trailing colon in RBS keyword parameter offset
Align RBS keyword parameter offsets with Ruby indexer behavior. The RBS indexer now includes the trailing colon in the offset for required and optional keyword parameters (e.g. `name:` instead of `name`). Adds `Offset::extend_end` helper to adjust byte ranges. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3dba913 commit 9306948

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

rust/rubydex/src/indexing/rbs_indexer.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,16 @@ impl<'a> RBSIndexer<'a> {
271271

272272
for (key, _value) in function_node.required_keywords().iter() {
273273
let name = self.source_at(&key.location());
274-
let offset = Offset::from_rbs_location(&key.location());
274+
// Extend offset by 1 to include the trailing colon, matching Ruby indexer behavior
275+
let offset = Offset::from_rbs_location(&key.location()).extend_end(1);
275276
let str_id = self.local_graph.intern_string(name);
276277
parameters.push(Parameter::RequiredKeyword(ParameterStruct::new(offset, str_id)));
277278
}
278279

279280
for (key, _value) in function_node.optional_keywords().iter() {
280281
let name = self.source_at(&key.location());
281-
let offset = Offset::from_rbs_location(&key.location());
282+
// Extend offset by 1 to include the trailing colon, matching Ruby indexer behavior
283+
let offset = Offset::from_rbs_location(&key.location()).extend_end(1);
282284
let str_id = self.local_graph.intern_string(name);
283285
parameters.push(Parameter::OptionalKeyword(ParameterStruct::new(offset, str_id)));
284286
}
@@ -1257,12 +1259,12 @@ mod tests {
12571259

12581260
assert_parameter!(&def.signatures().as_slice()[0][4], RequiredKeyword, |param| {
12591261
assert_string_eq!(context, param.str(), "name");
1260-
assert_offset_string!(context, param.offset(), "name");
1262+
assert_offset_string!(context, param.offset(), "name:");
12611263
});
12621264

12631265
assert_parameter!(&def.signatures().as_slice()[0][5], OptionalKeyword, |param| {
12641266
assert_string_eq!(context, param.str(), "age");
1265-
assert_offset_string!(context, param.offset(), "age");
1267+
assert_offset_string!(context, param.offset(), "age:");
12661268
});
12671269

12681270
assert_parameter!(&def.signatures().as_slice()[0][6], RestKeyword, |param| {
@@ -1298,12 +1300,12 @@ mod tests {
12981300

12991301
assert_parameter!(&def.signatures().as_slice()[0][4], RequiredKeyword, |param| {
13001302
assert_string_eq!(context, param.str(), "name");
1301-
assert_offset_string!(context, param.offset(), "name");
1303+
assert_offset_string!(context, param.offset(), "name:");
13021304
});
13031305

13041306
assert_parameter!(&def.signatures().as_slice()[0][5], OptionalKeyword, |param| {
13051307
assert_string_eq!(context, param.str(), "age");
1306-
assert_offset_string!(context, param.offset(), "age");
1308+
assert_offset_string!(context, param.offset(), "age:");
13071309
});
13081310

13091311
assert_parameter!(&def.signatures().as_slice()[0][6], RestKeyword, |param| {

rust/rubydex/src/offset.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ impl Offset {
7474
self.end
7575
}
7676

77+
/// Returns a new offset with the end extended by the given number of bytes.
78+
#[must_use]
79+
pub const fn extend_end(self, bytes: u32) -> Self {
80+
Self {
81+
start: self.start,
82+
end: self.end + bytes,
83+
}
84+
}
85+
7786
/// Converts an offset to a display range like `1:1-1:5`
7887
#[must_use]
7988
pub fn to_display_range(&self, document: &Document) -> String {

0 commit comments

Comments
 (0)