From f965b8c4f9b7a6a937816880d8091095ad7dbdda Mon Sep 17 00:00:00 2001 From: Andy Waite <13400+andyw8@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:33:05 -0400 Subject: [PATCH] Extract `comments_to_string` --- .../lib/ruby_indexer/rbs_indexer.rb | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb b/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb index 57f6c2da8..0c39dd414 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb @@ -54,7 +54,7 @@ def handle_class_or_module_declaration(declaration, pathname) nesting = [declaration.name.name.to_s] file_path = pathname.to_s location = to_ruby_indexer_location(declaration.location) - comments = Array(declaration.comment&.string) + comments = comments_to_string(declaration) entry = if declaration.is_a?(RBS::AST::Declarations::Class) parent_class = declaration.super_class&.name&.name&.to_s Entry::Class.new(nesting, file_path, location, location, comments, parent_class) @@ -111,7 +111,7 @@ def handle_method(member, owner) name = member.name.name file_path = member.location.buffer.name location = to_ruby_indexer_location(member.location) - comments = Array(member.comment&.string) + comments = comments_to_string(member) visibility = case member.visibility when :private @@ -242,14 +242,14 @@ def handle_constant(declaration, nesting, file_path) fully_qualified_name, file_path, to_ruby_indexer_location(declaration.location), - Array(declaration.comment&.string), + comments_to_string(declaration), )) end sig { params(member: RBS::AST::Members::Alias, owner_entry: Entry::Namespace).void } def handle_signature_alias(member, owner_entry) file_path = member.location.buffer.name - comments = Array(member.comment&.string) + comments = comments_to_string(member) entry = Entry::UnresolvedMethodAlias.new( member.new_name.to_s, @@ -262,5 +262,18 @@ def handle_signature_alias(member, owner_entry) @index.add(entry) end + + sig do + params(declaration: T.any( + RBS::AST::Declarations::Class, + RBS::AST::Declarations::Module, + RBS::AST::Declarations::Constant, + RBS::AST::Members::MethodDefinition, + RBS::AST::Members::Alias, + )).returns(T::Array[String]) + end + def comments_to_string(declaration) + Array(declaration.comment&.string) + end end end