yard 0.9.45 → 0.9.46

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -0
  3. data/docs/Tags.md +96 -9
  4. data/lib/yard/autoload.rb +4 -0
  5. data/lib/yard/cli/diff.rb +25 -10
  6. data/lib/yard/code_objects/method_object.rb +1 -1
  7. data/lib/yard/code_objects/module_object.rb +4 -3
  8. data/lib/yard/code_objects/namespace_object.rb +7 -5
  9. data/lib/yard/handlers/base.rb +20 -13
  10. data/lib/yard/handlers/c/base.rb +2 -13
  11. data/lib/yard/handlers/processor.rb +9 -1
  12. data/lib/yard/handlers/rbs/alias_handler.rb +25 -0
  13. data/lib/yard/handlers/rbs/attribute_handler.rb +3 -1
  14. data/lib/yard/handlers/rbs/constant_handler.rb +3 -1
  15. data/lib/yard/handlers/rbs/method_handler.rb +13 -3
  16. data/lib/yard/handlers/rbs/mixin_handler.rb +7 -1
  17. data/lib/yard/handlers/rbs/visibility_handler.rb +12 -0
  18. data/lib/yard/handlers/ruby/class_handler.rb +8 -0
  19. data/lib/yard/handlers/ruby/constant_handler.rb +1 -5
  20. data/lib/yard/handlers/ruby/legacy/class_handler.rb +1 -0
  21. data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +1 -1
  22. data/lib/yard/handlers/ruby/struct_handler_methods.rb +13 -0
  23. data/lib/yard/open_struct.rb +5 -0
  24. data/lib/yard/parser/rbs/rbs_parser.rb +78 -26
  25. data/lib/yard/parser/rbs/statement.rb +17 -2
  26. data/lib/yard/parser/ruby/ast_node.rb +2 -1
  27. data/lib/yard/parser/ruby/ruby_parser.rb +14 -9
  28. data/lib/yard/parser/source_parser.rb +38 -3
  29. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +13 -9
  30. data/lib/yard/tags/types_explainer.rb +267 -16
  31. data/lib/yard/templates/helpers/html_helper.rb +49 -39
  32. data/lib/yard/templates/helpers/markup/hybrid_markdown.rb +1 -1
  33. data/lib/yard/version.rb +1 -1
  34. data/templates/default/fulldoc/html/js/app.js +3 -0
  35. data/templates/default/fulldoc/html/js/full_list.js +5 -1
  36. metadata +5 -6
@@ -35,7 +35,7 @@ module YARD
35
35
 
36
36
  def to_s(singular = true)
37
37
  if name[0, 1] =~ /[A-Z]/
38
- singular ? "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} " + name : "#{name}#{name[-1, 1] =~ /[A-Z]/ ? "'" : ''}s"
38
+ singular ? "#{indefinite_article(name)} " + name : "#{name}#{name[-1, 1] =~ /[A-Z]/ ? "'" : ''}s"
39
39
  else
40
40
  name
41
41
  end
@@ -53,6 +53,11 @@ module YARD
53
53
  acc
54
54
  end
55
55
  end
56
+
57
+ # @return ["a", "an"] whichever indefinite article precedes `word`
58
+ def indefinite_article(word)
59
+ word[0, 1] =~ /[aeiou]/i ? "an" : "a"
60
+ end
56
61
  end
57
62
 
58
63
  # @private
@@ -70,23 +75,111 @@ module YARD
70
75
  end
71
76
 
72
77
  # @private
