Skip to content

Commit ede6d74

Browse files
soutaroclaude
andcommitted
Fix Ruby indexer keyword parameter offset to exclude trailing colon
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>
1 parent fbad98c commit ede6d74

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

rust/rubydex/src/indexing/ruby_indexer.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ impl<'a> RubyIndexer<'a> {
160160
String::from_utf8_lossy(location.as_slice()).to_string()
161161
}
162162

163+
fn offset_to_string(&self, offset: &Offset) -> String {
164+
self.source[offset.start() as usize..offset.end() as usize].to_string()
165+
}
166+
163167
fn find_comments_for(&self, offset: u32) -> (Box<[Comment]>, DefinitionFlags) {
164168
let offset_usize = offset as usize;
165169
if self.comments.is_empty() {
@@ -257,27 +261,21 @@ impl<'a> RubyIndexer<'a> {
257261
match keyword {
258262
ruby_prism::Node::RequiredKeywordParameterNode { .. } => {
259263
let required = keyword.as_required_keyword_parameter_node().unwrap();
260-
let name_loc = required.name_loc();
261-
let str_id = self
262-
.local_graph
263-
.intern_string(Self::location_to_string(&name_loc).trim_end_matches(':').to_string());
264+
let loc = required.name_loc();
265+
let full = Offset::from_prism_location(&loc);
266+
let offset = Offset::new(full.start(), full.end() - 1); // Exclude trailing colon
267+
let str_id = self.local_graph.intern_string(self.offset_to_string(&offset));
264268

265-
parameters.push(Parameter::RequiredKeyword(ParameterStruct::new(
266-
Offset::from_prism_location(&name_loc),
267-
str_id,
268-
)));
269+
parameters.push(Parameter::RequiredKeyword(ParameterStruct::new(offset, str_id)));
269270
}
270271
ruby_prism::Node::OptionalKeywordParameterNode { .. } => {
271272
let optional = keyword.as_optional_keyword_parameter_node().unwrap();
272-
let name_loc = optional.name_loc();
273-
let str_id = self
274-
.local_graph
275-
.intern_string(Self::location_to_string(&name_loc).trim_end_matches(':').to_string());
273+
let loc = optional.name_loc();
274+
let full = Offset::from_prism_location(&loc);
275+
let offset = Offset::new(full.start(), full.end() - 1); // Exclude trailing colon
276+
let str_id = self.local_graph.intern_string(self.offset_to_string(&offset));
276277

277-
parameters.push(Parameter::OptionalKeyword(ParameterStruct::new(
278-
Offset::from_prism_location(&name_loc),
279-
str_id,
280-
)));
278+
parameters.push(Parameter::OptionalKeyword(ParameterStruct::new(offset, str_id)));
281279
}
282280
_ => {}
283281
}
@@ -3166,10 +3164,12 @@ mod tests {
31663164

31673165
assert_parameter!(&params[4], RequiredKeyword, |param| {
31683166
assert_string_eq!(context, param.str(), "e");
3167+
assert_eq!(context.source_at(param.offset()), "e");
31693168
});
31703169

31713170
assert_parameter!(&params[5], OptionalKeyword, |param| {
31723171
assert_string_eq!(context, param.str(), "g");
3172+
assert_eq!(context.source_at(param.offset()), "g");
31733173
});
31743174

31753175
assert_parameter!(&params[6], RestKeyword, |param| {

0 commit comments

Comments
 (0)