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

Fix annotate-with-rdoc print constant docs #768

Merged
merged 1 commit into from
Aug 28, 2021
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
18 changes: 11 additions & 7 deletions bin/annotate-with-rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ def resolve_name(name, outer:)
end

def comment_for_constant(const_name, stores:)
klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
store.find_class_named(class_name) || store.find_module_named(class_name)
class_name =
if (ns = const_name.namespace).empty?
TypeName("::Object")
else
ns.to_type_name
end

klass = store_for_class(class_name.relative!.to_s, stores: stores)&.yield_self {|store|
store.find_class_named(class_name.relative!.to_s) || store.find_module_named(class_name.relative!.to_s)
}

if klass
Expand Down Expand Up @@ -128,7 +135,7 @@ def annotate_declaration(decl:, outer:, stores:)
case decl
when RBS::AST::Declarations::Constant
puts " Importing documentation for #{decl.name}..."
const_name = resolve_name(decl, outer: outer)
const_name = resolve_name(decl.name, outer: outer)
comment = comment_for_constant(const_name, stores: stores)
decl.instance_variable_set(:@comment, comment)
when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module
Expand All @@ -142,10 +149,7 @@ def annotate_declaration(decl:, outer:, stores:)

outer_ = outer + [decl.name.to_namespace]
decl.members.each do |member|
case member
when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module
annotate_declaration(decl: member, outer: outer_, stores: stores)
end
annotate_declaration(decl: member, outer: outer_, stores: stores)
end
end
end
Expand Down