rdoc 6.11.0 → 6.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rdoc/code_object/alias.rb +2 -9
  3. data/lib/rdoc/code_object/any_method.rb +7 -12
  4. data/lib/rdoc/code_object/attr.rb +4 -7
  5. data/lib/rdoc/code_object/class_module.rb +37 -19
  6. data/lib/rdoc/code_object/constant.rb +1 -1
  7. data/lib/rdoc/code_object/context/section.rb +10 -68
  8. data/lib/rdoc/code_object/context.rb +4 -46
  9. data/lib/rdoc/code_object/method_attr.rb +2 -22
  10. data/lib/rdoc/code_object/require.rb +1 -1
  11. data/lib/rdoc/code_object/top_level.rb +4 -24
  12. data/lib/rdoc/code_object.rb +3 -35
  13. data/lib/rdoc/comment.rb +12 -5
  14. data/lib/rdoc/generator/darkfish.rb +92 -108
  15. data/lib/rdoc/generator/json_index.rb +1 -17
  16. data/lib/rdoc/generator/markup.rb +2 -2
  17. data/lib/rdoc/generator/pot/message_extractor.rb +2 -2
  18. data/lib/rdoc/generator/pot.rb +0 -5
  19. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +1 -30
  20. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +1 -1
  21. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +1 -1
  22. data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -0
  23. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +13 -0
  24. data/lib/rdoc/generator/template/darkfish/index.rhtml +4 -4
  25. data/lib/rdoc/markdown.kpeg +7 -5
  26. data/lib/rdoc/markdown.rb +34 -21
  27. data/lib/rdoc/markup/heading.rb +7 -1
  28. data/lib/rdoc/markup/to_html.rb +6 -1
  29. data/lib/rdoc/parser/c.rb +5 -8
  30. data/lib/rdoc/parser/changelog.rb +3 -2
  31. data/lib/rdoc/parser/prism_ruby.rb +109 -45
  32. data/lib/rdoc/parser/ruby.rb +8 -11
  33. data/lib/rdoc/parser/simple.rb +1 -1
  34. data/lib/rdoc/parser.rb +3 -3
  35. data/lib/rdoc/rdoc.rb +3 -18
  36. data/lib/rdoc/ri/driver.rb +28 -19
  37. data/lib/rdoc/rubygems_hook.rb +1 -7
  38. data/lib/rdoc/servlet.rb +8 -7
  39. data/lib/rdoc/stats.rb +2 -2
  40. data/lib/rdoc/store.rb +9 -13
  41. data/lib/rdoc/text.rb +2 -2
  42. data/lib/rdoc/version.rb +1 -1
  43. metadata +2 -4
  44. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +0 -19
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +0 -9
data/lib/rdoc/markdown.rb CHANGED
@@ -10978,7 +10978,7 @@ class RDoc::Markdown
10978
10978
  return _tmp
10979
10979
  end
10980
10980
 
10981
- # Image = "!" (ExplicitLink | ReferenceLink):a { "rdoc-image:#{a[/\[(.*)\]/, 1]}" }
10981
+ # Image = "!" ExplicitLinkWithLabel:a { "rdoc-image:#{a[:link]}:#{a[:label]}" }
10982
10982
  def _Image
10983
10983
 
10984
10984
  _save = self.pos
@@ -10988,24 +10988,13 @@ class RDoc::Markdown
10988
10988
  self.pos = _save
10989
10989
  break
10990
10990
  end
10991
-
10992
- _save1 = self.pos
10993
- while true # choice
10994
- _tmp = apply(:_ExplicitLink)
10995
- break if _tmp
10996
- self.pos = _save1
10997
- _tmp = apply(:_ReferenceLink)
10998
- break if _tmp
10999
- self.pos = _save1
11000
- break
11001
- end # end choice
11002
-
10991
+ _tmp = apply(:_ExplicitLinkWithLabel)
11003
10992
  a = @result
11004
10993
  unless _tmp
11005
10994
  self.pos = _save
11006
10995
  break
11007
10996
  end
11008
- @result = begin; "rdoc-image:#{a[/\[(.*)\]/, 1]}" ; end
10997
+ @result = begin; "rdoc-image:#{a[:link]}:#{a[:label]}" ; end
11009
10998
  _tmp = true
11010
10999
  unless _tmp
11011
11000
  self.pos = _save
@@ -11153,13 +11142,36 @@ class RDoc::Markdown
11153
11142
  return _tmp