78
+ class IntersectionType < Type
79
+ attr_accessor :types
80
+
81
+ def initialize(types)
82
+ @types = types
83
+ end
84
+
85
+ def to_s(singular = true)
86
+ # A leading "both"/"all of" disambiguates a single value
87
+ # satisfying every listed type from what "a Foo and a Bar" alone
88
+ # could otherwise read as - two separate things.
89
+ prefix = types.size == 2 ? "both " : "all of "
90
+ prefix + list_join(types.map {|t| t.to_s(singular) }, with: "and")
91
+ end
92
+ end
93
+
94
+ # @private
95
+ class GroupType < Type
96
+ attr_accessor :types
97
+
98
+ def initialize(types)
99
+ @types = types
100
+ end
101
+
102
+ def to_s(singular = true)
103
+ "(" + list_join(types.map {|t| disambiguate(t, singular) }) + ")"
104
+ end
105
+
106
+ private
107
+
108
+ # {IntersectionType} and a multi-method {DuckType} (`#foo & #bar`)
109
+ # both render as a bare "X and Y", with no punctuation of their own
110
+ # to mark where they end. Sitting next to a sibling in this group's
111
+ # own "or"-joined list, that reads ambiguously (e.g. "a Foo and a
112
+ # Bar or a Baz" doesn't show whether the "and" or the "or" binds
113
+ # tighter) even though the parse itself is unambiguous. Wrap those
114
+ # two cases in their own parens so the group's members are visually
115
+ # self-delimiting; every other {Type} already is (a bare name, or
116
+ # something with its own bracketing like {GroupType} itself).
117
+ def disambiguate(type, singular)
118
+ rendered = type.to_s(singular)
119
+ needs_parens = type.is_a?(IntersectionType) ||
120
+ (type.is_a?(DuckType) && type.name.include?('&'))
121
+ needs_parens ? "(#{rendered})" : rendered
122
+ end
123
+ end
124
+
125
+ # @private
126
+ #
127
+ # `<...>`'s type parameters are conventionally used two ways - as a
128
+ # homogeneous collection's implicit union of element type(s), or as
129
+ # a class's distinct, positional type parameters, e.g.
130
+ # `Result<Success, Failure>` - and this class renders either way,
131
+ # chosen per instance by {#union?}. This keeps that choice entirely
132
+ # out of the parser: every `<...>` becomes one of these, regardless
133
+ # of name.
73
134
  class CollectionType < Type
74
135
  attr_accessor :types
75
136
 
137
+ # Type names known in advance to be genuinely homogeneous
138
+ # collections, where `<...>`'s type parameters really do mean
139
+ # "any one of these". Fixed and not user-configurable - YARD has
140
+ # no syntax for a class to declare its own `<...>` convention, so
141
+ # this can only ever be a hardcoded, conservative list.
142
+ UNION_COLLECTION_NAMES = %w[Array Set].freeze
143
+
76
144
  def initialize(name, types)
77
145
  @name = name
78
146
  @types = types
79
147
  end
80
148
 
81
149
  def to_s(_singular = true)
82
- "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} #{name} of (" + list_join(types.map {|t| t.to_s(false) }) + ")"
150
+ if union?
151
+ "#{indefinite_article(name)} #{name} of (" + list_join(flattened_types.map {|t| t.to_s(false) }) + ")"
152
+ else
153
+ "#{indefinite_article(name)} #{name} with type parameters (" +
154
+ types.map {|t| t.to_s(true) }.join(", ") + ")"
155
+ end
156
+ end
157
+
158
+ private
159
+
160
+ # A single type parameter is never ambiguous (there's nothing to
161
+ # distinguish a union from a positional type parameter when
162
+ # there's only one), so it's read as a union regardless of name;
163
+ # otherwise, only the known homogeneous-collection names are.
164
+ def union?
165
+ types.size <= 1 || UNION_COLLECTION_NAMES.include?(name)
166
+ end
167
+
168
+ # A parsed type parameter that's itself a union (from `Foo | Bar`
169
+ # in e.g. `Array<Foo | Bar, Baz>`) is a {GroupType}. Since this
170
+ # whole parameter list is already read as one flat union, absorb
171
+ # such a parameter's own members into that same list instead of
172
+ # rendering it as a nested, parenthesized sub-union - the two mean
173
+ # the same thing here.
174
+ def flattened_types
175
+ types.flat_map {|t| t.is_a?(GroupType) ? t.types : [t] }
83
176
  end
84
177
  end
85
178
 
86
179
  # @private
87
180
  class FixedCollectionType < CollectionType
88
181
  def to_s(_singular = true)
89
- "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} #{name} containing (" + types.map(&:to_s).join(" followed by ") + ")"
182
+ "#{indefinite_article(name)} #{name} containing (" + types.map(&:to_s).join(" followed by ") + ")"
90
183
  end
91
184
  end
92
185
 
@@ -134,9 +227,9 @@ module YARD
134
227
  end
135
228
 
136
229
  def to_s(_singular = true)
137
- return "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} #{name}" if @key_value_pairs.empty?
230
+ return "#{indefinite_article(name)} #{name}" if @key_value_pairs.empty?
138
231
 
