Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify class and module handling for RBS #2336

Merged
merged 1 commit into from
Jul 22, 2024
Merged
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
40 changes: 14 additions & 26 deletions lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,33 @@ def process_signature(pathname, declarations)
sig { params(declaration: RBS::AST::Declarations::Base, pathname: Pathname).void }
def process_declaration(declaration, pathname)
case declaration
when RBS::AST::Declarations::Class
handle_class_declaration(declaration, pathname)
when RBS::AST::Declarations::Module
handle_module_declaration(declaration, pathname)
when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module
vinistock marked this conversation as resolved.
Show resolved Hide resolved
handle_class_or_module_declaration(declaration, pathname)
else # rubocop:disable Style/EmptyElse
# Other kinds not yet handled
end
end

sig { params(declaration: RBS::AST::Declarations::Class, pathname: Pathname).void }
def handle_class_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)
parent_class = declaration.super_class&.name&.name&.to_s
class_entry = Entry::Class.new(nesting, file_path, location, location, comments, parent_class)
add_declaration_mixins_to_entry(declaration, class_entry)
@index.add(class_entry)
declaration.members.each do |member|
next unless member.is_a?(RBS::AST::Members::MethodDefinition)

handle_method(member, class_entry)
end
sig do
params(declaration: T.any(RBS::AST::Declarations::Class, RBS::AST::Declarations::Module), pathname: Pathname).void
end

sig { params(declaration: RBS::AST::Declarations::Module, pathname: Pathname).void }
def handle_module_declaration(declaration, pathname)
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)
module_entry = Entry::Module.new(nesting, file_path, location, location, comments)
add_declaration_mixins_to_entry(declaration, module_entry)
@index.add(module_entry)
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)
else
Entry::Module.new(nesting, file_path, location, location, comments)
end
add_declaration_mixins_to_entry(declaration, entry)
@index.add(entry)
declaration.members.each do |member|
next unless member.is_a?(RBS::AST::Members::MethodDefinition)

handle_method(member, module_entry)
handle_method(member, entry)
end
end

Expand Down
Loading