11154
11143
  end
11155
11144
 
11156
- # ExplicitLink = Label:l "(" @Sp Source:s Spnl Title @Sp ")" { "{#{l}}[#{s}]" }
11145
+ # ExplicitLink = ExplicitLinkWithLabel:a { "{#{a[:label]}}[#{a[:link]}]" }
11157
11146
  def _ExplicitLink
11158
11147
 
11148
+ _save = self.pos
11149
+ while true # sequence
11150
+ _tmp = apply(:_ExplicitLinkWithLabel)
11151
+ a = @result
11152
+ unless _tmp
11153
+ self.pos = _save
11154
+ break
11155
+ end
11156
+ @result = begin; "{#{a[:label]}}[#{a[:link]}]" ; end
11157
+ _tmp = true
11158
+ unless _tmp
11159
+ self.pos = _save
11160
+ end
11161
+ break
11162
+ end # end sequence
11163
+
11164
+ set_failed_rule :_ExplicitLink unless _tmp
11165
+ return _tmp
11166
+ end
11167
+
11168
+ # ExplicitLinkWithLabel = Label:label "(" @Sp Source:link Spnl Title @Sp ")" { { label: label, link: link } }
11169
+ def _ExplicitLinkWithLabel
11170
+
11159
11171
  _save = self.pos
11160
11172
  while true # sequence
11161
11173
  _tmp = apply(:_Label)
11162
- l = @result
11174
+ label = @result
11163
11175
  unless _tmp
11164
11176
  self.pos = _save
11165
11177
  break
@@ -11175,7 +11187,7 @@ class RDoc::Markdown
11175
11187
  break
11176
11188
  end
11177
11189
  _tmp = apply(:_Source)
11178
- s = @result
11190
+ link = @result
11179
11191
  unless _tmp
11180
11192
  self.pos = _save
11181
11193
  break
@@ -11200,7 +11212,7 @@ class RDoc::Markdown
11200
11212
  self.pos = _save
11201
11213
  break
11202
11214
  end
11203
- @result = begin; "{#{l}}[#{s}]" ; end
11215
+ @result = begin; { label: label, link: link } ; end
11204
11216
  _tmp = true
11205
11217
  unless _tmp
11206
11218
  self.pos = _save
@@ -11208,7 +11220,7 @@ class RDoc::Markdown
11208
11220
  break
11209
11221
  end # end sequence
11210
11222
 
11211
- set_failed_rule :_ExplicitLink unless _tmp
11223
+ set_failed_rule :_ExplicitLinkWithLabel unless _tmp
11212
11224
  return _tmp
11213
11225
  end
11214
11226
 
@@ -16711,12 +16723,13 @@ class RDoc::Markdown
16711
16723
  Rules[:_StrongStar] = rule_info("StrongStar", "\"**\" !@Whitespace @StartList:a (!\"**\" Inline:b { a << b })+ \"**\" { strong a.join }")
16712
16724
  Rules[:_StrongUl] = rule_info("StrongUl", "\"__\" !@Whitespace @StartList:a (!\"__\" Inline:b { a << b })+ \"__\" { strong a.join }")
16713
16725
  Rules[:_Strike] = rule_info("Strike", "&{ strike? } \"~~\" !@Whitespace @StartList:a (!\"~~\" Inline:b { a << b })+ \"~~\" { strike a.join }")
16714
- Rules[:_Image] = rule_info("Image", "\"!\" (ExplicitLink | ReferenceLink):a { \"rdoc-image:\#{a[/\\[(.*)\\]/, 1]}\" }")
16726
+ Rules[:_Image] = rule_info("Image", "\"!\" ExplicitLinkWithLabel:a { \"rdoc-image:\#{a[:link]}:\#{a[:label]}\" }")
16715
16727
  Rules[:_Link] = rule_info("Link", "(ExplicitLink | ReferenceLink | AutoLink)")
16716
16728
  Rules[:_ReferenceLink] = rule_info("ReferenceLink", "(ReferenceLinkDouble | ReferenceLinkSingle)")
16717
16729
  Rules[:_ReferenceLinkDouble] = rule_info("ReferenceLinkDouble", "Label:content < Spnl > !\"[]\" Label:label { link_to content, label, text }")
16718
16730
  Rules[:_ReferenceLinkSingle] = rule_info("ReferenceLinkSingle", "Label:content < (Spnl \"[]\")? > { link_to content, content, text }")
