Skip to content

Commit

Permalink
Extract comments_to_string
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Jul 25, 2024
1 parent 574795c commit f965b8c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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

0 comments on commit f965b8c

Please sign in to comment.