rdoc 6.3.4.1 → 8.0.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 (205) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +195 -0
  3. data/History.rdoc +65 -63
  4. data/LEGAL.rdoc +7 -1
  5. data/LICENSE.rdoc +6 -0
  6. data/README.md +236 -0
  7. data/RI.md +842 -0
  8. data/TODO.rdoc +8 -7
  9. data/doc/markup_reference/markdown.md +659 -0
  10. data/doc/markup_reference/rdoc.rdoc +1169 -0
  11. data/exe/rdoc +0 -1
  12. data/lib/rdoc/{alias.rb → code_object/alias.rb} +4 -18
  13. data/lib/rdoc/{any_method.rb → code_object/any_method.rb} +50 -24
  14. data/lib/rdoc/{attr.rb → code_object/attr.rb} +16 -14
  15. data/lib/rdoc/{class_module.rb → code_object/class_module.rb} +225 -58
  16. data/lib/rdoc/{constant.rb → code_object/constant.rb} +44 -10
  17. data/lib/rdoc/code_object/context/section.rb +182 -0
  18. data/lib/rdoc/{context.rb → code_object/context.rb} +78 -106
  19. data/lib/rdoc/{extend.rb → code_object/extend.rb} +0 -1
  20. data/lib/rdoc/{include.rb → code_object/include.rb} +0 -1
  21. data/lib/rdoc/{method_attr.rb → code_object/method_attr.rb} +46 -48
  22. data/lib/rdoc/{mixin.rb → code_object/mixin.rb} +6 -4
  23. data/lib/rdoc/{normal_class.rb → code_object/normal_class.rb} +2 -3
  24. data/lib/rdoc/{normal_module.rb → code_object/normal_module.rb} +2 -3
  25. data/lib/rdoc/{require.rb → code_object/require.rb} +1 -2
  26. data/lib/rdoc/{single_class.rb → code_object/single_class.rb} +5 -1
  27. data/lib/rdoc/{top_level.rb → code_object/top_level.rb} +60 -63
  28. data/lib/rdoc/code_object.rb +11 -39
  29. data/lib/rdoc/code_objects.rb +1 -2
  30. data/lib/rdoc/comment.rb +202 -99
  31. data/lib/rdoc/cross_reference.rb +75 -62
  32. data/lib/rdoc/encoding.rb +8 -24
  33. data/lib/rdoc/erb_partial.rb +1 -2
  34. data/lib/rdoc/erbio.rb +3 -8
  35. data/lib/rdoc/generator/aliki.rb +200 -0
  36. data/lib/rdoc/generator/darkfish.rb +156 -122
  37. data/lib/rdoc/generator/json_index.rb +8 -24
  38. data/lib/rdoc/generator/markup.rb +70 -34
  39. data/lib/rdoc/generator/pot/message_extractor.rb +7 -7
  40. data/lib/rdoc/generator/pot/po.rb +1 -1
  41. data/lib/rdoc/generator/pot/po_entry.rb +8 -8
  42. data/lib/rdoc/generator/pot.rb +1 -5
  43. data/lib/rdoc/generator/ri.rb +1 -2
  44. data/lib/rdoc/generator/template/aliki/DESIGN.md +536 -0
  45. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +8 -0
  46. data/lib/rdoc/generator/template/aliki/_footer.rhtml +23 -0
  47. data/lib/rdoc/generator/template/aliki/_head.rhtml +163 -0
  48. data/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
  49. data/lib/rdoc/generator/template/aliki/_icons.rhtml +208 -0
  50. data/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +16 -0
  51. data/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +15 -0
  52. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +27 -0
  53. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +27 -0
  54. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
  55. data/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +41 -0
  56. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +67 -0
  57. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
  58. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +21 -0
  59. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
  60. data/lib/rdoc/generator/template/aliki/class.rhtml +230 -0
  61. data/lib/rdoc/generator/template/aliki/css/rdoc.css +2181 -0
  62. data/lib/rdoc/generator/template/aliki/index.rhtml +22 -0
  63. data/lib/rdoc/generator/template/aliki/js/aliki.js +513 -0
  64. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  65. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +299 -0
  66. data/lib/rdoc/generator/template/aliki/js/search_controller.js +129 -0
  67. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  68. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  69. data/lib/rdoc/generator/template/aliki/js/theme-toggle.js +112 -0
  70. data/lib/rdoc/generator/template/aliki/page.rhtml +18 -0
  71. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +14 -0
  72. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +65 -0
  73. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +3 -3
  74. data/lib/rdoc/generator/template/darkfish/_head.rhtml +35 -14
  75. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +1 -5
  76. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +11 -9
  77. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +11 -9
  78. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +7 -6
  79. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +20 -11
  80. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +25 -5
  81. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +4 -9
  82. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +2 -1
  83. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
  84. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +28 -7
  85. data/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
  86. data/lib/rdoc/generator/template/darkfish/class.rhtml +138 -90
  87. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +420 -358
  88. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  89. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  90. data/lib/rdoc/generator/template/darkfish/index.rhtml +14 -12
  91. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +59 -3
  92. data/lib/rdoc/generator/template/darkfish/js/search.js +15 -5
  93. data/lib/rdoc/generator/template/darkfish/page.rhtml +7 -6
  94. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +12 -9
  95. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +24 -21
  96. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +35 -21
  97. data/lib/rdoc/generator/template/json_index/js/navigation.js +8 -8
  98. data/lib/rdoc/generator/template/json_index/js/searcher.js +48 -6
  99. data/lib/rdoc/generator.rb +6 -5
  100. data/lib/rdoc/i18n/text.rb +3 -3
  101. data/lib/rdoc/i18n.rb +1 -1
  102. data/lib/rdoc/known_classes.rb +5 -4
  103. data/lib/rdoc/markdown/entities.rb +0 -1
  104. data/lib/rdoc/markdown/literals.kpeg +0 -2
  105. data/lib/rdoc/markdown/literals.rb +0 -1
  106. data/lib/rdoc/markdown.kpeg +140 -62
  107. data/lib/rdoc/markdown.rb +1015 -873
  108. data/lib/rdoc/markup/blank_line.rb +25 -24
  109. data/lib/rdoc/markup/block_quote.rb +1 -2
  110. data/lib/rdoc/markup/document.rb +10 -11
  111. data/lib/rdoc/markup/element.rb +21 -0
  112. data/lib/rdoc/markup/formatter.rb +134 -115
  113. data/lib/rdoc/markup/hard_break.rb +30 -28
  114. data/lib/rdoc/markup/heading.rb +163 -72
  115. data/lib/rdoc/markup/include.rb +3 -4
  116. data/lib/rdoc/markup/indented_paragraph.rb +4 -5
  117. data/lib/rdoc/markup/inline_parser.rb +312 -0
  118. data/lib/rdoc/markup/list.rb +6 -7
  119. data/lib/rdoc/markup/list_item.rb +6 -7
  120. data/lib/rdoc/markup/paragraph.rb +2 -3
  121. data/lib/rdoc/markup/parser.rb +29 -19
  122. data/lib/rdoc/markup/pre_process.rb +39 -18
  123. data/lib/rdoc/markup/raw.rb +52 -56
  124. data/lib/rdoc/markup/rule.rb +2 -3
  125. data/lib/rdoc/markup/table.rb +49 -32
  126. data/lib/rdoc/markup/to_ansi.rb +58 -8
  127. data/lib/rdoc/markup/to_bs.rb +47 -38
  128. data/lib/rdoc/markup/to_html.rb +343 -105
  129. data/lib/rdoc/markup/to_html_crossref.rb +143 -58
  130. data/lib/rdoc/markup/to_html_snippet.rb +78 -76
  131. data/lib/rdoc/markup/to_joined_paragraph.rb +3 -9
  132. data/lib/rdoc/markup/to_label.rb +34 -25
  133. data/lib/rdoc/markup/to_markdown.rb +74 -51
  134. data/lib/rdoc/markup/to_rdoc.rb +141 -82
  135. data/lib/rdoc/markup/to_table_of_contents.rb +4 -5
  136. data/lib/rdoc/markup/to_test.rb +10 -3
  137. data/lib/rdoc/markup/to_tt_only.rb +17 -31
  138. data/lib/rdoc/markup/verbatim.rb +5 -6
  139. data/lib/rdoc/markup.rb +59 -707
  140. data/lib/rdoc/options.rb +228 -101
  141. data/lib/rdoc/parser/c.rb +186 -184
  142. data/lib/rdoc/parser/changelog.rb +57 -13
  143. data/lib/rdoc/parser/markdown.rb +0 -2
  144. data/lib/rdoc/parser/rbs.rb +275 -0
  145. data/lib/rdoc/parser/rd.rb +0 -1
  146. data/lib/rdoc/parser/ruby.rb +963 -2024
  147. data/lib/rdoc/parser/ruby_colorizer.rb +253 -0
  148. data/lib/rdoc/parser/simple.rb +6 -23
  149. data/lib/rdoc/parser/text.rb +0 -1
  150. data/lib/rdoc/parser.rb +35 -14
  151. data/lib/rdoc/rbs_helper.rb +186 -0
  152. data/lib/rdoc/rd/block_parser.rb +659 -11
  153. data/lib/rdoc/rd/block_parser.ry +13 -9
  154. data/lib/rdoc/rd/inline.rb +4 -5
  155. data/lib/rdoc/rd/inline_parser.rb +646 -2
  156. data/lib/rdoc/rd.rb +4 -5
  157. data/lib/rdoc/rdoc.rb +234 -90
  158. data/lib/rdoc/ri/driver.rb +172 -172
  159. data/lib/rdoc/ri/paths.rb +3 -3
  160. data/lib/rdoc/{servlet.rb → ri/servlet.rb} +28 -27
  161. data/lib/rdoc/ri/store.rb +0 -1
  162. data/lib/rdoc/ri/task.rb +3 -3
  163. data/lib/rdoc/ri.rb +5 -5
  164. data/lib/rdoc/rubygems_hook.rb +106 -25
  165. data/lib/rdoc/server.rb +460 -0
  166. data/lib/rdoc/stats/normal.rb +1 -1
  167. data/lib/rdoc/stats/quiet.rb +1 -2
  168. data/lib/rdoc/stats/verbose.rb +3 -5
  169. data/lib/rdoc/stats.rb +158 -136
  170. data/lib/rdoc/store.rb +267 -48
  171. data/lib/rdoc/task.rb +54 -28
  172. data/lib/rdoc/text.rb +60 -120
  173. data/lib/rdoc/token_stream.rb +30 -45
  174. data/lib/rdoc/tom_doc.rb +9 -15
  175. data/lib/rdoc/version.rb +3 -1
  176. data/lib/rdoc.rb +90 -52
  177. data/lib/rubygems_plugin.rb +14 -0
  178. data/man/ri.1 +2 -0
  179. data/rdoc-logo.svg +43 -0
  180. data/rdoc.gemspec +25 -200
  181. metadata +120 -53
  182. data/CONTRIBUTING.rdoc +0 -220
  183. data/ExampleMarkdown.md +0 -37
  184. data/ExampleRDoc.rdoc +0 -208
  185. data/Gemfile +0 -12
  186. data/README.rdoc +0 -129
  187. data/RI.rdoc +0 -57
  188. data/Rakefile +0 -101
  189. data/bin/console +0 -7
  190. data/bin/setup +0 -6
  191. data/lib/rdoc/anon_class.rb +0 -11
  192. data/lib/rdoc/context/section.rb +0 -232
  193. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  194. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +0 -19
  195. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +0 -9
  196. data/lib/rdoc/generator/template/json_index/.document +0 -1
  197. data/lib/rdoc/ghost_method.rb +0 -7
  198. data/lib/rdoc/markup/attr_changer.rb +0 -23
  199. data/lib/rdoc/markup/attr_span.rb +0 -36
  200. data/lib/rdoc/markup/attribute_manager.rb +0 -409
  201. data/lib/rdoc/markup/attributes.rb +0 -71
  202. data/lib/rdoc/markup/regexp_handling.rb +0 -41
  203. data/lib/rdoc/meta_method.rb +0 -7
  204. data/lib/rdoc/parser/ripper_state_lex.rb +0 -590
  205. data/lib/rdoc/parser/ruby_tools.rb +0 -167