16719
- Rules[:_ExplicitLink] = rule_info("ExplicitLink", "Label:l \"(\" @Sp Source:s Spnl Title @Sp \")\" { \"{\#{l}}[\#{s}]\" }")
16731
+ Rules[:_ExplicitLink] = rule_info("ExplicitLink", "ExplicitLinkWithLabel:a { \"{\#{a[:label]}}[\#{a[:link]}]\" }")
16732
+ Rules[:_ExplicitLinkWithLabel] = rule_info("ExplicitLinkWithLabel", "Label:label \"(\" @Sp Source:link Spnl Title @Sp \")\" { { label: label, link: link } }")
16720
16733
  Rules[:_Source] = rule_info("Source", "(\"<\" < SourceContents > \">\" | < SourceContents >) { text }")
16721
16734
  Rules[:_SourceContents] = rule_info("SourceContents", "((!\"(\" !\")\" !\">\" Nonspacechar)+ | \"(\" SourceContents \")\")*")
16722
16735
  Rules[:_Title] = rule_info("Title", "(TitleSingle | TitleDouble | \"\"):a { a }")
@@ -66,7 +66,13 @@ RDoc::Markup::Heading =
66
66
  # element.
67
67
 
68
68
  def plain_html
69
- self.class.to_html.to_html(text.dup)
69
+ text = self.text.dup
70
+
71
+ if matched = text.match(/rdoc-image:[^:]+:(.*)/)
72
+ text = matched[1]
73
+ end
74
+
75
+ self.class.to_html.to_html(text)
70
76
  end
71
77
 
72
78
  def pretty_print q # :nodoc:
@@ -98,7 +98,12 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
98
98
 
99
99
  gen_url CGI.escapeHTML(url), CGI.escapeHTML(text)
100
100
  when /^rdoc-image:/
