Skip to content

RDoc: Add support for generics in RDoc #1105

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 15 additions & 2 deletions lib/rdoc_plugin/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,27 @@ def parse_member(decl:, context:, outer_name: nil)

def parse_class_decl(decl:, context:, outer_name: nil)
full_name = fully_qualified_name(outer_name: outer_name, decl: decl)
klass = context.add_class(RDoc::NormalClass, full_name.to_s, decl.super_class&.name&.to_s || "::Object")
klass = context.add_class(RDoc::NormalClass, full_name.to_s, decl.super_class&.name&.to_s || "::Object",
decl.type_params.map do |type_param|
RDoc::TypeParameter.new(type_param.name.to_s,
type_param.variance,
type_param.unchecked?,
type_param.upper_bound&.name&.to_s)
end
)
klass.add_comment(construct_comment(context: context, comment: comment_string(decl)), context) if decl.comment
decl.members.each { |member| parse_member(decl: member, context: context, outer_name: full_name) }
end

def parse_module_decl(decl:, context:, outer_name: nil)
full_name = fully_qualified_name(outer_name: outer_name, decl: _ = decl)
kmodule = context.add_module(RDoc::NormalModule, full_name.to_s)
kmodule = context.add_module(RDoc::NormalModule, full_name.to_s,
decl.type_params.map do |type_param|
RDoc::TypeParameter.new(type_param.name.to_s,
type_param.variance,
type_param.unchecked?,
type_param.upper_bound&.name&.to_s)
end)
kmodule.add_comment(construct_comment(context: context, comment: comment_string(decl)), context) if decl.comment
decl.members.each { |member| parse_member(decl: member, context: context, outer_name: full_name) }
end
Expand Down
23 changes: 21 additions & 2 deletions stdlib/rdoc/0/rdoc.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ module RDoc
# later sees `class Container`. `add_class` automatically upgrades `given_name`
# to a class in this case.
#
def add_class: (class_types class_type, ::String given_name, ?::String superclass) -> (RDoc::NormalClass | RDoc::SingleClass)
def add_class: (class_types class_type, ::String given_name, ?::String superclass, ?Array[RDoc::TypeParameter]) -> (RDoc::NormalClass | RDoc::SingleClass)

# <!--
# rdoc-file=lib/rdoc/context.rb
Expand Down Expand Up @@ -271,7 +271,7 @@ module RDoc
# Adds a module named `name`. If RDoc already knows `name` is a class then that
# class is returned instead. See also #add_class.
#
def add_module: (singleton(RDoc::NormalModule) class_type, String name) -> RDoc::NormalModule
def add_module: (singleton(RDoc::NormalModule) class_type, String name, ?Array[RDoc::TypeParameter]) -> RDoc::NormalModule

# <!--
# rdoc-file=lib/rdoc/context.rb
Expand Down Expand Up @@ -749,6 +749,25 @@ module RDoc
def initialize: (String? text, String name, String old_name, RDoc::Comment? comment, ?bool `singleton`) -> void
end

class TypeParameter < CodeObject
type variance = :invariant | :covariant | :contravariant

attr_reader name: String
attr_reader variance: variance
attr_reader upper_bound: String?
attr_reader `unchecked`: bool

def initialize: (String name, Symbol variance, ?bool `unchecked`, ?String? upper_bound) -> void

def ==: (untyped other) -> bool

alias eql? ==

def unchecked?: () -> bool

def to_s: () -> String
end

# <!-- rdoc-file=lib/rdoc/stats.rb -->
# RDoc statistics collector which prints a summary and report of a project's
# documentation totals.
Expand Down