data/lib/rdoc/store.rb CHANGED
@@ -54,7 +54,7 @@ class RDoc::Store
54
54
  # Creates a new MissingFileError for the missing +file+ for the given
55
55
  # +name+ that should have been in the +store+.
56
56
 
57
- def initialize store, file, name
57
+ def initialize(store, file, name)
58
58
  @store = store
59
59
  @file = file
60
60
  @name = name
@@ -94,11 +94,7 @@ class RDoc::Store
94
94
 
95
95
  attr_accessor :path
96
96
 
97
- ##
98
- # The RDoc::RDoc driver for this parse tree. This allows classes consulting
99
- # the documentation tree to access user-set options, for example.
100
-
101
- attr_accessor :rdoc
97
+ attr_reader :options
102
98
 
103
99
  ##
104
100
  # Type of ri datastore this was loaded from. See RDoc::RI::Driver,
@@ -124,11 +120,11 @@ class RDoc::Store
124
120
  ##
125
121
  # Creates a new Store of +type+ that will load or save to +path+
126
122
 
127
- def initialize path = nil, type = nil
128
- @dry_run = false
129
- @encoding = nil
130
- @path = path
131
- @rdoc = nil
123
+ def initialize(options, path: nil, type: nil)
124
+ @options = options
125
+ @dry_run = options.dry_run
126
+ @encoding = options.encoding
127
+ @path = path || options.op_dir
132
128
  @type = type