101
- %[<img src=\"#{CGI.escapeHTML($')}\">]
101
+ url, alt = $'.split(":", 2) # Split the string after "rdoc-image:" into url and alt
102
+ if alt && !alt.empty?
103
+ %[<img src="#{CGI.escapeHTML(url)}" alt="#{CGI.escapeHTML(alt)}">]
104
+ else
105
+ %[<img src="#{CGI.escapeHTML(url)}">]
106
+ end
102
107
  when /\Ardoc-[a-z]+:/
103
108
  CGI.escapeHTML($')
104
109
  end
data/lib/rdoc/parser/c.rb CHANGED
@@ -168,7 +168,7 @@ class RDoc::Parser::C < RDoc::Parser
168
168
  # Prepares for parsing a C file. See RDoc::Parser#initialize for details on
169
169
  # the arguments.
170
170
 
171
- def initialize top_level, file_name, content, options, stats
171
+ def initialize top_level, content, options, stats
172
172
  super
173
173
 
174
174
  @known_classes = RDoc::KNOWN_CLASSES.dup
@@ -248,9 +248,7 @@ class RDoc::Parser::C < RDoc::Parser
248
248
  # method that reference the same function.
249
249
 
250
250
  def add_alias(var_name, class_obj, old_name, new_name, comment)
251
- al = RDoc::Alias.new '', old_name, new_name, ''
252
- al.singleton = @singleton_classes.key? var_name
253
- al.comment = comment
251
+ al = RDoc::Alias.new '', old_name, new_name, comment, singleton: @singleton_classes.key?(var_name)
254
252
  al.record_location @top_level
255
253
  class_obj.add_alias al
256
254
  @stats.add_alias al
@@ -810,7 +808,7 @@ class RDoc::Parser::C < RDoc::Parser
810
808
 
811
809
  def find_modifiers comment, meth_obj
812
810
  comment.normalize
813
- comment.extract_call_seq meth_obj
811
+ meth_obj.call_seq = comment.extract_call_seq
814
812
 
815
813
  look_for_directives_in meth_obj, comment
816
814
  end
@@ -1015,10 +1013,9 @@ class RDoc::Parser::C < RDoc::Parser
1015
1013
  type = 'method' # force public
1016
1014
  end
1017
1015
 
1018
- meth_obj = RDoc::AnyMethod.new '', meth_name
1016
+ singleton = singleton || %w[singleton_method module_function].include?(type)
1017
+ meth_obj = RDoc::AnyMethod.new '', meth_name, singleton: singleton
1019
1018
  meth_obj.c_function = function
1020
- meth_obj.singleton =
1021
- singleton || %w[singleton_method module_function].include?(type)
1022
1019
 
1023
1020
  p_count = Integer(param_count) rescue -1
1024
1021
 
@@ -210,8 +210,9 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
210
210
  grouped_entries = group_entries entries
211
211
 
212
212
  doc = create_document grouped_entries
213
-
214
- @top_level.comment = doc
213
+ comment = RDoc::Comment.new(@content)
214
+ comment.document = doc
215
+ @top_level.comment = comment
215
216
 
216
217
  @top_level
217
218
  end
@@ -18,7 +18,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
18
18
  attr_accessor :visibility
19
19
  attr_reader :container, :singleton
20
20
 
21
- def initialize(top_level, file_name, content, options, stats)
21
+ def initialize(top_level, content, options, stats)
22
22
  super
23
23
 
24
24
  content = handle_tab_width(content)
@@ -31,10 +31,21 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
31
31
  @track_visibility = :nodoc != @options.visibility
32
32
  @encoding = @options.encoding
33
33
 
34
- @module_nesting = [top_level]
34
+ @module_nesting = [[top_level, false]]
35
35
  @container = top_level
36
36
  @visibility = :public
37
37
  @singleton = false
38
+ @in_proc_block = false
39
+ end
40
+
41
+ # Suppress `extend` and `include` within block
42
+ # because they might be a metaprogramming block
43
+ # example: `Module.new { include M }` `M.module_eval { include N }`
44
+
45
+ def with_in_proc_block
46
+ @in_proc_block = true
47
+ yield
48
+ @in_proc_block = false
38
49
  end
39
50
 
40
51
  # Dive into another container
@@ -43,22 +54,24 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
43
54
  old_container = @container
44
55
  old_visibility = @visibility
45
56
  old_singleton = @singleton
57
+ old_in_proc_block = @in_proc_block
46
58
  @visibility = :public
47
59
  @container = container
48
60
  @singleton = singleton
61
+ @in_proc_block = false
49
62
  unless singleton
50
- @module_nesting.push container
51
-
52
63
  # Need to update module parent chain to emulate Module.nesting.
53
64
  # This mechanism is inaccurate and needs to be fixed.
54
65
  container.parent = old_container
55
66
  end
67
+ @module_nesting.push([container, singleton])
56
68
  yield container
57
69
  ensure
58
70
  @container = old_container
59
71
  @visibility = old_visibility
60
72
  @singleton = old_singleton
61
- @module_nesting.pop unless singleton
73
+ @in_proc_block = old_in_proc_block
74
+ @module_nesting.pop
62
75
  end
63
76
 
64
77
  # Records the location of this +container+ in the file for this parser and
@@ -204,6 +217,10 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
204
217
  @stats.add_method meth
205
218
  end
206
219
 
220
+ def has_modifier_nodoc?(line_no) # :nodoc:
221
+ @modifier_comments[line_no]&.text&.match?(/\A#\s*:nodoc:/)
222
+ end
223
+
207
224
  def handle_modifier_directive(code_object, line_no) # :nodoc:
208
225
  comment = @modifier_comments[line_no]
209
226
  @preprocess.handle(comment.text, code_object) if comment
@@ -272,21 +289,19 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
272
289
 
273
290
  if attributes
274
291
  attributes.each do |attr|
275
- a = RDoc::Attr.new(@container, attr, rw, processed_comment)
292
+ a = RDoc::Attr.new(@container, attr, rw, processed_comment, singleton: @singleton)
276
293
  a.store = @store
277
294
  a.line = line_no
278
- a.singleton = @singleton
279
295
  record_location(a)
280
296
  @container.add_attribute(a)
281
297
  a.visibility = visibility
282
298
  end
283
299
  elsif line_no || node
284
300
  method_name ||= call_node_name_arguments(node).first if is_call_node
285
- meth = RDoc::AnyMethod.new(@container, method_name)
286
- meth.singleton = @singleton || singleton_method
301
+ meth = RDoc::AnyMethod.new(@container, method_name, singleton: @singleton || singleton_method)
287
302
  handle_consecutive_comment_directive(meth, comment)
288
303
  comment.normalize
289
- comment.extract_call_seq(meth)
304
+ meth.call_seq = comment.extract_call_seq
290
305
  meth.comment = comment
291
306
  if node
292
307
  tokens = visible_tokens_from_location(node.location)
@@ -299,7 +314,6 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
299
314
  meth,
300
315
  line_no: line_no,
301
316
  visibility: visibility,
302
- singleton: @singleton || singleton_method,
303
317
  params: '()',
304
318
  calls_super: false,
305
319
  block_params: nil,
@@ -435,8 +449,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
435
449
  comment = consecutive_comment(line_no)
436
450
  handle_consecutive_comment_directive(@container, comment)
437
451
  visibility = @container.find_method(old_name, @singleton)&.visibility || :public
438
- a = RDoc::Alias.new(nil, old_name, new_name, comment, @singleton)
439
- a.comment = comment
452
+ a = RDoc::Alias.new(nil, old_name, new_name, comment, singleton: @singleton)
440
453
  handle_modifier_directive(a, line_no)
441
454
  a.store = @store
442
455
  a.line = line_no
@@ -455,10 +468,9 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
455
468
  return unless @container.document_children
456
469
 
457
470
  names.each do |symbol|
458
- a = RDoc::Attr.new(nil, symbol.to_s, rw, comment)
471
+ a = RDoc::Attr.new(nil, symbol.to_s, rw, comment, singleton: @singleton)
459
472
  a.store = @store
460
473
  a.line = line_no
461
- a.singleton = @singleton
462
474
  record_location(a)
463
475
  handle_modifier_directive(a, line_no)
464
476
  @container.add_attribute(a) if should_document?(a)
@@ -467,6 +479,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
467
479
  end
468
480
 
469
481
  def add_includes_extends(names, rdoc_class, line_no) # :nodoc:
482
+ return if @in_proc_block
470
483
  comment = consecutive_comment(line_no)
471
484
  handle_consecutive_comment_directive(@container, comment)
472
485
  names.each do |name|
@@ -492,51 +505,53 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
492
505
 
493
506
  # Adds a method defined by `def` syntax
494
507
 
495
- def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:, start_line:, end_line:)
508
+ def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:, start_line:, args_end_line:, end_line:)
509
+ return if @in_proc_block
510
+
496
511
  receiver = receiver_name ? find_or_create_module_path(receiver_name, receiver_fallback_type) : @container
497
- meth = RDoc::AnyMethod.new(nil, name)
512
+ meth = RDoc::AnyMethod.new(nil, name, singleton: singleton)
498
513
  if (comment = consecutive_comment(start_line))
499
514
  handle_consecutive_comment_directive(@container, comment)
500
515
  handle_consecutive_comment_directive(meth, comment)
501
516
 
502
517
  comment.normalize
503
- comment.extract_call_seq(meth)
518
+ meth.call_seq = comment.extract_call_seq
504
519
  meth.comment = comment
505
520
  end
506
521
  handle_modifier_directive(meth, start_line)
522
+ handle_modifier_directive(meth, args_end_line)
507
523
  handle_modifier_directive(meth, end_line)
508
524
  return unless should_document?(meth)
509
525
 
510
-
511
- if meth.name == 'initialize' && !singleton
512
- if meth.dont_rename_initialize
513
- visibility = :protected
514
- else
515
- meth.name = 'new'
516
- singleton = true
517
- visibility = :public
518
- end
519
- end
520
-
521
526
  internal_add_method(
522
527
  receiver,
523
528
  meth,
524
529
  line_no: start_line,
525
530
  visibility: visibility,
526
- singleton: singleton,
527
531
  params: params,
528
532
  calls_super: calls_super,
529
533
  block_params: block_params,
530
534
  tokens: tokens
531
535
  )
536
+
537
+ # Rename after add_method to register duplicated 'new' and 'initialize'
538
+ # defined in c and ruby just like the old parser did.
539
+ if meth.name == 'initialize' && !singleton
540
+ if meth.dont_rename_initialize
541
+ meth.visibility = :protected
542
+ else
543
+ meth.name = 'new'
544
+ meth.singleton = true
545
+ meth.visibility = :public
546
+ end
547
+ end
532
548
  end
533
549
 
534
- private def internal_add_method(container, meth, line_no:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:) # :nodoc:
550
+ private def internal_add_method(container, meth, line_no:, visibility:, params:, calls_super:, block_params:, tokens:) # :nodoc:
535
551
  meth.name ||= meth.call_seq[/\A[^()\s]+/] if meth.call_seq
536
552
  meth.name ||= 'unknown'
537
553
  meth.store = @store
538
554
  meth.line = line_no
539
- meth.singleton = singleton
540
555
  container.add_method(meth) # should add after setting singleton and before setting visibility
541
556
  meth.visibility = visibility
542
557
  meth.params ||= params
@@ -565,12 +580,17 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
565
580
  if root_name.empty?
566
581
  mod = @top_level
567
582
  else
568
- @module_nesting.reverse_each do |nesting|
583
+ @module_nesting.reverse_each do |nesting, singleton|
584
+ next if singleton
569
585
  mod = nesting.find_module_named(root_name)
570
586
  break if mod
587
+ # If a constant is found and it is not a module or class, RDoc can't document about it.
588
+ # Return an anonymous module to avoid wrong document creation.
589
+ return RDoc::NormalModule.new(nil) if nesting.find_constant_named(root_name)
571
590
  end
572
- return mod || add_module.call(@top_level, root_name, create_mode) unless name
573
- mod ||= add_module.call(@top_level, root_name, :module)
591
+ last_nesting, = @module_nesting.reverse_each.find { |_, singleton| !singleton }
592
+ return mod || add_module.call(last_nesting, root_name, create_mode) unless name
593
+ mod ||= add_module.call(last_nesting, root_name, :module)
574
594
  end
575
595
  path.each do |name|
576
596
  mod = mod.find_module_named(name) || add_module.call(mod, name, :module)
@@ -584,7 +604,8 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
584
604
  owner_name, path = constant_path.split('::', 2)
585
605
  return constant_path if owner_name.empty? # ::Foo, ::Foo::Bar
586
606
  mod = nil
587
- @module_nesting.reverse_each do |nesting|
607
+ @module_nesting.reverse_each do |nesting, singleton|
608
+ next if singleton
588
609
  mod = nesting.find_module_named(owner_name)
589
610
  break if mod
590
611
  end
@@ -598,7 +619,10 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
598
619
  def find_or_create_constant_owner_name(constant_path)
599
620
  const_path, colon, name = constant_path.rpartition('::')
600
621
  if colon.empty? # class Foo
601
- [@container, name]
622
+ # Within `class C` or `module C`, owner is C(== current container)
623
+ # Within `class <<C`, owner is C.singleton_class
624
+ # but RDoc don't track constants of a singleton class of module
625
+ [(@singleton ? nil : @container), name]
602
626
  elsif const_path.empty? # class ::Foo
603
627
  [@top_level, name]
604
628
  else # `class Foo::Bar` or `class ::Foo::Bar`
@@ -612,6 +636,8 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
612
636
  comment = consecutive_comment(start_line)
613
637
  handle_consecutive_comment_directive(@container, comment)
614
638
  owner, name = find_or_create_constant_owner_name(constant_name)
639
+ return unless owner
640
+
615
641
  constant = RDoc::Constant.new(name, rhs_name, comment)
616
642
  constant.store = @store
617
643
  constant.line = start_line
@@ -635,12 +661,14 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
635
661
 
636
662
  # Adds module or class
637
663
 
638
- def add_module_or_class(module_name, start_line, end_line, is_class: false, superclass_name: nil)
664
+ def add_module_or_class(module_name, start_line, end_line, is_class: false, superclass_name: nil, superclass_expr: nil)
639
665
  comment = consecutive_comment(start_line)
640
666
  handle_consecutive_comment_directive(@container, comment)
641
667
  return unless @container.document_children
642
668
 
643
669
  owner, name = find_or_create_constant_owner_name(module_name)
670
+ return unless owner
671
+
644
672
  if is_class
645
673
  # RDoc::NormalClass resolves superclass name despite of the lack of module nesting information.
646
674
  # We need to fix it when RDoc::NormalClass resolved to a wrong constant name
@@ -648,13 +676,14 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
648
676
  superclass_full_path = resolve_constant_path(superclass_name)
649
677
  superclass = @store.find_class_or_module(superclass_full_path) if superclass_full_path
650
678
  superclass_full_path ||= superclass_name
679
+ superclass_full_path = superclass_full_path.sub(/^::/, '')
651
680
  end
652
681
  # add_class should be done after resolving superclass
653
- mod = owner.classes_hash[name] || owner.add_class(RDoc::NormalClass, name, superclass_name || '::Object')
682
+ mod = owner.classes_hash[name] || owner.add_class(RDoc::NormalClass, name, superclass_name || superclass_expr || '::Object')
654
683
  if superclass_name
655
684
  if superclass
656
685
  mod.superclass = superclass
657
- elsif mod.superclass.is_a?(String) && mod.superclass != superclass_full_path
686
+ elsif (mod.superclass.is_a?(String) || mod.superclass.name == 'Object') && mod.superclass != superclass_full_path
658
687
  mod.superclass = superclass_full_path
659
688
  end
660
689
  end
@@ -678,6 +707,20 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
678
707
  @store = store
679
708
  end
680
709
 
710
+ def visit_if_node(node)
711
+ if node.end_keyword
712
+ super
713
+ else
714
+ # Visit with the order in text representation to handle this method comment
715
+ # # comment
716
+ # def f
717
+ # end if call_node
718
+ node.statements.accept(self)
719
+ node.predicate.accept(self)
720
+ end
721
+ end
722
+ alias visit_unless_node visit_if_node
723
+
681
724
  def visit_call_node(node)
682
725
  @scanner.process_comments_until(node.location.start_line - 1)
683
726
  if node.receiver.nil?
@@ -715,6 +758,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
715
758
  when :private_class_method
716
759
  _visit_call_public_private_class_method(node, :private) { super }
717
760
  else
761
+ node.arguments&.accept(self)
718
762
  super
719
763
  end
720
764
  else
@@ -722,6 +766,13 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
722
766
  end
723
767
  end
724
768
 
769
+ def visit_block_node(node)
770
+ @scanner.with_in_proc_block do
771
+ # include, extend and method definition inside block are not documentable
772
+ super
773
+ end
774
+ end
775
+
725
776
  def visit_alias_method_node(node)
726
777
  @scanner.process_comments_until(node.location.start_line - 1)
727
778
  return unless node.old_name.is_a?(Prism::SymbolNode) && node.new_name.is_a?(Prism::SymbolNode)
@@ -729,12 +780,13 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
729
780
  end
730
781
 
731
782
  def visit_module_node(node)
783
+ node.constant_path.accept(self)
732
784
  @scanner.process_comments_until(node.location.start_line - 1)
733
785
  module_name = constant_path_string(node.constant_path)
734
786
  mod = @scanner.add_module_or_class(module_name, node.location.start_line, node.location.end_line) if module_name
735
787
  if mod
736
788
  @scanner.with_container(mod) do
737
- super
789
+ node.body&.accept(self)
738
790
  @scanner.process_comments_until(node.location.end_line)
739
791
  end
740
792
  else
@@ -743,13 +795,16 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
743
795
  end
744
796
 
745
797
  def visit_class_node(node)
798
+ node.constant_path.accept(self)
799
+ node.superclass&.accept(self)
746
800
  @scanner.process_comments_until(node.location.start_line - 1)
747
801
  superclass_name = constant_path_string(node.superclass) if node.superclass
802
+ superclass_expr = node.superclass.slice if node.superclass && !superclass_name
748
803
  class_name = constant_path_string(node.constant_path)
749
- klass = @scanner.add_module_or_class(class_name, node.location.start_line, node.location.end_line, is_class: true, superclass_name: superclass_name) if class_name
804
+ klass = @scanner.add_module_or_class(class_name, node.location.start_line, node.location.end_line, is_class: true, superclass_name: superclass_name, superclass_expr: superclass_expr) if class_name
750
805
  if klass
751
806
  @scanner.with_container(klass) do
752
- super
807
+ node.body&.accept(self)
753
808
  @scanner.process_comments_until(node.location.end_line)
754
809
  end
755
810
  else
@@ -760,6 +815,12 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
760
815
  def visit_singleton_class_node(node)
761
816
  @scanner.process_comments_until(node.location.start_line - 1)
762
817
 
818
+ if @scanner.has_modifier_nodoc?(node.location.start_line)
819
+ # Skip visiting inside the singleton class. Also skips creation of node.expression as a module
820
+ @scanner.skip_comments_until(node.location.end_line)
821
+ return
822
+ end
823
+
763
824
  expression = node.expression
764
825
  expression = expression.body.body.first if expression.is_a?(Prism::ParenthesesNode) && expression.body&.body&.size == 1
765
826
 
@@ -774,9 +835,10 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
774
835
  when Prism::SelfNode
775
836
  mod = @scanner.container if @scanner.container != @top_level
776
837
  end
838
+ expression.accept(self)
777
839
  if mod
778
840
  @scanner.with_container(mod, singleton: true) do
779
- super
841
+ node.body&.accept(self)
780
842
  @scanner.process_comments_until(node.location.end_line)
781
843
  end
782
844
  else
@@ -786,6 +848,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
786
848
 
787
849
  def visit_def_node(node)
788
850
  start_line = node.location.start_line
851
+ args_end_line = node.parameters&.location&.end_line || start_line
789
852
  end_line = node.location.end_line
790
853
  @scanner.process_comments_until(start_line - 1)
791
854
 
@@ -836,6 +899,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
836
899
  calls_super: calls_super,
837
900
  tokens: tokens,
838
901
  start_line: start_line,
902
+ args_end_line: args_end_line,
839
903
  end_line: end_line
840
904
  )
