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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +57 -0
- data/docs/Tags.md +96 -9
- data/lib/yard/autoload.rb +4 -0
- data/lib/yard/cli/diff.rb +25 -10
- data/lib/yard/code_objects/method_object.rb +1 -1
- data/lib/yard/code_objects/module_object.rb +4 -3
- data/lib/yard/code_objects/namespace_object.rb +7 -5
- data/lib/yard/handlers/base.rb +20 -13
- data/lib/yard/handlers/c/base.rb +2 -13
- data/lib/yard/handlers/processor.rb +9 -1
- data/lib/yard/handlers/rbs/alias_handler.rb +25 -0
- data/lib/yard/handlers/rbs/attribute_handler.rb +3 -1
- data/lib/yard/handlers/rbs/constant_handler.rb +3 -1
- data/lib/yard/handlers/rbs/method_handler.rb +13 -3
- data/lib/yard/handlers/rbs/mixin_handler.rb +7 -1
- data/lib/yard/handlers/rbs/visibility_handler.rb +12 -0
- data/lib/yard/handlers/ruby/class_handler.rb +8 -0
- data/lib/yard/handlers/ruby/constant_handler.rb +1 -5
- data/lib/yard/handlers/ruby/legacy/class_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +1 -1
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +13 -0
- data/lib/yard/open_struct.rb +5 -0
- data/lib/yard/parser/rbs/rbs_parser.rb +78 -26
- data/lib/yard/parser/rbs/statement.rb +17 -2
- data/lib/yard/parser/ruby/ast_node.rb +2 -1
- data/lib/yard/parser/ruby/ruby_parser.rb +14 -9
- data/lib/yard/parser/source_parser.rb +38 -3
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +13 -9
- data/lib/yard/tags/types_explainer.rb +267 -16
- data/lib/yard/templates/helpers/html_helper.rb +49 -39
- data/lib/yard/templates/helpers/markup/hybrid_markdown.rb +1 -1
- data/lib/yard/version.rb +1 -1
- data/templates/default/fulldoc/html/js/app.js +3 -0
- data/templates/default/fulldoc/html/js/full_list.js +5 -1
- metadata +5 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0bd148f151a06412b39192381cd3854b8ee0ba7c7017bb4c10f8512668e02f1d
|
|
4
|
+
data.tar.gz: 910b9fe9065d2674d985f1abc1c7f12444aa7157ae418fe44cda24787cdedf91
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6c30cd815a55a15586b67d9bd30037f229913b3aeb890788e4c016527d20f443bafe27787cd05360b66b1d111c8a30e73e3ac25fb592b3c7831af6e23b245985
|
|
7
|
+
data.tar.gz: 8d65ea35ba1a0356ea7c5ad4fefd57b99ae2f4b895a5bb8ccf3717c72d515562e08b8108ebfab8019407e99a245abea154af3831fffdccc4517f25dde02aafd4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,62 @@
|
|
|
1
1
|
# main
|
|
2
2
|
|
|
3
|
+
# [0.9.46] - November 26th, 2026
|
|
4
|
+
|
|
5
|
+
[0.9.46]: https://github.com/lsegal/yard/compare/v0.9.45...v0.9.46
|
|
6
|
+
|
|
7
|
+
- Fix gem archive path traversal in `yard diff`. Reported by Shopify
|
|
8
|
+
(@oss-security-shopify).
|
|
9
|
+
[GHSA-r86q-p7r5-qcmh](https://github.com/lsegal/yard/security/advisories/GHSA-r86q-p7r5-qcmh)
|
|
10
|
+
- Use the browser's current URL to poll for documentation while a library builds.
|
|
11
|
+
Reported by zx (@manus-pi).
|
|
12
|
+
- Fix the search result count in the file and class lists, and the first click
|
|
13
|
+
on a search result being lost when the search field loses focus (#1736)
|
|
14
|
+
- Fix type parser rejecting namespaced RBS interface names such as
|
|
15
|
+
`Asana::Client::_Projects` (#1735)
|
|
16
|
+
- Fix stack overflow when a module's mixins form a cycle
|
|
17
|
+
- Register RBS method aliases
|
|
18
|
+
- Register RBS class and module aliases (`class Foo = Bar`) as constants
|
|
19
|
+
- Support RBS visibility modifiers, `private` sections and `self?` methods
|
|
20
|
+
- Support RBS method signatures that span several lines
|
|
21
|
+
- Fix RBS `include`, `extend` and `prepend` keeping type arguments in the mixin name
|
|
22
|
+
- Fix RBS parser not closing a namespace at an `end` followed by an inline
|
|
23
|
+
comment, which nested every later declaration one level too deep (#1723)
|
|
24
|
+
- Fix stack overflow when many files reference namespaces defined in later files (#1375).
|
|
25
|
+
A handler that calls `Handlers::Base#ensure_loaded!` on an unresolved object is now
|
|
26
|
+
deferred and run again from the start once all files are parsed, instead of parsing
|
|
27
|
+
the remaining files recursively. The `max_retries` argument to `ensure_loaded!` and
|
|
28
|
+
`Handlers::C::Base#ensure_variable_defined!` is deprecated and ignored.
|
|
29
|
+
- Add support for intersection (`Foo & Bar`) types: a value must satisfy
|
|
30
|
+
every type listed, rather than any one of them, reading as "both a Foo
|
|
31
|
+
and a Bar" (or "all of a Foo, a Bar, and a Baz" for 3+) to avoid reading
|
|
32
|
+
like two separate values (closes #1644)
|
|
33
|
+
- Add `|` as a union operator (`Foo | Bar` means an object that's either a
|
|
34
|
+
Foo or a Bar). Type lists that already mean a union - the top level, a
|
|
35
|
+
hash's key/value lists, `Array<...>`/`Set<...>` - read `,` and `|` the
|
|
36
|
+
same way; elsewhere, where a comma-separated list means distinct type
|
|
37
|
+
parameters or tuple slots (`Array(...)`, or `<...>` for a name other
|
|
38
|
+
than `Array`/`Set`), `|` groups a union within a single one of them
|
|
39
|
+
(closes #1699)
|
|
40
|
+
- Add `[...]`, used the same way parentheses are in algebra: to override
|
|
41
|
+
the default order of operations, e.g. to use a union as one conjunct of
|
|
42
|
+
an intersection (closes #1699)
|
|
43
|
+
- Document the existing anonymous `<A>`, `(A)`, and `{A=>B}` shorthand forms
|
|
44
|
+
- Stop assuming `Foo<A, B>` always means "A or B": only `Array`/`Set` (known
|
|
45
|
+
homogeneous collections) keep that implicit-union reading; any other
|
|
46
|
+
name with 2+ type parameters now reads neutrally as "with type
|
|
47
|
+
parameters (A, B)", since `<...>` is also conventionally used for a
|
|
48
|
+
class's distinct type parameters (e.g. `Result<Success, Failure>`).
|
|
49
|
+
`Hash<KeyType, ValueType>` gets its own dedicated positional rendering,
|
|
50
|
+
matching `Hash{KeyType=>ValueType}`
|
|
51
|
+
- Fix spurious "Cannot resolve link" warnings for braces inside fenced code
|
|
52
|
+
blocks nested in HTML blocks (e.g. `<details>`) in Markdown files (#1706)
|
|
53
|
+
- Fix RBS method tags for signatures with type parameters or an optional block
|
|
54
|
+
- Fix TypesExplainer parsing of nested collection types in Hash key position
|
|
55
|
+
- Fix duplicate "View source" links after client-side navigation in default HTML template
|
|
56
|
+
- Fix duplicated character class range warning in HybridMarkdown
|
|
57
|
+
- Fix quadratic parsing slowdown on source files containing very large literals
|
|
58
|
+
- Send XHR requests from processing template
|
|
59
|
+
|
|
3
60
|
# [0.9.45] - July 14th, 2026
|
|
4
61
|
|
|
5
62
|
[0.9.45]: https://github.com/lsegal/yard/compare/v0.9.44...v0.9.45
|
data/docs/Tags.md
CHANGED
|
@@ -169,18 +169,29 @@ Note that one extra type that is accepted by convention is the `Boolean` type,
|
|
|
169
169
|
which represents both the `TrueClass` and `FalseClass` types. This type does not
|
|
170
170
|
exist in Ruby, however.
|
|
171
171
|
|
|
172
|
-
####
|
|
172
|
+
#### Parameterized Types
|
|
173
173
|
|
|
174
174
|
In addition to basic types (like String or Array), YARD conventions allow for
|
|
175
|
-
a "generics" like syntax to specify container objects or other
|
|
175
|
+
a "generics" like syntax to specify container objects or other parameterized types.
|
|
176
176
|
The syntax is `Type<SubType, OtherSubType, ...>`. For instance, an Array might
|
|
177
177
|
contain only String objects, in which case the type specification would be
|
|
178
|
-
`Array<String>`. Multiple
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
178
|
+
`Array<String>`. Multiple type parameters can be listed, separated by commas:
|
|
179
|
+
`Array<String, Fixnum>` can contain any amount of Strings or Fixnums, in any
|
|
180
|
+
order - `Array` and `Set` both treat their type parameters as an implicit
|
|
181
|
+
union, meaning "any of these".
|
|
182
|
+
|
|
183
|
+
The type name before `<...>` can be omitted, in which case it defaults to
|
|
184
|
+
`Array`: `<String, Fixnum>` means the same thing as `Array<String, Fixnum>`.
|
|
185
|
+
|
|
186
|
+
Not every type uses its parameters this way, though: `Result<Success, Failure>`
|
|
187
|
+
uses `Success` and `Failure` as two distinct type parameters, not "either of
|
|
188
|
+
these". A type with a single parameter is unambiguous either way. For a name
|
|
189
|
+
that isn't specifically known to mean a union, YARD describes its
|
|
190
|
+
parameters neutrally, without asserting either reading:
|
|
191
|
+
`Result<Success, Failure>` reads as "a Result with type parameters (a
|
|
192
|
+
Success, a Failure)". `Hash<KeyType, ValueType>` is a special case with its
|
|
193
|
+
own dedicated positional rendering (slot 1 is the key type, slot 2 is the
|
|
194
|
+
value type), matching the `Hash{KeyType=>ValueType}` syntax described below.
|
|
184
195
|
|
|
185
196
|
#### Duck-Types
|
|
186
197
|
|
|
@@ -194,9 +205,24 @@ that responds to the "read" method:
|
|
|
194
205
|
# @param io [#read] the input object to read from
|
|
195
206
|
def read(io) io.read end
|
|
196
207
|
|
|
208
|
+
#### Intersection Types
|
|
209
|
+
|
|
210
|
+
Types joined with `&` describe an intersection: a value that satisfies every
|
|
211
|
+
type listed, rather than any one of them (which is what a union - the `|`
|
|
212
|
+
operator - already means). For instance, an argument that must both
|
|
213
|
+
inherit from `Foo` and respond to `#bar` would be listed as `Foo & #bar`.
|
|
214
|
+
|
|
215
|
+
# Accepts any Comparable string.
|
|
216
|
+
# @param value [String & Comparable] the value to accept
|
|
217
|
+
def accept(value) end
|
|
218
|
+
|
|
219
|
+
`&` is legal in every position a type can appear, and always binds tighter
|
|
220
|
+
than any union or slot separator around it - see
|
|
221
|
+
[Operator Precedence](#Operator_Precedence) below.
|
|
222
|
+
|
|
197
223
|
#### Hashes
|
|
198
224
|
|
|
199
|
-
Hashes can be specified either via the
|
|
225
|
+
Hashes can be specified either via the parameterized type discussed above,
|
|
200
226
|
in the form `Hash<KeyType, ValueType>`, or using the hash specific syntax:
|
|
201
227
|
`Hash{KeyTypes=>ValueTypes}`. In the latter case, KeyTypes or ValueTypes can
|
|
202
228
|
also be a list of types separated by commas.
|
|
@@ -222,6 +248,9 @@ Keys in the hash-specific syntax are commonly [literal values](#Literals) such
|
|
|
222
248
|
as symbols (`:key`) or strings (`'key'`, `"key"`), but any type listed in the
|
|
223
249
|
[type conventions](#Type_List_Conventions) is allowed.
|
|
224
250
|
|
|
251
|
+
The type name before `{...}` can be omitted, in which case it defaults to
|
|
252
|
+
`Hash`: `{K=>V}` means the same thing as `Hash{K=>V}`.
|
|
253
|
+
|
|
225
254
|
#### Order-Dependent Lists
|
|
226
255
|
|
|
227
256
|
An order dependent list is a set of types surrounded by "()" and separated by
|
|
@@ -229,6 +258,64 @@ commas. This list must contain exactly those types in exactly the order specifie
|
|
|
229
258
|
For instance, an Array containing a String, Fixnum and Hash in that order (and
|
|
230
259
|
having exactly those 3 elements) would be listed as: `Array(String, Fixnum, Hash)`.
|
|
231
260
|
|
|
261
|
+
The type name before `(...)` can be omitted, in which case it defaults to
|
|
262
|
+
`Array`: `(String, Fixnum, Hash)` means the same thing as
|
|
263
|
+
`Array(String, Fixnum, Hash)`.
|
|
264
|
+
|
|
265
|
+
A single slot can itself be a union: `Array(Integer | String, Symbol)` is a
|
|
266
|
+
2-element Array whose first element is an Integer or a String - see
|
|
267
|
+
[Union Operator](#Union_Operator) below.
|
|
268
|
+
|
|
269
|
+
#### Union Operator
|
|
270
|
+
|
|
271
|
+
`|` marks a union: a value matching any of the listed types.
|
|
272
|
+
`Integer | String` means an Integer or a String.
|
|
273
|
+
|
|
274
|
+
Some type lists already mean a union without `|` - a plain comma-separated
|
|
275
|
+
list at the top level, a hash's key or value list, inside `[...]`
|
|
276
|
+
(described below), and inside `Array<...>`/`Set<...>`. In those places `,`
|
|
277
|
+
and `|` come to the same thing, so use whichever reads better:
|
|
278
|
+
`Integer, String` and `Integer | String` describe the same type.
|
|
279
|
+
|
|
280
|
+
Elsewhere, each comma-separated item is a distinct, positional type
|
|
281
|
+
parameter instead - a fixed-order list like `Array(...)`, or `<...>` for a
|
|
282
|
+
type other than `Array`/`Set` (see
|
|
283
|
+
[Parameterized Types](#Parameterized_Types) above). There, use `|` within a
|
|
284
|
+
single item to say it can be any of several types:
|
|
285
|
+
`Array(Integer | String, Symbol)` is a 2-element Array whose first element
|
|
286
|
+
is an Integer or a String, and `Result<Success | Failure, Other>` is a
|
|
287
|
+
Result whose first type parameter is a Success or a Failure.
|
|
288
|
+
|
|
289
|
+
#### Operator Precedence
|
|
290
|
+
|
|
291
|
+
`&`, `,`, and `|` can all appear in the same type, and `&` always binds
|
|
292
|
+
tighter than the union or slot separator around it: `Foo & Bar, Baz` means
|
|
293
|
+
either both a Foo and a Bar, or a Baz - not `Foo`, unioned with `Bar & Baz`.
|
|
294
|
+
|
|
295
|
+
#### Overriding the Order of Operations
|
|
296
|
+
|
|
297
|
+
Square brackets `[...]` are used the same way parentheses are in algebra:
|
|
298
|
+
to override the order of operations described above. Types inside `[...]`
|
|
299
|
+
are combined first; hence `[Foo | Bar] & Baz` describes a value that's
|
|
300
|
+
either a Foo or a Bar, and also a Baz - not `Foo`, unioned with
|
|
301
|
+
`Bar & Baz`. Without the brackets, `&` binds tighter than the union
|
|
302
|
+
around it, so `Foo | Bar & Baz` means the latter.
|
|
303
|
+
|
|
304
|
+
Inside `[...]`, `,` and `|` both mean a union, so `[Foo, Bar]` and
|
|
305
|
+
`[Foo | Bar]` describe the same type.
|
|
306
|
+
|
|
307
|
+
<p class="note">
|
|
308
|
+
While you can treat them the same in practice, this <code>[...]</code> is
|
|
309
|
+
not the same thing as the <code>[Types]</code> brackets that delimit a
|
|
310
|
+
tag's whole <a href="#Types_Specifier_List">types specifier list</a> -
|
|
311
|
+
that outer bracket is tag punctuation, not part of any individual type.
|
|
312
|
+
</p>
|
|
313
|
+
|
|
314
|
+
`[...]` never takes a preceding type name - `[Integer | String]` alone
|
|
315
|
+
just means "an Integer or a String," identical in meaning to the plain
|
|
316
|
+
top-level list `Integer, String`, just usable in more places. It can nest
|
|
317
|
+
inside itself (`[[Foo | Bar] | Baz]`).
|
|
318
|
+
|
|
232
319
|
#### Literals
|
|
233
320
|
|
|
234
321
|
Some literals are accepted by virtue of being Ruby literals, but also by YARD
|
data/lib/yard/autoload.rb
CHANGED
|
@@ -72,11 +72,13 @@ module YARD
|
|
|
72
72
|
# RBS type signature handlers
|
|
73
73
|
module RBS
|
|
74
74
|
autoload :Base, __p('handlers/rbs/base')
|
|
75
|
+
autoload :AliasHandler, __p('handlers/rbs/alias_handler')
|
|
75
76
|
autoload :AttributeHandler, __p('handlers/rbs/attribute_handler')
|
|
76
77
|
autoload :ConstantHandler, __p('handlers/rbs/constant_handler')
|
|
77
78
|
autoload :MethodHandler, __p('handlers/rbs/method_handler')
|
|
78
79
|
autoload :MixinHandler, __p('handlers/rbs/mixin_handler')
|
|
79
80
|
autoload :NamespaceHandler, __p('handlers/rbs/namespace_handler')
|
|
81
|
+
autoload :VisibilityHandler, __p('handlers/rbs/visibility_handler')
|
|
80
82
|
end
|
|
81
83
|
|
|
82
84
|
# CRuby Handlers
|
|
@@ -152,6 +154,7 @@ module YARD
|
|
|
152
154
|
|
|
153
155
|
autoload :Base, __p('handlers/base')
|
|
154
156
|
autoload :HandlerAborted, __p('handlers/base')
|
|
157
|
+
autoload :HandlerDeferred, __p('handlers/base')
|
|
155
158
|
autoload :NamespaceMissingError, __p('handlers/base')
|
|
156
159
|
autoload :Processor, __p('handlers/processor')
|
|
157
160
|
end
|
|
@@ -201,6 +204,7 @@ module YARD
|
|
|
201
204
|
|
|
202
205
|
autoload :Base, __p('parser/base')
|
|
203
206
|
autoload :ParserSyntaxError, __p('parser/source_parser')
|
|
207
|
+
autoload :OrderedParser, __p('parser/source_parser')
|
|
204
208
|
autoload :SourceParser, __p('parser/source_parser')
|
|
205
209
|
autoload :UndocumentableError, __p('parser/source_parser')
|
|
206
210
|
end
|
data/lib/yard/cli/diff.rb
CHANGED
|
@@ -178,9 +178,11 @@ module YARD
|
|
|
178
178
|
end
|
|
179
179
|
|
|
180
180
|
def expand_and_parse(gemfile, io)
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
Dir.mktmpdir('yard-diff-') do |dir|
|
|
182
|
+
log.info "Expanding #{gemfile} to #{dir}..."
|
|
183
|
+
expand_gem(io, File.realpath(dir))
|
|
184
|
+
generate_yardoc(dir)
|
|
185
|
+
end
|
|
184
186
|
end
|
|
185
187
|
|
|
186
188
|
def generate_yardoc(dir)
|
|
@@ -189,11 +191,7 @@ module YARD
|
|
|
189
191
|
end
|
|
190
192
|
end
|
|
191
193
|
|
|
192
|
-
def expand_gem(
|
|
193
|
-
tmpdir = File.join(Dir.tmpdir, gemfile)
|
|
194
|
-
FileUtils.mkdir_p(tmpdir)
|
|
195
|
-
log.info "Expanding #{gemfile} to #{tmpdir}..."
|
|
196
|
-
|
|
194
|
+
def expand_gem(io, tmpdir)
|
|
197
195
|
if Gem::VERSION >= '2.0.0'
|
|
198
196
|
require 'rubygems/package/tar_reader'
|
|
199
197
|
reader = Gem::Package::TarReader.new(io)
|
|
@@ -202,7 +200,8 @@ module YARD
|
|
|
202
200
|
Zlib::GzipReader.wrap(pkg) do |gzio|
|
|
203
201
|
tar = Gem::Package::TarReader.new(gzio)
|
|
204
202
|
tar.each do |entry|
|
|
205
|
-
|
|
203
|
+
next unless entry.file?
|
|
204
|
+
file = gem_entry_path(tmpdir, entry.full_name)
|
|
206
205
|
FileUtils.mkdir_p(File.dirname(file))
|
|
207
206
|
File.open(file, 'wb') do |out|
|
|
208
207
|
out.write(entry.read)
|
|
@@ -223,8 +222,24 @@ module YARD
|
|
|
223
222
|
end
|
|
224
223
|
end
|
|
225
224
|
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def gem_entry_path(root, name)
|
|
228
|
+
if name =~ %r{\A(?:[/\\]|[a-z]:)}i
|
|
229
|
+
raise Gem::Package::PathError.new(name, root)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
if File::ALT_SEPARATOR
|
|
233
|
+
# Windows aliases paths with trailing dots or spaces and treats colons as streams.
|
|
234
|
+
components = name.split(%r{[/\\]})
|
|
235
|
+
if components.any? {|part| part != '.' && part != '..' && part =~ /:|[. ]\z/ }
|
|
236
|
+
raise Gem::Package::PathError.new(name, root)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
226
239
|
|
|
227
|
-
|
|
240
|
+
path = File.expand_path(File.join(root, name))
|
|
241
|
+
raise Gem::Package::PathError.new(name, root) unless path.start_with?(root + '/')
|
|
242
|
+
path
|
|
228
243
|
end
|
|
229
244
|
|
|
230
245
|
def require_rubygems
|
|
@@ -31,7 +31,7 @@ module YARD::CodeObjects
|
|
|
31
31
|
# method in +:class+ scope, but also creates a new (empty) method
|
|
32
32
|
# as a private +:instance+ method on the same class or module.
|
|
33
33
|
#
|
|
34
|
-
# @param [NamespaceObject] namespace the namespace
|
|
34
|
+
# @param [NamespaceObject, :root, nil] namespace the namespace
|
|
35
35
|
# @param [String, Symbol] name the method name
|
|
36
36
|
# @param [Symbol] scope +:instance+, +:class+, or +:module+
|
|
37
37
|
def initialize(namespace, name, scope = :instance, &block)
|
|
@@ -9,12 +9,13 @@ module YARD::CodeObjects
|
|
|
9
9
|
# @param [Boolean] include_mods if true, will include mixed in
|
|
10
10
|
# modules (which is likely what is wanted).
|
|
11
11
|
# @return [Array<NamespaceObject>] a list of namespace objects
|
|
12
|
-
def inheritance_tree(include_mods = false)
|
|
12
|
+
def inheritance_tree(include_mods = false, visited = [])
|
|
13
13
|
return [self] unless include_mods
|
|
14
|
+
visited += [self]
|
|
14
15
|
[self] + mixins(:instance, :class).map do |m|
|
|
15
|
-
next if m
|
|
16
|
+
next if visited.include?(m)
|
|
16
17
|
next m unless m.respond_to?(:inheritance_tree)
|
|
17
|
-
m.inheritance_tree(true)
|
|
18
|
+
m.is_a?(ModuleObject) ? m.inheritance_tree(true, visited) : m.inheritance_tree(true)
|
|
18
19
|
end.compact.flatten.uniq
|
|
19
20
|
end
|
|
20
21
|
end
|
|
@@ -38,9 +38,9 @@ module YARD::CodeObjects
|
|
|
38
38
|
# @return [Hash] a list of methods
|
|
39
39
|
attr_reader :attributes
|
|
40
40
|
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
# @return [Hash]
|
|
41
|
+
# Maps alias method objects to the names of the methods they alias.
|
|
42
|
+
# Class and instance aliases share this hash; each key records its scope.
|
|
43
|
+
# @return [Hash{MethodObject => Symbol}] alias methods mapped to their target names
|
|
44
44
|
attr_reader :aliases
|
|
45
45
|
|
|
46
46
|
# Class mixins
|
|
@@ -143,10 +143,12 @@ module YARD::CodeObjects
|
|
|
143
143
|
# @see #meths
|
|
144
144
|
def included_meths(opts = {})
|
|
145
145
|
opts = SymbolHash[:scope => [:instance, :class]].update(opts)
|
|
146
|
+
# Mixins already being expanded further up, so include cycles terminate.
|
|
147
|
+
visited = (opts[:visited] || []) + [self]
|
|
146
148
|
[opts[:scope]].flatten.map do |scope|
|
|
147
149
|
mixins(scope).inject([]) do |list, mixin|
|
|
148
|
-
next list if mixin.is_a?(Proxy)
|
|
149
|
-
arr = mixin.meths(opts.merge(:scope => :instance)).reject do |o|
|
|
150
|
+
next list if mixin.is_a?(Proxy) || visited.include?(mixin)
|
|
151
|
+
arr = mixin.meths(opts.merge(:scope => :instance, :visited => visited)).reject do |o|
|
|
150
152
|
next false if opts[:all]
|
|
151
153
|
child(:name => o.name, :scope => scope) || list.find {|o2| o2.name == o.name }
|
|
152
154
|
end
|
data/lib/yard/handlers/base.rb
CHANGED
|
@@ -7,6 +7,13 @@ module YARD
|
|
|
7
7
|
# @since 0.8.4
|
|
8
8
|
class HandlerAborted < ::RuntimeError; end
|
|
9
9
|
|
|
10
|
+
# Raised by {Base#ensure_loaded!} when a handler cannot complete until
|
|
11
|
+
# the remaining files in the {Parser::OrderedParser} have been parsed.
|
|
12
|
+
# The {Processor} silences the exception and processes the handler
|
|
13
|
+
# again once all files have been parsed.
|
|
14
|
+
# @see Processor#process
|
|
15
|
+
class HandlerDeferred < ::RuntimeError; end
|
|
16
|
+
|
|
10
17
|
# Raised during processing phase when a handler needs to perform
|
|
11
18
|
# an operation on an object's namespace but the namespace could
|
|
12
19
|
# not be resolved.
|
|
@@ -566,8 +573,9 @@ module YARD
|
|
|
566
573
|
# in a file that has not been handled).
|
|
567
574
|
#
|
|
568
575
|
# Calling this method defers the handler until all other files have been
|
|
569
|
-
# processed
|
|
570
|
-
#
|
|
576
|
+
# processed, at which point the handler is processed again from the
|
|
577
|
+
# beginning (see {Processor#process}). If the object cannot be
|
|
578
|
+
# resolved once all files have been processed, an exception is raised.
|
|
571
579
|
#
|
|
572
580
|
# @example Adding a mixin to the String class programmatically
|
|
573
581
|
# ensure_loaded! P('String')
|
|
@@ -575,23 +583,22 @@ module YARD
|
|
|
575
583
|
# P('String').mixins << P('MyMixin')
|
|
576
584
|
#
|
|
577
585
|
# @param [Proxy, CodeObjects::Base] object the object to resolve.
|
|
578
|
-
# @param [Integer] max_retries
|
|
579
|
-
#
|
|
580
|
-
# @raise [
|
|
581
|
-
#
|
|
582
|
-
#
|
|
586
|
+
# @param [Integer] max_retries deprecated and ignored. The handler is
|
|
587
|
+
# deferred until +object+ is resolved or no more objects can be resolved.
|
|
588
|
+
# @raise [HandlerDeferred] if the handler was deferred. This exception
|
|
589
|
+
# is silenced by the {Processor}.
|
|
590
|
+
# @raise [NamespaceMissingError] if the object cannot be resolved, this
|
|
591
|
+
# exception is raised and the handler finishes processing.
|
|
583
592
|
def ensure_loaded!(object, max_retries = 1)
|
|
584
593
|
return if object.root?
|
|
585
594
|
return object unless object.is_a?(Proxy)
|
|
586
595
|
|
|
587
|
-
|
|
588
|
-
while object.is_a?(Proxy)
|
|
589
|
-
raise NamespaceMissingError, object if retries > max_retries
|
|
596
|
+
if globals.ordered_parser && globals.ordered_parser.deferring?
|
|
590
597
|
log.debug "Missing object #{object} in file `#{parser.file}', moving it to the back of the line."
|
|
591
|
-
|
|
592
|
-
retries += 1
|
|
598
|
+
raise HandlerDeferred
|
|
593
599
|
end
|
|
594
|
-
|
|
600
|
+
|
|
601
|
+
raise NamespaceMissingError, object
|
|
595
602
|
end
|
|
596
603
|
|
|
597
604
|
# @group Macro Support
|
data/lib/yard/handlers/c/base.rb
CHANGED
|
@@ -75,19 +75,8 @@ module YARD
|
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def ensure_variable_defined!(var, max_retries = 1)
|
|
78
|
-
|
|
79
|
-
object
|
|
80
|
-
|
|
81
|
-
loop do
|
|
82
|
-
object = namespace_for_variable(var)
|
|
83
|
-
break unless object.is_a?(Proxy)
|
|
84
|
-
|
|
85
|
-
raise NamespaceMissingError, object if retries > max_retries
|
|
86
|
-
log.debug "Missing namespace variable #{var} in file `#{parser.file}', moving it to the back of the line."
|
|
87
|
-
parser.parse_remaining_files
|
|
88
|
-
retries += 1
|
|
89
|
-
end
|
|
90
|
-
|
|
78
|
+
object = namespace_for_variable(var)
|
|
79
|
+
ensure_loaded!(object, max_retries) if object.is_a?(Proxy)
|
|
91
80
|
object
|
|
92
81
|
end
|
|
93
82
|
|
|
@@ -103,7 +103,9 @@ module YARD
|
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
# Processes a list of statements by finding handlers to process each
|
|
106
|
-
# one.
|
|
106
|
+
# one. A handler that raises {HandlerDeferred} is processed again, with
|
|
107
|
+
# a copy of the current state, once the {Parser::OrderedParser} has
|
|
108
|
+
# parsed all files.
|
|
107
109
|
#
|
|
108
110
|
# @param [Array] statements a list of statements
|
|
109
111
|
# @return [void]
|
|
@@ -112,6 +114,12 @@ module YARD
|
|
|
112
114
|
find_handlers(stmt).each do |handler|
|
|
113
115
|
begin
|
|
114
116
|
handler.new(self, stmt).process
|
|
117
|
+
rescue HandlerDeferred
|
|
118
|
+
if globals.ordered_parser
|
|
119
|
+
copy = dup
|
|
120
|
+
copy.extra_state = extra_state.dup
|
|
121
|
+
globals.ordered_parser.deferred_statements << [copy, stmt]
|
|
122
|
+
end
|
|
115
123
|
rescue HandlerAborted
|
|
116
124
|
log.debug "#{handler} cancelled from #{caller.last}"
|
|
117
125
|
log.debug "\tin file '#{file}':#{stmt.line}:\n\n" + stmt.show + "\n"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Handles RBS method aliases: `alias new_name old_name` and
|
|
3
|
+
# `alias self.new_name self.old_name`.
|
|
4
|
+
class YARD::Handlers::RBS::AliasHandler < YARD::Handlers::RBS::Base
|
|
5
|
+
handles :alias
|
|
6
|
+
namespace_only
|
|
7
|
+
|
|
8
|
+
process do
|
|
9
|
+
meth_scope = statement.visibility == :class ? :class : :instance
|
|
10
|
+
old_meth = statement.old_name.to_sym
|
|
11
|
+
old_obj = namespace.child(:name => old_meth, :scope => meth_scope)
|
|
12
|
+
new_obj = register MethodObject.new(namespace, statement.name, meth_scope)
|
|
13
|
+
namespace.aliases[new_obj] = old_meth
|
|
14
|
+
|
|
15
|
+
if old_obj
|
|
16
|
+
new_obj.signature = old_obj.signature
|
|
17
|
+
new_obj.source = old_obj.source
|
|
18
|
+
comments = [old_obj.docstring.to_raw, statement.comments].join("\n")
|
|
19
|
+
doc = YARD::Docstring.parser.parse(comments, new_obj, self)
|
|
20
|
+
new_obj.docstring = doc.to_docstring
|
|
21
|
+
new_obj.docstring.line_range = statement.comments_range
|
|
22
|
+
new_obj.docstring.object = new_obj
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -10,7 +10,7 @@ class YARD::Handlers::RBS::AttributeHandler < YARD::Handlers::RBS::Base
|
|
|
10
10
|
attr_name = statement.name
|
|
11
11
|
rbs_type = statement.attr_rbs_type
|
|
12
12
|
yard_types = rbs_type ? YARD::Handlers::RBS::MethodHandler.rbs_type_to_yard_types(rbs_type) : nil
|
|
13
|
-
mscope = statement.
|
|
13
|
+
mscope = statement.scope == :class ? :class : :instance
|
|
14
14
|
|
|
15
15
|
case statement.type
|
|
16
16
|
when :attr_reader
|
|
@@ -32,6 +32,7 @@ class YARD::Handlers::RBS::AttributeHandler < YARD::Handlers::RBS::Base
|
|
|
32
32
|
obj.source ||= "def #{name}\n @#{name}\nend"
|
|
33
33
|
obj.signature ||= "def #{name}"
|
|
34
34
|
obj = register(obj)
|
|
35
|
+
obj.visibility = statement.visibility if statement.visibility
|
|
35
36
|
obj.docstring = "Returns the value of attribute #{name}." if obj.docstring.blank?(false)
|
|
36
37
|
apply_tag_types(obj, :return, types)
|
|
37
38
|
namespace.attributes[obj.scope][name] ||= SymbolHash[:read => nil, :write => nil]
|
|
@@ -45,6 +46,7 @@ class YARD::Handlers::RBS::AttributeHandler < YARD::Handlers::RBS::Base
|
|
|
45
46
|
obj.source ||= "def #{name}=(value)\n @#{name} = value\nend"
|
|
46
47
|
obj.signature ||= "def #{name}=(value)"
|
|
47
48
|
obj = register(obj)
|
|
49
|
+
obj.visibility = statement.visibility if statement.visibility
|
|
48
50
|
obj.docstring = "Sets the attribute #{name}\n@param value the value to set the attribute #{name} to." if obj.docstring.blank?(false)
|
|
49
51
|
apply_tag_types(obj, :param, types, "value")
|
|
50
52
|
namespace.attributes[obj.scope][name] ||= SymbolHash[:read => nil, :write => nil]
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# Handles RBS constant declarations: `Name: Type
|
|
2
|
+
# Handles RBS constant declarations: `Name: Type`, and class and module
|
|
3
|
+
# aliases: `class Name = Other`, `module Name = Other`
|
|
3
4
|
class YARD::Handlers::RBS::ConstantHandler < YARD::Handlers::RBS::Base
|
|
4
5
|
handles :constant
|
|
5
6
|
|
|
6
7
|
process do
|
|
7
8
|
obj = register ConstantObject.new(namespace, statement.name)
|
|
9
|
+
obj.value = statement.value if statement.value
|
|
8
10
|
if statement.attr_rbs_type && !obj.has_tag?(:return)
|
|
9
11
|
obj.add_tag YARD::Tags::Tag.new(:return, '', rbs_types(statement.attr_rbs_type))
|
|
10
12
|
end
|
|
@@ -8,9 +8,11 @@ class YARD::Handlers::RBS::MethodHandler < YARD::Handlers::RBS::Base
|
|
|
8
8
|
handles :method_def
|
|
9
9
|
|
|
10
10
|
process do
|
|
11
|
-
|
|
12
|
-
obj =
|
|
11
|
+
obj = register MethodObject.new(namespace, statement.name, statement.scope || :instance)
|
|
12
|
+
obj.visibility = statement.visibility if statement.visibility
|
|
13
13
|
apply_signature_tags(obj, statement.signatures)
|
|
14
|
+
# Copy the tags to the private instance method of a `self?.` method too.
|
|
15
|
+
register_module_function(obj)
|
|
14
16
|
|
|
15
17
|
# For initialize, ensure the return type is the class, not void.
|
|
16
18
|
if statement.name == 'initialize'
|
|
@@ -130,6 +132,13 @@ class YARD::Handlers::RBS::MethodHandler < YARD::Handlers::RBS::Base
|
|
|
130
132
|
params = []
|
|
131
133
|
block_param = nil
|
|
132
134
|
|
|
135
|
+
# Skip method type parameters: leading `[...]`.
|
|
136
|
+
if remaining.start_with?('[')
|
|
137
|
+
close = find_matching(remaining, 0, '[', ']')
|
|
138
|
+
raise YARD::Parser::UndocumentableError, "malformed signature (unclosed '['): #{sig}" if close.nil?
|
|
139
|
+
remaining = remaining[close + 1..-1].lstrip
|
|
140
|
+
end
|
|
141
|
+
|
|
133
142
|
# 1. Extract positional/keyword params: leading `(...)`.
|
|
134
143
|
if remaining.start_with?('(')
|
|
135
144
|
close = find_matching(remaining, 0, '(', ')')
|
|
@@ -139,7 +148,8 @@ class YARD::Handlers::RBS::MethodHandler < YARD::Handlers::RBS::Base
|
|
|
139
148
|
params = parse_params_list(params_str)
|
|
140
149
|
end
|
|
141
150
|
|
|
142
|
-
# 2. Extract block type: `{ ... }`.
|
|
151
|
+
# 2. Extract block type: `{ ... }`, or an optional block `?{ ... }`.
|
|
152
|
+
remaining = remaining.sub(/\A\?\s*(?=\{)/, '')
|
|
143
153
|
if remaining.start_with?('{')
|
|
144
154
|
close = find_matching(remaining, 0, '{', '}')
|
|
145
155
|
raise YARD::Parser::UndocumentableError, "malformed signature (unclosed '{'): #{sig}" if close.nil?
|
|
@@ -4,7 +4,13 @@ class YARD::Handlers::RBS::MixinHandler < YARD::Handlers::RBS::Base
|
|
|
4
4
|
handles :include, :extend, :prepend
|
|
5
5
|
|
|
6
6
|
process do
|
|
7
|
-
mixin =
|
|
7
|
+
case mixin = Proxy.new(namespace, statement.mixin_name)
|
|
8
|
+
when ConstantObject # If a constant is included, use its value as the real object
|
|
9
|
+
mixin = Proxy.new(namespace, mixin.value || statement.mixin_name, :module)
|
|
10
|
+
else
|
|
11
|
+
mixin = Proxy.new(namespace, statement.mixin_name, :module)
|
|
12
|
+
end
|
|
13
|
+
|
|
8
14
|
case statement.type
|
|
9
15
|
when :include
|
|
10
16
|
mixins = namespace.mixins(:instance)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Handles RBS visibility sections: a bare `public` or `private` line sets
|
|
3
|
+
# the visibility of the instance members declared after it.
|
|
4
|
+
class YARD::Handlers::RBS::VisibilityHandler < YARD::Handlers::RBS::Base
|
|
5
|
+
handles :visibility
|
|
6
|
+
namespace_only
|
|
7
|
+
|
|
8
|
+
process do
|
|
9
|
+
self.visibility = statement.name.to_sym
|
|
10
|
+
globals.visibility_origin = :keyword
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -21,6 +21,8 @@ class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
|
|
|
21
21
|
end
|
|
22
22
|
if is_a_struct
|
|
23
23
|
parse_struct_superclass(klass, statement[1])
|
|
24
|
+
elsif superclass == "Data"
|
|
25
|
+
parse_data_superclass(klass, statement[1])
|
|
24
26
|
elsif klass
|
|
25
27
|
create_attributes(klass, members_from_tags(klass))
|
|
26
28
|
end
|
|
@@ -95,6 +97,11 @@ class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
|
|
|
95
97
|
create_attributes(klass, members)
|
|
96
98
|
end
|
|
97
99
|
|
|
100
|
+
def parse_data_superclass(klass, superclass)
|
|
101
|
+
return unless superclass.call? && superclass.parameters
|
|
102
|
+
create_readers(klass, extract_parameters(superclass))
|
|
103
|
+
end
|
|
104
|
+
|
|
98
105
|
def parse_superclass(superclass)
|
|
99
106
|
return nil unless superclass
|
|
100
107
|
|
|
@@ -113,6 +120,7 @@ class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
|
|
|
113
120
|
if cname =~ /^O?Struct$/ && superclass.method_name(true) == :new
|
|
114
121
|
return cname
|
|
115
122
|
end
|
|
123
|
+
return cname if cname == "Data" && superclass.method_name(true) == :define
|
|
116
124
|
end
|
|
117
125
|
nil
|
|
118
126
|
end
|
|
@@ -48,11 +48,7 @@ class YARD::Handlers::Ruby::ConstantHandler < YARD::Handlers::Ruby::Base
|
|
|
48
48
|
lhs = statement[0]
|
|
49
49
|
if (lhs.type == :var_field && lhs[0].type == :const) || lhs.type == :const_path_field
|
|
50
50
|
klass = create_class(lhs.source, P(:Data))
|
|
51
|
-
extract_parameters(statement[1])
|
|
52
|
-
next if klass.attributes[:instance][member]
|
|
53
|
-
klass.attributes[:instance][member] = SymbolHash[:read => nil, :write => nil]
|
|
54
|
-
create_reader(klass, member)
|
|
55
|
-
end
|
|
51
|
+
create_readers(klass, extract_parameters(statement[1]))
|
|
56
52
|
parse_block(statement[1].block[1], :namespace => klass) unless statement[1].block.nil?
|
|
57
53
|
else
|
|
58
54
|
raise YARD::Parser::UndocumentableError, "Data assignment to #{lhs.source}"
|