133
129
 
134
130
  @cache = {
@@ -139,10 +135,10 @@ class RDoc::Store
139
135
  :c_singleton_class_variables => {},
140
136
  :encoding => @encoding,
141
137
  :instance_methods => {},
142
- :main => nil,
138
+ :main => options.main_page,
143
139
  :modules => [],
144
140
  :pages => [],
145
- :title => nil,
141
+ :title => options.title,
146
142
  }
147
143
 
148
144
  @classes_hash = {}
@@ -166,14 +162,14 @@ class RDoc::Store
166
162
  # Adds +module+ as an enclosure (namespace) for the given +variable+ for C
167
163
  # files.
168
164
 
169
- def add_c_enclosure variable, namespace
165
+ def add_c_enclosure(variable, namespace)
170
166
  @c_enclosure_classes[variable] = namespace
171
167
  end
172
168
 
173
169
  ##
174
170
  # Adds C variables from an RDoc::Parser::C
175
171
 
176
- def add_c_variables c_parser
172
+ def add_c_variables(c_parser)
177
173
  filename = c_parser.top_level.relative_name
178
174
 
179
175
  @c_class_variables[filename] = make_variable_map c_parser.classes
@@ -185,7 +181,7 @@ class RDoc::Store
185
181
  # Adds the file with +name+ as an RDoc::TopLevel to the store. Returns the