841
905
  ensure
@@ -944,7 +1008,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
944
1008
  @scanner.visibility = visibility
945
1009
  else # `public :foo, :bar`, `private def foo; end`
946
1010
  yield
947
- names = visibility_method_arguments(call_node, singleton: @scanner.singleton)
1011
+ names = visibility_method_arguments(call_node, singleton: false)
948
1012
  @scanner.change_method_visibility(names, visibility) if names
949
1013
  end
950
1014
  end
@@ -170,7 +170,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
170
170
  ##
171
171
  # Creates a new Ruby parser.
172
172
 
173
- def initialize(top_level, file_name, content, options, stats)
173
+ def initialize(top_level, content, options, stats)
174
174
  super
175
175
 
176
176
  content = handle_tab_width(content)
@@ -293,7 +293,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
293
293
  # Creates a new attribute in +container+ with +name+.
294
294
 
295
295
  def create_attr container, single, name, rw, comment # :nodoc:
296
- att = RDoc::Attr.new get_tkread, name, rw, comment, single == SINGLE
296
+ att = RDoc::Attr.new get_tkread, name, rw, comment, singleton: single == SINGLE
297
297
  record_location att
298
298
 
299
299
  container.add_attribute att
@@ -792,8 +792,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
792
792
  return
793
793
  end
