Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions rust/rubydex/src/indexing/rbs_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,16 @@ impl<'a> RBSIndexer<'a> {

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

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

assert_parameter!(&def.signatures().as_slice()[0][4], RequiredKeyword, |param| {
assert_string_eq!(context, param.str(), "name");
assert_offset_string!(context, param.offset(), "name");
assert_offset_string!(context, param.offset(), "name:");
});

assert_parameter!(&def.signatures().as_slice()[0][5], OptionalKeyword, |param| {
assert_string_eq!(context, param.str(), "age");
assert_offset_string!(context, param.offset(), "age");
assert_offset_string!(context, param.offset(), "age:");
});

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

assert_parameter!(&def.signatures().as_slice()[0][4], RequiredKeyword, |param| {
assert_string_eq!(context, param.str(), "name");
assert_offset_string!(context, param.offset(), "name");
assert_offset_string!(context, param.offset(), "name:");
});

assert_parameter!(&def.signatures().as_slice()[0][5], OptionalKeyword, |param| {
assert_string_eq!(context, param.str(), "age");
assert_offset_string!(context, param.offset(), "age");
assert_offset_string!(context, param.offset(), "age:");
});

assert_parameter!(&def.signatures().as_slice()[0][6], RestKeyword, |param| {
Expand Down
9 changes: 9 additions & 0 deletions rust/rubydex/src/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ impl Offset {
self.end
}

/// Returns a new offset with the end extended by the given number of bytes.
#[must_use]
pub const fn extend_end(self, bytes: u32) -> Self {
Self {
start: self.start,
end: self.end + bytes,
}
}

/// Converts an offset to a display range like `1:1-1:5`
#[must_use]
pub fn to_display_range(&self, document: &Document) -> String {
Expand Down
Loading