186
182
  # created RDoc::TopLevel.
187
183
 
188
- def add_file absolute_name, relative_name: absolute_name, parser: nil
184
+ def add_file(absolute_name, relative_name: absolute_name, parser: nil)
189
185
  unless top_level = @files_hash[relative_name] then
190
186
  top_level = RDoc::TopLevel.new absolute_name, relative_name
191
187
  top_level.parser = parser if parser
@@ -197,9 +193,139 @@ class RDoc::Store
197
193
  top_level
198
194
  end
199
195
 
200
- def update_parser_of_file(absolute_name, parser)
201
- if top_level = @files_hash[absolute_name] then
202
- @text_files_hash[absolute_name] = top_level if top_level.text?
196
+ ##
197
+ # Removes a file and its classes/modules from the store. Used by the
198
+ # live-reloading server when a source file is deleted.
199
+ #
200
+ # Note: this does not handle reopened classes correctly. If a class is
201
+ # defined across multiple files (e.g. +Foo+ in both +a.rb+ and +b.rb+),
202
+ # deleting one file removes the entire class from the store — including
203
+ # the parts contributed by the other file. Saving the remaining file
204
+ # triggers a re-parse that restores it.
205
+
206
+ def remove_file(relative_name)
207
+ top_level = @files_hash.delete(relative_name)
208
+ @text_files_hash.delete(relative_name)
209
+ @c_class_variables.delete(relative_name)
210
+ @c_singleton_class_variables.delete(relative_name)
211
+ return unless top_level
212
+
213
+ remove_classes_and_modules(top_level.classes_or_modules)
214
+ end
215
+
216
+ ##
217
+ # Removes a file's contributions (methods, constants, comments, etc.)
218
+ # from its classes and modules. If no other files contribute to a
219
+ # class or module, it is removed from the store entirely. This
220
+ # prevents duplication when the file is re-parsed while preserving
221
+ # shared namespaces like +RDoc+ that span many files.
222
+
223
+ def clear_file_contributions(relative_name, keep_position: false)
224
+ top_level = @files_hash[relative_name]
225
+ return unless top_level
226
+
227
+ top_level.classes_or_modules.each do |cm|
228
+ # Remove methods and attributes contributed by this file
229
+ cm.method_list.reject! { |m| m.file == top_level }
230
+ cm.attributes.reject! { |a| a.file == top_level }
231
+
232
+ # Rebuild methods_hash from remaining methods and attributes
233
+ cm.methods_hash.clear
234
+ cm.method_list.each { |m| cm.methods_hash[m.pretty_name] = m }
235
+ cm.attributes.each { |a| cm.methods_hash[a.pretty_name] = a }
236
+
237
+ # Remove constants contributed by this file
238
+ cm.constants.reject! { |c| c.file == top_level }
239
+ cm.constants_hash.clear
240
+ cm.constants.each { |c| cm.constants_hash[c.name] = c }
241
+
242
+ # Remove includes, extends, and aliases from this file
243
+ cm.includes.reject! { |i| i.file == top_level }
244
+ cm.extends.reject! { |e| e.file == top_level }
245
+ cm.aliases.reject! { |a| a.file == top_level }
246
+ cm.external_aliases.reject! { |a| a.file == top_level }
247
+
248
+ # Clear or remove comment entries from this file
249
+ if cm.is_a?(RDoc::ClassModule)
250
+ if keep_position
251
+ cm.comment_location[top_level] = [] if cm.comment_location.key?(top_level)
252
+ else
253
+ cm.comment_location.delete(top_level)
254
+ end
255
+ cm.rebuild_comment_from_location
256
+ end
257
+
258
+ unless keep_position
259
+ # Remove this file from the class/module's file list
260
+ cm.in_files.delete(top_level)
261
+
262
+ # If no files contribute to this class/module anymore, remove it
263
+ # from the store entirely. This handles file deletion correctly
264
+ # for classes that are only defined in the deleted file, while
265
+ # preserving classes that span multiple files.
266
+ if cm.in_files.empty?
267
+ if cm.is_a?(RDoc::NormalModule)
268
+ @modules_hash.delete(cm.full_name)
269
+ else
270
+ @classes_hash.delete(cm.full_name)
271
+ end
272
+ cm.parent&.classes_hash&.delete(cm.name)
273
+ cm.parent&.modules_hash&.delete(cm.name)
274
+ end
275
+ end
276
+ end
277
+
278
+ # Clear the TopLevel's class/module list to prevent duplicates
279
+ top_level.classes_or_modules.clear
280
+ end
281
+
282
+ ##
283
+ # Removes stale empty placeholders left by +clear_file_contributions+ with
284
+ # <tt>keep_position: true</tt>. After re-parsing, a file may no longer
285
+ # define a class it previously contributed to, leaving an empty entry in
286
+ # +comment_location+ and a stale +in_files+ reference. Call this after
287
+ # all re-parsing is complete.
288
+
289
+ def cleanup_stale_contributions
290
+ all_classes_and_modules.each do |cm|
291
+ cm.comment_location.delete_if { |_, comments| comments.empty? }
292
+ cm.rebuild_comment_from_location
293
+
294
+ cm.in_files.select! { |tl| cm.comment_location.key?(tl) ||
295
+ cm.method_list.any? { |m| m.file == tl } ||
296
+ cm.attributes.any? { |a| a.file == tl } ||
297
+ cm.constants.any? { |c| c.file == tl } }
298
+
299
+ if cm.in_files.empty?
300
+ if cm.is_a?(RDoc::NormalModule)
301
+ @modules_hash.delete(cm.full_name)
302
+ else
303
+ @classes_hash.delete(cm.full_name)
304
+ end
305
+ cm.parent&.classes_hash&.delete(cm.name)
306
+ cm.parent&.modules_hash&.delete(cm.name)
307
+ end
308
+ end
309
+ end
310
+
311
+ ##
312
+ # Make sure any references to C variable names are resolved to the corresponding class.
313
+ #
314
+
315
+ def resolve_c_superclasses
316
+ @classes_hash.each_value do |klass|
317
+ if klass.superclass.is_a?(String) && (candidate = find_c_enclosure(klass.superclass))
318
+ klass.superclass = candidate
319
+ end
320
+ end
321
+ end
322
+
323
+ ##
324
+ # Caches +relative_name+ in the text files hash, if it is a text file.
325
+
326
+ def cache_text_file(relative_name)
327
+ if top_level = @files_hash[relative_name]
328
+ @text_files_hash[relative_name] = top_level if top_level.text?
203
329
  end