794
794
 
795
- al = RDoc::Alias.new(get_tkread, old_name, new_name, comment,
796
- single == SINGLE)
795
+ al = RDoc::Alias.new(get_tkread, old_name, new_name, comment, singleton: single == SINGLE)
797
796
  record_location al
798
797
  al.line = line_no
799
798
 
@@ -1153,7 +1152,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
1153
1152
  end
1154
1153
 
1155
1154
  comment.normalize
1156
- comment.extract_call_seq meth
1155
+ meth.call_seq = comment.extract_call_seq
1157
1156
 
1158
1157
  return unless meth.name
1159
1158
 
@@ -1358,10 +1357,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
1358
1357
 
1359
1358
  return unless name
1360
1359
 
1361
- meth = RDoc::MetaMethod.new get_tkread, name
1360
+ meth = RDoc::MetaMethod.new get_tkread, name, singleton: singleton
1362
1361
  record_location meth
1363
1362
  meth.line = line_no
1364
- meth.singleton = singleton
1365
1363
 
1366
1364
  remove_token_listener self
1367
1365
 
@@ -1417,7 +1415,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
1417
1415
 
1418
1416
  look_for_directives_in meth, comment
1419
1417
  comment.normalize
1420
- comment.extract_call_seq meth
1418
+ meth.call_seq = comment.extract_call_seq
1421
1419
 
1422
1420
  container.add_method meth
1423
1421
 
@@ -1461,9 +1459,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
1461
1459
 
1462
1460
  return unless name
1463
1461
 
1464
- meth = RDoc::AnyMethod.new get_tkread, name
1462
+ meth = RDoc::AnyMethod.new get_tkread, name, singleton: single == SINGLE ? true : singleton
1465
1463
  look_for_directives_in meth, comment
1466
- meth.singleton = single == SINGLE ? true : singleton
1467
1464
  if singleton
1468
1465
  # `current_line_visibility' is useless because it works against
1469
1466
  # the normal method named as same as the singleton method, after
@@ -1485,7 +1482,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
1485
1482
  parse_method_params_and_body container, single, meth, added_container
1486
1483
 
1487
1484
  comment.normalize
1488
- comment.extract_call_seq meth
1485
+ meth.call_seq = comment.extract_call_seq
1489
1486
 
1490
1487
  meth.comment = comment
1491
1488