139
- result = "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} #{name} with "
232
+ result = "#{indefinite_article(name)} #{name} with "
140
233
  parts = @key_value_pairs.map do |keys, values|
141
234
  "keys made of (" + list_join(keys.map {|t| t.to_s(false) }) +
142
235
  ") and values of (" + list_join(values.map {|t| t.to_s(false) }) + ")"
@@ -154,9 +247,13 @@ module YARD
154
247
  :collection_end => />/,
155
248
  :fixed_collection_start => /\(/,
156
249
  :fixed_collection_end => /\)/,
157
- :type_name => /#{ISEP}#{METHODNAMEMATCH}|#{NAMESPACEMATCH}|#{LITERALMATCH}|\w+/,
250
+ :group_start => /\[/,
251
+ :group_end => /\]/,
252
+ :type_name => /#{ISEP}#{METHODNAMEMATCH}|(?:(?:#{NSEPQ}\s*)?_?#{CONSTANTMATCH})+|#{LITERALMATCH}|\w+/,
158
253
  :symbol => /:#{METHODNAMEMATCH}/,
159
254
  :type_next => /[,]/,
255
+ :intersect => /&/,
256
+ :union => /\|/,
160
257
  :whitespace => /\s+/,
161
258
  :hash_collection_start => /\{/,
162
259
  :hash_collection_value => /=>/,
@@ -181,34 +278,90 @@ module YARD
181
278
 
182
279
  private
183
280
 
184
- def parse_until(until_tokens)
281
+ # @param slot_pipe [Boolean] whether `,` separates positional type
282
+ # parameters/slots (a fixed tuple's `(...)`, or a parameterized
283
+ # type's `<...>`), in which case a bare `|` groups alternatives
284
+ # within a single one of them instead of adding another
285
+ # top-level item. False for containers whose whole
286
+ # comma-separated list already means "any of these" (the top
287
+ # level, `{...}`, and `[...]`) - there, `,` and `|` both just add
288
+ # another alternative to that same list.
289
+ #
290
+ # `&` (intersection) is legal anywhere a type is expected (it never
291
+ # needs this distinction), accumulated via
292
+ # `intersection_conjuncts`/{#finish_intersection}, and always
293
+ # binds tighter than whichever separator is active: `A & B, C` is
294
+ # `(A & B), C` everywhere, and `Array(A & B | C, D)` is
295
+ # `Array((A & B) | C, D)` - a 2-slot tuple whose first slot is
296
+ # `(A & B) or C`.
297
+ #
298
+ # `[...]` groups a union (spelled with either `,` or `|`) into a
299
+ # single type usable as one conjunct of an intersection at the
300
+ # top level, where a bare union would otherwise just add another
301
+ # independent top-level item instead: `[A | B] & C` groups `A`
302
+ # and `B` before intersecting with `C`, where `A | B & C` would
303
+ # parse as the two top-level items `A` and `B & C`.
304
+ # @return [Array(Array<Type>, Symbol)] the parsed types and the
305
+ # token that ended the list
306
+ def parse_until(until_tokens, slot_pipe: false)
185
307
  current_parsed_types = []
186
308
  type = nil
187
309
  name = nil
188
310
  finished = false
189
311
  end_token = nil
312
+ intersection_conjuncts = []
313
+ slot_conjuncts = []
190
314
  types = parse_with_handlers do |token_type, token|
191
315
  case token_type
192
316
  when *until_tokens
193
317
  raise SyntaxError, "expecting name, got '#{token}'" if name.nil?
194
318
  type = create_type(name) unless type
195
- current_parsed_types << type
319
+ slot = finish_intersection(intersection_conjuncts, type)
320
+ slot = finish_group(slot_conjuncts, slot) if slot_pipe
321
+ current_parsed_types << slot
322
+ intersection_conjuncts = []
323
+ slot_conjuncts = []
196
324
  finished = true
197
325
  end_token = token_type
198
326
  when :type_name
199
327
  raise SyntaxError, "expecting END, got name '#{token}'" if name
200
328
  name = token
329
+ when :intersect
330
+ raise SyntaxError, "expecting name, got '&' at #{@scanner.pos}" if name.nil?
331
+ type = create_type(name) unless type
332
+ intersection_conjuncts << type
333
+ name = nil
334
+ type = nil
201
335
  when :type_next
202
336
  raise SyntaxError, "expecting name, got '#{token}' at #{@scanner.pos}" if name.nil?
203
337
  type = create_type(name) unless type
204
- current_parsed_types << type
338
+ slot = finish_intersection(intersection_conjuncts, type)
339
+ slot = finish_group(slot_conjuncts, slot) if slot_pipe
340
+ current_parsed_types << slot
341
+ intersection_conjuncts = []
342
+ slot_conjuncts = []
343
+ name = nil
344
+ type = nil
345
+ when :union
346
+ raise SyntaxError, "expecting name, got '|' at #{@scanner.pos}" if name.nil?
347
+ type = create_type(name) unless type
348
+ combined = finish_intersection(intersection_conjuncts, type)
349
+ intersection_conjuncts = []
350
+ if slot_pipe
351
+ slot_conjuncts << combined
352
+ else
353
+ current_parsed_types << combined
354
+ end
205
355
  name = nil
206
356
  type = nil
207
357
  when :fixed_collection_start, :collection_start
208
358
  name ||= "Array"
209
- klass = token_type == :collection_start ? CollectionType : FixedCollectionType
210
- nested_types, = parse_until([:fixed_collection_end, :collection_end, :parse_end])
211
- type = klass.new(name, nested_types)
359
+ type = parse_collection(name, fixed: token_type == :fixed_collection_start)
360
+ when :group_start
361
+ raise SyntaxError, "'[' cannot follow a type name" if name
362
+ nested_types, = parse_until([:group_end, :parse_end])
363
+ type = GroupType.new(nested_types)
364
+ name = "Group"
212
365
  when :hash_collection_start
213
366
  name ||= "Hash"
214
367
  type = parse_hash_collection(name)
@@ -241,17 +394,48 @@ module YARD
241
394
  def parse_hash_collection(name)
242
395
  key_value_pairs = []
243
396
  current_keys = []
397
+ key_name = nil
398
+ key_type = nil
399
+ intersection_conjuncts = []
244
400
  finished = false
245
401
 
402
+ # Finalizes whatever key is pending (if any) into `current_keys`,
403
+ # the same way `parse_until` finalizes a union member - `&` binds
404
+ # tighter than the `,`/`|` (synonyms here, as everywhere outside
405
+ # `(...)`) that separates keys.
406
+ finalize_key = lambda do
407
+ next if key_name.nil?
408
+ key_type = create_type(key_name) unless key_type
409
+ current_keys << finish_intersection(intersection_conjuncts, key_type)
410
+ intersection_conjuncts = []
411
+ key_name = nil
412
+ key_type = nil
413
+ end
414
+
246
415
  parse_with_handlers do |token_type, token|
247
416
  case token_type
248
417
  when :type_name
249
- current_keys << create_type(token)
250
- when :type_next
251
- # Comma - continue collecting keys unless we just processed a value
252
- # In that case, start a new key group
418
+ raise SyntaxError, "expecting END, got name '#{token}'" if key_name
419
+ key_name = token
420
+ when :intersect
421
+ raise SyntaxError, "expecting name, got '&' at #{@scanner.pos}" if key_name.nil?
422
+ key_type = create_type(key_name) unless key_type
423
+ intersection_conjuncts << key_type
424
+ key_name = nil
425
+ key_type = nil
426
+ when :type_next, :union
427
+ # ',' and '|' are synonyms here, as everywhere outside '(...)'
428
+ raise SyntaxError, "expecting name, got '#{token}' at #{@scanner.pos}" if key_name.nil?
429
+ finalize_key.call
430
+ when :fixed_collection_start, :collection_start
431
+ key_name ||= "Array"
432
+ key_type = parse_collection(key_name, fixed: token_type == :fixed_collection_start)
433
+ when :hash_collection_start
434
+ key_name ||= "Hash"
435
+ key_type = parse_hash_collection(key_name)
253
436
  when :hash_collection_value
254
437
  # => - current keys map to the next value(s)
438
+ finalize_key.call
255
439
  raise SyntaxError, "no keys before =>" if current_keys.empty?
256
440
  values, end_token = parse_until([:hash_collection_value_end, :hash_collection_end, :parse_end])
257
441
  key_value_pairs << [current_keys, values]
@@ -270,6 +454,73 @@ module YARD
270
454
 
271
455
  private
272
456
 
457
+ # Parses the type parameters of a `name<...>` or `name(...)` that
458
+ # has just been opened, in either a type list or a hash's keys.
459
+ #
460
+ # Both a fixed tuple's `(...)` and a parameterized type's `<...>`
461
+ # treat `,` as separating positional type parameters, and a bare
462
+ # `|` as grouping alternatives within just one of them
463
+ # (`finish_group`) - parsing doesn't need to know whether `name`
464
+ # means an implicit union. Whether a name's type parameters get
465
+ # described as a union (Array, Set) or neutrally (everything
466
+ # else) is purely a rendering choice, made below.
467
+ #
468
+ # @param name [String] the collection's name
469
+ # @param fixed [Boolean] whether it was opened with `(` rather than `<`
470
+ # @return [Type] the parsed collection type
471
+ def parse_collection(name, fixed:)
472
+ nested_types, = parse_until(
473
+ [:fixed_collection_end, :collection_end, :parse_end], slot_pipe: true
474
+ )
475
+ if fixed
476
+ FixedCollectionType.new(name, nested_types)
477
+ elsif name == "Hash" && nested_types.size == 2
478
+ # `Hash<KeyType, ValueType>` is documented as positional
479
+ # (slot 0 = key type, slot 1 = value type), matching the
480
+ # dedicated `Hash{K=>V}` syntax - not an implicit union.
481
+ HashCollectionType.new(name, [nested_types[0]], [nested_types[1]])
482
+ else
483
+ # Whether these type parameters get described as a union
484
+ # (Array, Set) or neutrally (everything else) doesn't
485
+ # affect parsing, so it's not decided here - see
486
+ # {CollectionType#union?}.
487
+ CollectionType.new(name, nested_types)
488
+ end
489
+ end
490
+
491
+ # Combines the conjuncts of an `A & B & ...` intersection with the
492
+ # final type in the chain. Consecutive duck-types (`#foo & #bar`)
493
+ # collapse into a single {DuckType} listing all of the methods, to
494
+ # match the pre-existing duck-type convention; any other mix of
495
+ # types becomes an {IntersectionType}.
496
+ #
497
+ # @param conjuncts [Array<Type>] the conjuncts seen so far (may be empty)
498
+ # @param last_type [Type] the final conjunct in the chain
499
+ # @return [Type] the combined type for this union slot
500
+ def finish_intersection(conjuncts, last_type)
501
+ return last_type if conjuncts.empty?
502
+ all_types = conjuncts + [last_type]
503
+ if all_types.all? {|t| t.is_a?(DuckType) }
504
+ DuckType.new(all_types.map(&:name).join(' & '))
505
+ else
506
+ IntersectionType.new(all_types)
507
+ end
508
+ end
509
+
510
+ # Combines the `|`-separated conjuncts of one order-dependent-list
511
+ # slot (`A | B` in `Array(A | B, C)`) with the slot's final type
512
+ # into a single {GroupType}, the same representation `[...]`
513
+ # produces - so `Array(A | B, C)` and `Array([A | B], C)` describe
514
+ # the same type.
515
+ #
516
+ # @param conjuncts [Array<Type>] the conjuncts seen so far (may be empty)
517
+ # @param last_type [Type] the final conjunct in the slot
518
+ # @return [Type] the combined type for this slot
519
+ def finish_group(conjuncts, last_type)
520
+ return last_type if conjuncts.empty?
521
+ GroupType.new(conjuncts + [last_type])
522
+ end
523
+
273
524
  def create_type(name)
274
525
  if name[0, 1] == ":" || (name[0, 1] =~ /['"]/ && name[-1, 1] =~ /['"]/)
275
526
  LiteralType.new(name)
@@ -233,47 +233,13 @@ module YARD
233
233
  # @param [String] text the text to resolve links in
234
234
  # @return [String] HTML with linkified references
235
235
  def resolve_links(text)
236
- code_tags = 0
237
- text.gsub(%r{<(/)?(pre|code|tt)|(\\|!)?\{(?!\})(\S+?)(?:\s([^\}]*?\S))?\}(?=\W|.+</|$)}m) do |str|
238
- closed = $1
239
- tag = $2
240
- escape = $3
241
- name = $4
242
- title = $5
243
- match = $&
244
- if tag
245
- code_tags += (closed ? -1 : 1)
246
- next str
247
- end
248
- next str unless code_tags == 0
249
-
250
- next(match[1..-1]) if escape
251
-
252
- next(match) if name[0, 1] == '|'
253
-
254
- if name == '<a' && title =~ %r{href=["'](.+?)["'].*>.*</a>\s*(.*)\Z}
255
- name = $1
256
- title = $2
257
- title = nil if title.empty?
258
- end
259
-
260
- name = CGI.unescapeHTML(name)
261
-
262
- if object.is_a?(String)
263
- object
236
+ text.split(%r{(^[ \t]{0,3}(?:`{3,}|~{3,})[^\n]*\n.*?^[ \t]{0,3}(?:`{3,}|~{3,})[ \t]*(?:\n|\z))}m).map do |part|
237
+ if part =~ %r{\A[ \t]{0,3}(?:`{3,}|~{3,})}m
238
+ part
264
239
  else
265
- link = linkify(name, title)
266
- if (link == name || link == title) && (name + ' ' + link !~ /\A<a\s.*>/)
267
- match = /(.+)?(\{#{Regexp.quote name}(?:\s.*?)?\})(.+)?/.match(text)
268
- file = (defined?(@file) && @file ? @file.filename : object.file) || '(unknown)'
269
- line = (defined?(@file) && @file ? 1 : (object.docstring.line_range ? object.docstring.line_range.first : 1)) + (match ? $`.count("\n") : 0)
270
- log.warn "In file `#{file}':#{line}: Cannot resolve link to #{name} from text" + (match ? ":" : ".") +
271
- "\n\t" + (match[1] ? '...' : '') + match[2].delete("\n") + (match[3] ? '...' : '') if match
272
- end
273
-
274
- link
240
+ resolve_links_in_text(part)
275
241
  end
276
- end
242
+ end.join
277
243
  end
278
244
 
279
245
  # (see BaseHelper#link_file)
@@ -606,6 +572,50 @@ module YARD
606
572
 
607
573
  private
608
574
 
575
+ def resolve_links_in_text(text)
576
+ code_tags = 0
577
+ text.gsub(%r{<(/)?(pre|code|tt)|(\\|!)?\{(?!\})(\S+?)(?:\s([^\}]*?\S))?\}(?=\W|.+</|$)}m) do |str|
578
+ closed = $1
579
+ tag = $2
580
+ escape = $3
581
+ name = $4
582
+ title = $5
583
+ match = $&
584
+ if tag
585
+ code_tags += (closed ? -1 : 1)
586
+ next str
587
+ end
588
+ next str unless code_tags == 0
589
+
590
+ next(match[1..-1]) if escape
591
+
592
+ next(match) if name[0, 1] == '|'
593
+
594
+ if name == '<a' && title =~ %r{href=["'](.+?)["'].*>.*</a>\s*(.*)\Z}
595
+ name = $1
596
+ title = $2
597
+ title = nil if title.empty?
598
+ end
599
+
600
+ name = CGI.unescapeHTML(name)
601
+
602
+ if object.is_a?(String)
603
+ object
604
+ else
605
+ link = linkify(name, title)
606
+ if (link == name || link == title) && (name + ' ' + link !~ /\A<a\s.*>/)
607
+ match = /(.+)?(\{#{Regexp.quote name}(?:\s.*?)?\})(.+)?/.match(text)
608
+ file = (defined?(@file) && @file ? @file.filename : object.file) || '(unknown)'
609
+ line = (defined?(@file) && @file ? 1 : (object.docstring.line_range ? object.docstring.line_range.first : 1)) + (match ? $`.count("\n") : 0)
610
+ log.warn "In file `#{file}':#{line}: Cannot resolve link to #{name} from text" + (match ? ":" : ".") +
611
+ "\n\t" + (match[1] ? '...' : '') + match[2].delete("\n") + (match[3] ? '...' : '') if match
612
+ end
613
+
614
+ link
615
+ end
616
+ end
617
+ end
618
+
609
619
  # Converts a set of hash options into HTML attributes for a tag
610
620
  #
611
621
  # @param [Hash{String => String}] opts the tag options
@@ -555,7 +555,7 @@ module YARD
555
555
  index += 1
556
556
  end
557
557
 
558
- output.gsub(/(^|[\s>])\+([^\s+\n](?:[^+\n]*?[^\s+\n])?)\+(?=$|[\s<.,;:!?)]|\z)/) do
558
+ output.gsub(/(^|[\s>])\+([^\s+](?:[^+\n]*?[^\s+])?)\+(?=$|[\s<.,;:!?)]|\z)/) do
559
559
  prefix = $1
560
560
  prefix + store_placeholder(placeholders, "<code>#{h(restore_placeholders($2, placeholders))}</code>")
561
561
  end
data/lib/yard/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module YARD
5
- VERSION = '0.9.45'
5
+ VERSION = '0.9.46'
6
6
  end
@@ -144,6 +144,9 @@
144
144
 
145
145
  function createSourceLinks() {
146
146
  queryAll(".method_details_list .source_code").forEach((sourceCode) => {
147
+ if (sourceCode.previousElementSibling?.classList.contains("showSource"))
148
+ return;
149
+
147
150
  const toggleWrapper = document.createElement("span");
148
151
  const link = document.createElement("a");
149
152
 
@@ -2,6 +2,7 @@
2
2
  let clicked = null;
3
3
  let searchTimeout = null;
4
4
  const searchCache = [];
5
+ let lastSearchString = null;
5
6
  let caseSensitiveMatch = false;
6
7
 
7
8
  function query(selector, root) {
@@ -166,6 +167,7 @@
166
167
  }
167
168
 
168
169
  function clearSearch() {
170
+ lastSearchString = null;
169
171
  clearSearchTimeout();
170
172
  queryAll("#full_list .found").forEach((node) => {
171
173
  node.classList.remove("found");
@@ -184,6 +186,8 @@
184
186
  }
185
187
 
186
188
  function performSearch(searchString) {
189
+ if (searchString === lastSearchString) return;
190
+ lastSearchString = searchString;
187
191
  clearSearchTimeout();
188
192
  query("#full_list").classList.add("insearch");
189
193
  query("#content").classList.add("insearch");
@@ -229,7 +233,7 @@
229
233
  }
230
234
 
231
235
  function searchDone() {
232
- const found = queryAll("#full_list li").filter(isVisible).length;
236
+ const found = queryAll("#full_list .found").length;
233
237
 
234
238
  searchTimeout = null;
235
239
  highlight();
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.45
4
+ version: 0.9.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loren Segal
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-07-14 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: |2
14
13
  YARD is a documentation generation tool for the Ruby programming language.
@@ -115,12 +114,14 @@ files:
115
114
  - lib/yard/handlers/c/symbol_handler.rb
116
115
  - lib/yard/handlers/common/method_handler.rb
117
116
  - lib/yard/handlers/processor.rb
117
+ - lib/yard/handlers/rbs/alias_handler.rb
118
118
  - lib/yard/handlers/rbs/attribute_handler.rb
119
119
  - lib/yard/handlers/rbs/base.rb
120
120
  - lib/yard/handlers/rbs/constant_handler.rb
121
121
  - lib/yard/handlers/rbs/method_handler.rb
122
122
  - lib/yard/handlers/rbs/mixin_handler.rb
123
123
  - lib/yard/handlers/rbs/namespace_handler.rb
124
+ - lib/yard/handlers/rbs/visibility_handler.rb
124
125
  - lib/yard/handlers/ruby/alias_handler.rb
125
126
  - lib/yard/handlers/ruby/attribute_handler.rb
126
127
  - lib/yard/handlers/ruby/base.rb
@@ -410,7 +411,6 @@ metadata:
410
411
  yard.run: yri
411
412
  changelog_uri: https://rubydoc.info/gems/yard/file/CHANGELOG.md
412
413
  source_code_uri: https://github.com/lsegal/yard
413
- post_install_message:
414
414
  rdoc_options: []
415
415
  require_paths:
416
416
  - lib
@@ -425,8 +425,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
425
425
  - !ruby/object:Gem::Version
426
426
  version: '0'
427
427
  requirements: []
428
- rubygems_version: 3.4.20
429
- signing_key:
428
+ rubygems_version: 3.6.7
430
429
  specification_version: 4
431
430
  summary: Documentation tool for consistent and usable documentation in Ruby.
432
431
  test_files: []