204
330
  end
205
331
 
@@ -217,6 +343,86 @@ class RDoc::Store
217
343
  @classes_hash.values + @modules_hash.values
218
344
  end
219
345
 
346
+ ##
347
+ # Returns a hash mapping class/module names to their paths, for use
348
+ # by type signature linking. Maps both qualified names (Foo::Bar) and
349
+ # unambiguous unqualified names (Bar). Ambiguous unqualified names
350
+ # (where multiple classes share the same name) are excluded to avoid
351
+ # wrong links. Cached after first call.
352
+
353
+ ##
354
+ # Invalidates the cached type name lookup. Server mode calls this after
355
+ # re-parsing changes the set of classes and modules.
356
+
357
+ def invalidate_type_name_lookup # :nodoc:
358
+ @type_name_lookup = nil
359
+ end
360
+
361
+ def type_name_lookup
362
+ @type_name_lookup ||= begin
363
+ lookup = {}
364
+ unqualified_names = {}
365
+ ambiguous_names = {}
366
+ all_classes_and_modules.each do |cm|
367
+ lookup[cm.full_name] = cm.path
368
+ unqualified_name = cm.name
369
+
370
+ if ambiguous_names[unqualified_name]
371
+ # already known ambiguous, skip
372
+ elsif unqualified_names.key?(unqualified_name)
373
+ unqualified_names.delete(unqualified_name)
374
+ ambiguous_names[unqualified_name] = true
375
+ else
376
+ unqualified_names[unqualified_name] = cm.path
377
+ end
378
+ end
379
+ lookup.merge!(unqualified_names)
380
+ end
381
+ end
382
+
383
+ ##
384
+ # Stores RBS type signatures loaded from sidecar .rbs files, keyed by
385
+ # "ClassName#method" or "ClassName.method". Replaces any previously
386
+ # stored set, so passing +{}+ clears it. Inline +#:+ annotations on
387
+ # method objects are NOT touched — those are owned by the source file.
388
+
389
+ def merge_rbs_signatures(signatures)
390
+ @rbs_signatures = signatures
391
+ end
392
+
393
+ ##
394
+ # Returns the RBS type signature lines for +method_attr+ from loaded
395
+ # sidecar +.rbs+ files, or +nil+ if none. Falls through to the
396
+ # canonical method for aliases, and handles +initialize+ -> +.new+
397
+ # singleton mapping.
398
+
399
+ def rbs_signature_for(method_attr)
400
+ return nil unless @rbs_signatures
401
+ cm = method_attr.parent
402
+ return nil unless cm.respond_to?(:full_name)
403
+
404
+ key = method_attr.singleton ? "#{cm.full_name}.#{method_attr.name}" : "#{cm.full_name}##{method_attr.name}"
405
+ sig = @rbs_signatures[key]
406
+
407
+ # RBS keys constructors as #initialize, but RDoc renames them to .new
408
+ if !sig && method_attr.name == 'new' && method_attr.singleton
409
+ sig = @rbs_signatures["#{cm.full_name}#initialize"]
410
+ end
411
+
412
+ # For aliases, fall through to the canonical method (its inline #:
413
+ # takes precedence over any sidecar signature on the alias's name).
414
+ if !sig && method_attr.is_alias_for
415
+ canonical = method_attr.is_alias_for
416
+ sig = canonical.type_signature_lines || rbs_signature_for(canonical)
417
+ end
418
+
419
+ sig
420
+ end
421
+
422
+ def clear_rbs_signatures # :nodoc:
423
+ @rbs_signatures = nil
424
+ end
425
+
220
426
  ##
221
427
  # All TopLevels known to RDoc
222
428
 
@@ -257,7 +463,7 @@ class RDoc::Store
257
463
  ##
258
464
  # Path to the ri data for +klass_name+
259
465
 
260
- def class_file klass_name
466
+ def class_file(klass_name)
261
467
  name = klass_name.split('::').last
262
468
  File.join class_path(klass_name), "cdesc-#{name}.ri"
263
469
  end
@@ -273,7 +479,7 @@ class RDoc::Store
273
479
  ##
274
480
  # Path where data for +klass_name+ will be stored (methods or class data)
275
481
 
276
- def class_path klass_name
482
+ def class_path(klass_name)
277
483
  File.join @path, *klass_name.split('::')
278
484
  end
279
485
 
@@ -288,7 +494,7 @@ class RDoc::Store
288
494
  # Removes empty items and ensures item in each collection are unique and
289
495
  # sorted
290
496
 
291
- def clean_cache_collection collection # :nodoc:
497
+ def clean_cache_collection(collection) # :nodoc:
292
498
  collection.each do |name, item|
293
499
  if item.empty? then
294
500
  collection.delete name
@@ -316,7 +522,7 @@ class RDoc::Store
316
522
  #
317
523
  # See also RDoc::Context#remove_from_documentation?
318
524
 
319
- def complete min_visibility
525
+ def complete(min_visibility)
320
526
  fix_basic_object_inheritance
321
527
 
322
528
  # cache included modules before they are removed from the documentation
@@ -363,7 +569,7 @@ class RDoc::Store
363
569
  ##
364
570
  # Finds the enclosure (namespace) for the given C +variable+.
365
571
 
366
- def find_c_enclosure variable
572
+ def find_c_enclosure(variable)
367
573
  @c_enclosure_classes.fetch variable do
368
574
  break unless name = @c_enclosure_names[variable]
369
575
 
@@ -388,14 +594,14 @@ class RDoc::Store
388
594
  ##
389
595
  # Finds the class with +name+ in all discovered classes
390
596
 
391
- def find_class_named name
597
+ def find_class_named(name)
392
598
  @classes_hash[name]
393
599
  end
394
600
 
395
601
  ##
396
602
  # Finds the class with +name+ starting in namespace +from+
397
603
 
398
- def find_class_named_from name, from
604
+ def find_class_named_from(name, from)
399
605
  from = find_class_named from unless RDoc::Context === from
400
606
 
401
607
  until RDoc::TopLevel === from do
@@ -413,7 +619,7 @@ class RDoc::Store
413
619
  ##
414
620
  # Finds the class or module with +name+
415
621
 
416
- def find_class_or_module name
622
+ def find_class_or_module(name)
417
623
  name = $' if name =~ /^::/
418
624
  @classes_hash[name] || @modules_hash[name]
419
625
  end
@@ -421,14 +627,14 @@ class RDoc::Store
421
627
  ##
422
628
  # Finds the file with +name+ in all discovered files
423
629
 
424
- def find_file_named name
630
+ def find_file_named(name)
425
631
  @files_hash[name]
426
632
  end
427
633
 
428
634
  ##
429
635
  # Finds the module with +name+ in all discovered modules
430
636
 
431
- def find_module_named name
637
+ def find_module_named(name)
432
638
  @modules_hash[name]
433
639
  end
434
640
 
@@ -436,7 +642,7 @@ class RDoc::Store
436
642
  # Returns the RDoc::TopLevel that is a text file and has the given
437
643
  # +file_name+
438
644
 
439
- def find_text_page file_name
645
+ def find_text_page(file_name)
440
646
  @text_files_hash.each_value.find do |file|
441
647
  file.full_name == file_name
442
648
  end
@@ -449,7 +655,7 @@ class RDoc::Store
449
655
  #--
450
656
  # TODO aliases should be registered by Context#add_module_alias
451
657
 
452
- def find_unique all_hash
658
+ def find_unique(all_hash)
453
659
  unique = []
454
660
 
455
661
  all_hash.each_pair do |full_name, cm|
@@ -592,7 +798,7 @@ class RDoc::Store
592
798
  ##
593
799
  # Loads ri data for +klass_name+ and hooks it up to this store.
594
800
 
595
- def load_class klass_name
801
+ def load_class(klass_name)
596
802
  obj = load_class_data klass_name
597
803
 
598
804
  obj.store = self
@@ -610,7 +816,7 @@ class RDoc::Store
610
816
  ##
611
817
  # Loads ri data for +klass_name+
612
818
 
613
- def load_class_data klass_name
819
+ def load_class_data(klass_name)
614
820
  file = class_file klass_name
615
821
 
616
822
  marshal_load(file)
@@ -623,7 +829,7 @@ class RDoc::Store
623
829
  ##
624
830
  # Loads ri data for +method_name+ in +klass_name+
625
831
 
626
- def load_method klass_name, method_name
832
+ def load_method(klass_name, method_name)
627
833
  file = method_file klass_name, method_name
628
834
 
629
835
  obj = marshal_load(file)
@@ -639,7 +845,7 @@ class RDoc::Store
639
845
  ##
640
846
  # Loads ri data for +page_name+
641
847
 
642
- def load_page page_name
848
+ def load_page(page_name)
643
849
  file = page_file page_name
644
850
 
645
851
  obj = marshal_load(file)
@@ -662,7 +868,7 @@ class RDoc::Store
662
868
  ##
663
869
  # Sets the main page for this RDoc store.
664
870
 
665
- def main= page
871
+ def main=(page)
666
872
  @cache[:main] = page
667
873
  end
668
874
 
@@ -670,7 +876,7 @@ class RDoc::Store
670
876
  # Converts the variable => ClassModule map +variables+ from a C parser into
671
877
  # a variable => class name map.
672
878
 
673
- def make_variable_map variables
879
+ def make_variable_map(variables)
674
880
  map = {}
675
881
 
676
882
  variables.each { |variable, class_module|
@@ -683,7 +889,7 @@ class RDoc::Store
683
889
  ##
684
890
  # Path to the ri data for +method_name+ in +klass_name+
685
891
 
686
- def method_file klass_name, method_name
892
+ def method_file(klass_name, method_name)
687
893
  method_name = method_name.split('::').last
688
894
  method_name =~ /#(.*)/
689
895
  method_type = $1 ? 'i' : 'c'
@@ -709,10 +915,10 @@ class RDoc::Store
709
915
  end
710
916
 
711
917
  ##
712
- # Returns the RDoc::TopLevel that is a text file and has the given +name+
918
+ # Returns the RDoc::TopLevel that is a file and has the given +name+
713
919
 
714
- def page name
715
- @text_files_hash.each_value.find do |file|
920
+ def page(name)
921
+ @files_hash.each_value.find do |file|
716
922
  file.page_name == name or file.base_name == name
717
923
  end
718
924
  end
@@ -720,7 +926,7 @@ class RDoc::Store
720
926
  ##
721
927
  # Path to the ri data for +page_name+
722
928
 
723
- def page_file page_name
929
+ def page_file(page_name)
724
930
  file_name = File.basename(page_name).gsub('.', '_')
725
931
 
726
932
  File.join @path, File.dirname(page_name), "page-#{file_name}.ri"
@@ -731,7 +937,7 @@ class RDoc::Store
731
937
  #
732
938
  # See RDoc::Context#remove_from_documentation?
733
939
 
734
- def remove_nodoc all_hash
940
+ def remove_nodoc(all_hash)
735
941
  all_hash.keys.each do |name|
736
942
  context = all_hash[name]
737
943
  all_hash.delete(name) if context.remove_from_documentation?
@@ -751,7 +957,7 @@ class RDoc::Store
751
957
  save_method klass, method
752
958
  end
753
959
 
754
- klass.each_attribute do |attribute|
960
+ klass.attributes.each do |attribute|
755
961
  save_method klass, attribute
756
962
  end
757
963
  end
@@ -793,7 +999,7 @@ class RDoc::Store
793
999
  ##
794
1000
  # Writes the ri data for +klass+ (or module)
795
1001
 
796
- def save_class klass
1002
+ def save_class(klass)
797
1003
  full_name = klass.full_name
798
1004
 
799
1005
  FileUtils.mkdir_p class_path(full_name) unless @dry_run
@@ -867,7 +1073,7 @@ class RDoc::Store
867
1073
  ##
868
1074
  # Writes the ri data for +method+ on +klass+
869
1075
 
870
- def save_method klass, method
1076
+ def save_method(klass, method)
871
1077
  full_name = klass.full_name
872
1078
 
873
1079
  FileUtils.mkdir_p class_path(full_name) unless @dry_run
@@ -890,7 +1096,7 @@ class RDoc::Store
890
1096
  ##
891
1097
  # Writes the ri data for +page+
892
1098
 
893
- def save_page page
1099
+ def save_page(page)
894
1100
  return unless page.text?
895
1101
 
896
1102
  path = page_file page.full_name
@@ -937,7 +1143,7 @@ class RDoc::Store
937
1143
  ##
938
1144
  # Sets the title page for this RDoc store.
939
1145
 
940
- def title= title
1146
+ def title=(title)
941
1147
  @cache[:title] = title
942
1148
  end
943
1149
 
@@ -967,6 +1173,19 @@ class RDoc::Store
967
1173
  end
968
1174
 
969
1175
  private
1176
+
1177
+ def remove_classes_and_modules(cms)
1178
+ cms.each do |cm|
1179
+ remove_classes_and_modules(cm.classes_and_modules)
1180
+
1181
+ if cm.is_a?(RDoc::NormalModule)
1182
+ @modules_hash.delete(cm.full_name)
1183
+ else
1184
+ @classes_hash.delete(cm.full_name)
1185
+ end
1186
+ end
1187
+ end
1188
+
970
1189
  def marshal_load(file)
971
1190
  File.open(file, 'rb') {|io| Marshal.load(io, MarshalFilter)}
972
1191
  end