decode 0.24.3 → 0.24.5

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 (49) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/bake/decode/rbs.rb +1 -1
  4. data/context/coverage.md +1 -1
  5. data/context/getting-started.md +1 -1
  6. data/context/ruby-documentation.md +3 -3
  7. data/context/types.md +127 -0
  8. data/lib/decode/comment/attribute.rb +4 -1
  9. data/lib/decode/comment/constant.rb +47 -0
  10. data/lib/decode/comment/node.rb +32 -12
  11. data/lib/decode/comment/option.rb +1 -1
  12. data/lib/decode/comment/parameter.rb +5 -1
  13. data/lib/decode/comment/rbs.rb +8 -8
  14. data/lib/decode/comment/tag.rb +13 -1
  15. data/lib/decode/comment/tags.rb +16 -5
  16. data/lib/decode/comment/text.rb +1 -0
  17. data/lib/decode/comment/yields.rb +5 -1
  18. data/lib/decode/definition.rb +33 -31
  19. data/lib/decode/documentation.rb +10 -5
  20. data/lib/decode/index.rb +12 -7
  21. data/lib/decode/language/generic.rb +10 -1
  22. data/lib/decode/language/reference.rb +7 -4
  23. data/lib/decode/language/ruby/class.rb +2 -2
  24. data/lib/decode/language/ruby/code.rb +21 -3
  25. data/lib/decode/language/ruby/definition.rb +15 -3
  26. data/lib/decode/language/ruby/generic.rb +2 -1
  27. data/lib/decode/language/ruby/parser.rb +132 -91
  28. data/lib/decode/language/ruby/reference.rb +4 -1
  29. data/lib/decode/language/ruby/segment.rb +2 -2
  30. data/lib/decode/languages.rb +29 -8
  31. data/lib/decode/location.rb +15 -1
  32. data/lib/decode/rbs/class.rb +91 -14
  33. data/lib/decode/rbs/generator.rb +67 -11
  34. data/lib/decode/rbs/method.rb +394 -68
  35. data/lib/decode/rbs/module.rb +81 -5
  36. data/lib/decode/rbs/type.rb +52 -0
  37. data/lib/decode/rbs/wrapper.rb +10 -3
  38. data/lib/decode/scope.rb +2 -2
  39. data/lib/decode/segment.rb +3 -2
  40. data/lib/decode/source.rb +5 -14
  41. data/lib/decode/syntax/rewriter.rb +4 -1
  42. data/lib/decode/trie.rb +28 -20
  43. data/lib/decode/version.rb +2 -1
  44. data/readme.md +6 -0
  45. data/releases.md +6 -0
  46. data/sig/decode.rbs +503 -113
  47. data.tar.gz.sig +0 -0
  48. metadata +4 -1
  49. metadata.gz.sig +0 -0
data/sig/decode.rbs CHANGED
@@ -1,10 +1,18 @@
1
1
  module Decode
2
+ VERSION: String
3
+
2
4
  # Represents comment parsing and processing functionality.
3
5
  module Comment
4
6
  # Describes an attribute type.
5
7
  #
6
8
  # - `@attribute [Integer] The person's age.`
7
- class Attribute < ::Tag
9
+ class Attribute < Tag
10
+ PATTERN: Regexp
11
+
12
+ attr_reader type(@type): String
13
+
14
+ @type: String
15
+
8
16
  # Build an attribute from a directive and match.
9
17
  public def self.build: (String directive, MatchData match) -> untyped
10
18
 
@@ -12,41 +20,75 @@ module Decode
12
20
  public def initialize: (String directive, String type) -> void
13
21
  end
14
22
 
23
+ # Represents a constant type declaration.
24
+ #
25
+ # - `@constant [Regexp] Pattern for matching parameters.`
26
+ class Constant < Tag
27
+ PATTERN: Regexp
28
+
29
+ attr_reader type(@type): String
30
+
31
+ @type: String
32
+
33
+ # Build a constant from a directive and regex match.
34
+ public def self.build: (String directive, MatchData match) -> Constant
35
+
36
+ # Initialize a new constant.
37
+ public def initialize: (String directive, String type) -> void
38
+ end
39
+
15
40
  # Represents a node in a comment tree structure.
16
41
  class Node
42
+ attr_reader children(@children): Array[Node | Text]?
43
+
44
+ @children: Array[Node | Text]?
45
+
17
46
  # Initialize the node.
18
- public def initialize: (Array[Node] | nil children) -> void
47
+ public def initialize: (Array[Node | Text]? children) -> void
19
48
 
20
49
  # Whether this node has any children nodes.
21
50
  # Ignores {Text} instances.
22
51
  public def children?: () -> bool
23
52
 
24
53
  # Add a child node to this node.
25
- public def add: (Node child) -> self
54
+ public def add: (Node | Text child) -> self
26
55
 
27
56
  # Enumerate all non-text children nodes.
28
- public def each: () -> untyped
57
+ public def each: () { (Node node) -> void } -> (Enumerator[Node] | self)
29
58
 
30
59
  # Filter children nodes by class type.
31
- public def filter: (Class klass) -> untyped
60
+ public def filter: (Class klass) { (Object node) -> void } -> (Enumerator[Node] | self)
32
61
 
33
62
  # Any lines of text associated with this node.
34
- public def text: () -> (Array[String] | nil)
63
+ public def text: () -> Array[String]?
35
64
 
36
65
  # Traverse the tags from this node using {each}. Invoke `descend.call(child)` to recursively traverse the specified child.
37
66
  public def traverse: () { (Node node, Proc descend) -> void } -> untyped
67
+
68
+ # Extract text lines from Text children of this node.
69
+ def extract_text: () -> Array[String]?
38
70
  end
39
71
 
40
72
  # Describes a method option (keyword argument).
41
73
  #
42
- # - `@option :cached [Boolean] Whether to cache the value.`
43
- class Option < ::Parameter
74
+ # - `@option :cached [bool] Whether to cache the value.`
75
+ class Option < Parameter
44
76
  end
45
77
 
46
78
  # Represents a named method parameter.
47
79
  #
48
80
  # - `@parameter age [Float] The users age.`
49
- class Parameter < ::Tag
81
+ class Parameter < Tag
82
+ PATTERN: Regexp
83
+
84
+ attr_reader name(@name): String
85
+
86
+ attr_reader type(@type): String
87
+
88
+ @name: String
89
+
90
+ @type: String
91
+
50
92
  # Build a parameter from a directive and regex match.
51
93
  public def self.build: (String directive, MatchData match) -> Parameter
52
94
 
@@ -60,9 +102,9 @@ module Decode
60
102
  # - `@deprecated Please use {other_method} instead.`
61
103
  # - `@blocking This method may block.`
62
104
  # - `@asynchronous This method may yield.`
63
- class Pragma < ::Tag
105
+ class Pragma < Tag
64
106
  # Parse a pragma directive from text.
65
- public def self.parse: (String directive, String text, Array[String] lines, Array[Tag] tags, Integer level) -> untyped
107
+ public def self.parse: (String directive, String text, Array[String] lines, Array[Tag] tags, ?Integer level) -> untyped
66
108
 
67
109
  # Build a pragma from a directive and text.
68
110
  public def self.build: (String directive, String text) -> untyped
@@ -74,7 +116,7 @@ module Decode
74
116
  # Identifies that a method might raise an exception.
75
117
  #
76
118
  # - `@raises [ArgumentError] If the argument cannot be coerced.`
77
- class Raises < ::Attribute
119
+ class Raises < Attribute
78
120
  end
79
121
 
80
122
  # Represents an RBS type annotation following rbs-inline syntax.
@@ -82,45 +124,60 @@ module Decode
82
124
  # Examples:
83
125
  # - `@rbs generic T` - Declares a generic type parameter for a class
84
126
  # - `@rbs [T] () { () -> T } -> Task[T]` - Complete method type signature
85
- class RBS < ::Tag
127
+ class RBS < Tag
128
+ attr_reader text(@text): String
129
+
130
+ @text: String
131
+
86
132
  # Parse an RBS pragma from text.
87
- public def self.parse: (String directive, String text, Array[String] lines, Array[Tag] tags, Integer level) -> untyped
133
+ public def self.parse: (String directive, String text, Array[String] lines, Array[Tag] tags, ?Integer level) -> untyped
88
134
 
89
135
  # Build an RBS pragma from a directive and text.
90
136
  public def self.build: (String directive, String text) -> untyped
91
137
 
92
138
  # Initialize a new RBS pragma.
93
- public def initialize: (String directive, String text) -> void
139
+ public def initialize: (String directive, String? text) -> void
94
140
 
95
141
  # Check if this is a generic type declaration.
96
142
  public def generic?: () -> bool
97
143
 
98
144
  # Extract the generic type parameter name.
99
- public def generic_parameter: () -> (String | nil)
145
+ public def generic_parameter: () -> String?
100
146
 
101
147
  # Check if this is a method type signature.
102
148
  public def method_signature?: () -> bool
103
149
 
104
150
  # Get the method type signature text.
105
- public def method_signature: () -> (String | nil)
151
+ public def method_signature: () -> String?
106
152
  end
107
153
 
108
154
  # Represents a return value.
109
155
  #
110
156
  # Example: `@returns [Integer] The person's age.`
111
- class Returns < ::Attribute
157
+ class Returns < Attribute
112
158
  end
113
159
 
114
160
  # Represents a documentation tag parsed from a comment directive.
115
- class Tag < ::Node
161
+ # Subclasses should define a PATTERN constant for matching their specific syntax.
162
+ class Tag < Node
163
+ PATTERN: Regexp
164
+
165
+ attr_reader directive(@directive): String
166
+
167
+ @directive: String
168
+
169
+ # Abstract method: Build a tag from directive and match data.
170
+ # Subclasses must implement this method.
171
+ public def self.build: (String directive, MatchData match) -> Tag
172
+
116
173
  # Build a pattern for bracketed content, supporting nested brackets.
117
- public def self.bracketed_content: (String name) -> String
174
+ public def self.bracketed_content: (Symbol name) -> String
118
175
 
119
176
  # Match text against the tag pattern.
120
177
  public def self.match: (String text) -> untyped
121
178
 
122
179
  # Parse a tag from a directive and text.
123
- public def self.parse: (String directive, String text, Array[String] lines, Tags tags, Integer level) -> untyped
180
+ public def self.parse: (String directive, String text, Array[String] lines, Tags tags, ?Integer level) -> untyped
124
181
 
125
182
  # Initialize a new tag.
126
183
  public def initialize: (String directive) -> void
@@ -128,24 +185,30 @@ module Decode
128
185
 
129
186
  # Represents a collection of documentation tags and their parsing logic.
130
187
  class Tags
188
+ PATTERN: Regexp
189
+
131
190
  # Build a tags parser with directive mappings.
132
- public def self.build: (Proc block) -> untyped
191
+ public def self.build: () { (Hash[String, Class]) -> void } -> Tags
133
192
 
134
193
  # Initialize a new tags parser.
135
- public def initialize: (Hash[String, Class] directives) -> void
194
+ public def initialize: (Hash[String, _Directive] directives) -> void
136
195
 
137
196
  # Check if a line has valid indentation for the given level.
138
197
  public def valid_indentation?: (String line, Integer level) -> bool
139
198
 
140
199
  # Parse documentation tags from lines.
141
- public def parse: (Array[String] lines, Integer level, Proc block) -> untyped
200
+ public def parse: (Array[String] lines, ?Integer level) { (Node | Text) -> void } -> void
142
201
 
143
202
  # Ignore lines at the specified indentation level.
144
- public def ignore: (Array[String] lines, Integer level) -> untyped
203
+ public def ignore: (Array[String] lines, ?Integer level) -> untyped
145
204
  end
146
205
 
147
206
  # A structured comment.
148
207
  class Text
208
+ attr_reader line(@line): String
209
+
210
+ @line: String
211
+
149
212
  # Initialize a new text node.
150
213
  public def initialize: (String line) -> void
151
214
 
@@ -156,7 +219,7 @@ module Decode
156
219
  # Identifies that a method might throw a specific symbol.
157
220
  #
158
221
  # - `@throws [:skip] To skip recursion.`
159
- class Throws < ::Attribute
222
+ class Throws < Attribute
160
223
  end
161
224
 
162
225
  # Describes a block parameter.
@@ -164,7 +227,9 @@ module Decode
164
227
  # - `@yields {|person| ... } If a block is given.`
165
228
  #
166
229
  # Should contain nested parameters.
167
- class Yields < ::Tag
230
+ class Yields < Tag
231
+ PATTERN: Regexp
232
+
168
233
  # Build a yields tag from a directive and match.
169
234
  public def self.build: (String directive, MatchData match) -> untyped
170
235
 
@@ -175,18 +240,40 @@ module Decode
175
240
 
176
241
  # A symbol with attached documentation.
177
242
  class Definition
243
+ attr_reader path(@path): Array[Symbol]
244
+
245
+ attr_reader parent(@parent): Definition?
246
+
247
+ attr_reader language(@language): Language::Generic
248
+
249
+ attr_reader source(@source): Source?
250
+
251
+ attr_reader comments(@comments): Array[String]?
252
+
253
+ attr_reader visibility(@visibility): Symbol
254
+
255
+ @path: Array[Symbol]
256
+
257
+ @parent: Definition?
258
+
259
+ @language: Language::Generic
260
+
261
+ @source: Source?
262
+
263
+ @comments: Array[String]?
264
+
265
+ @visibility: Symbol
266
+
178
267
  # Initialize the symbol.
179
- public def initialize: (Symbol | Array[Symbol] path, Symbol parent, Language language, Array[String] comments, Source source) -> void
268
+ public def initialize: (Symbol | Array[Symbol] path, ?parent: Definition?, ?language: Language::Generic?, ?comments: Array[String]?, ?visibility: Symbol, ?source: Source?) -> void
180
269
 
181
270
  # Generate a debug representation of the definition.
182
271
  public def inspect: () -> untyped
183
272
 
184
- # The symbol name.
185
- # e.g. `:Decode`.
186
273
  public def name: () -> untyped
187
274
 
188
275
  # The full path to the definition.
189
- public def full_path: () -> untyped
276
+ public def full_path: () -> Array[Symbol]
190
277
 
191
278
  # Whether the definition is considered part of the public interface.
192
279
  # This is used to determine whether the definition should be documented for coverage purposes.
@@ -198,32 +285,31 @@ module Decode
198
285
  # The qualified name is an absolute name which includes any and all namespacing.
199
286
  public def qualified_name: () -> String
200
287
 
201
- # The name relative to the parent.
202
288
  public def nested_name: () -> String
203
289
 
204
290
  # Does the definition name match the specified prefix?
205
- public def start_with?: () -> bool
291
+ public def start_with?: (String prefix) -> bool
206
292
 
207
293
  # Convert this definition into another kind of definition.
208
- public def convert: () -> untyped
294
+ public def convert: (Symbol kind) -> untyped
209
295
 
210
296
  # A short form of the definition.
211
297
  # e.g. `def short_form`.
212
- public def short_form: () -> (String | nil)
298
+ public def short_form: () -> String?
213
299
 
214
300
  # A long form of the definition.
215
301
  # e.g. `def initialize(kind, name, comments, **options)`.
216
- public def long_form: () -> (String | nil)
302
+ public def long_form: () -> String?
217
303
 
218
304
  # A long form which uses the qualified name if possible.
219
305
  # Defaults to {long_form}.
220
- public def qualified_form: () -> (String | nil)
306
+ public def qualified_form: () -> String?
221
307
 
222
308
  # Whether the definition spans multiple lines.
223
309
  public def multiline?: () -> bool
224
310
 
225
311
  # The full text of the definition.
226
- public def text: () -> (String | nil)
312
+ public def text: () -> String?
227
313
 
228
314
  # Whether this definition can contain nested definitions.
229
315
  public def container?: () -> bool
@@ -232,25 +318,49 @@ module Decode
232
318
  public def nested?: () -> bool
233
319
 
234
320
  # Structured access to the definitions comments.
235
- public def documentation: () -> (Documentation | nil)
321
+ public def documentation: () -> Documentation?
236
322
 
237
323
  # The location of the definition.
238
- public def location: () -> (Location | nil)
324
+ public def location: () -> Location?
239
325
  end
240
326
 
241
327
  # Structured access to a set of comment lines.
242
- class Documentation < ::Comment::Node
328
+ class Documentation < Comment::Node
329
+ attr_reader comments(@comments): Array[String]
330
+
331
+ attr_reader language(@language): Language::Generic?
332
+
333
+ @comments: Array[String]
334
+
335
+ @language: Language::Generic?
336
+
243
337
  # Initialize the documentation with an array of comments, within a specific language.
244
- public def initialize: (Array[String] comments, Language language) -> void
338
+ public def initialize: (Array[String] comments, Language::Generic? language) -> void
245
339
  end
246
340
 
247
341
  # Represents a list of definitions organised for quick lookup and lexical enumeration.
248
342
  class Index
343
+ attr_reader languages(@languages): Languages
344
+
345
+ attr_reader sources(@sources): Hash[String, Source]
346
+
347
+ attr_reader definitions(@definitions): Hash[String, Definition]
348
+
349
+ attr_reader trie(@trie): Trie[Definition]
350
+
351
+ @languages: Languages
352
+
353
+ @sources: Hash[String, Source]
354
+
355
+ @definitions: Hash[String, Definition]
356
+
357
+ @trie: Trie[Definition]
358
+
249
359
  # Create and populate an index from the given paths.
250
- public def self.for: (Array[String] paths, Languages languages) -> Index
360
+ public def self.for: (*String, ?languages: Languages) -> Index
251
361
 
252
362
  # Initialize an empty index.
253
- public def initialize: (Languages languages) -> void
363
+ public def initialize: (?Languages languages) -> void
254
364
 
255
365
  # Generate a string representation of this index.
256
366
  public def inspect: () -> String
@@ -260,15 +370,27 @@ module Decode
260
370
  public def update: (Array[String] paths) -> untyped
261
371
 
262
372
  # Lookup the specified reference and return matching definitions.
263
- public def lookup: (Language::Reference reference, Definition relative_to) -> (Definition | nil)
373
+ public def lookup: (Language::Reference reference, ?relative_to: Definition?) -> Definition?
264
374
  end
265
375
 
266
376
  # Language specific parsers and definitions.
267
377
  module Language
268
378
  # Represents a generic language implementation that can be extended for specific languages.
269
379
  class Generic
380
+ attr_reader name(@name): String
381
+
382
+ attr_reader extensions(@extensions): Array[String]
383
+
384
+ attr_reader tags(@tags): Comment::Tags
385
+
386
+ @name: String
387
+
388
+ @extensions: Array[String]
389
+
390
+ @tags: Comment::Tags
391
+
270
392
  # Initialize a new generic language.
271
- public def initialize: (String name, Array[String] extensions, Comment::Tags tags) -> void
393
+ public def initialize: (String name, ?extensions: Array[String], ?tags: Comment::Tags) -> void
272
394
 
273
395
  # Get all names for this language.
274
396
  public def names: () -> Array[String]
@@ -277,7 +399,7 @@ module Decode
277
399
  public def reference_for: (String identifier) -> Reference
278
400
 
279
401
  # Get the parser for this language.
280
- public def parser: () -> (Parser | nil)
402
+ public def parser: () -> untyped
281
403
 
282
404
  # Parse the input yielding definitions.
283
405
  public def definitions_for: (Source source) { (Definition definition) -> void } -> Enumerator[Segment]
@@ -285,12 +407,23 @@ module Decode
285
407
  # Parse the input yielding segments.
286
408
  # Segments are constructed from a block of top level comments followed by a block of code.
287
409
  public def segments_for: (Source source) { (Segment segment) -> void } -> Enumerator[Segment]
410
+
411
+ # Generate a code representation with syntax highlighting and link resolution.
412
+ public def code_for: (String text, Index index, ?relative_to: Definition) -> untyped
288
413
  end
289
414
 
290
415
  # An reference which can be resolved to zero or more definitions.
291
416
  class Reference
417
+ attr_reader identifier(@identifier): String
418
+
419
+ attr_reader language(@language): Language::Generic
420
+
421
+ @identifier: String
422
+
423
+ @language: Language::Generic
424
+
292
425
  # Initialize the reference.
293
- public def initialize: (String identifier) -> void
426
+ public def initialize: (String identifier, Language::Generic language, ?Array[String]? lexical_path) -> void
294
427
 
295
428
  # Generate a string representation of the reference.
296
429
  public def to_s: () -> untyped
@@ -314,10 +447,10 @@ module Decode
314
447
  public def priority: (String definition, String prefix) -> untyped
315
448
 
316
449
  # Find the best matching definition from a list.
317
- public def best: (Array[String] definitions) -> untyped
450
+ public def best: (Array[Definition] definitions) -> Definition?
318
451
 
319
452
  # The lexical path of the reference.
320
- public def path: () -> Array[String]
453
+ public def path: () -> Array[Symbol]
321
454
  end
322
455
 
323
456
  # Represents an interface for extracting information from Ruby source code.
@@ -326,9 +459,9 @@ module Decode
326
459
  public def self.new: () -> Ruby::Generic
327
460
 
328
461
  # Represents an alias statement, e.g., `alias new_name old_name` or `alias_method :new_name, :old_name`
329
- class Alias < ::Definition
462
+ class Alias < Definition
330
463
  # Initialize a new alias definition.
331
- public def initialize: (String new_name, String old_name, Hash options) -> void
464
+ public def initialize: (String new_name, String old_name, **Hash options) -> void
332
465
 
333
466
  # Generate a short form representation of the alias.
334
467
  public def short_form: () -> untyped
@@ -341,7 +474,7 @@ module Decode
341
474
  end
342
475
 
343
476
  # A Ruby-specific attribute.
344
- class Attribute < ::Definition
477
+ class Attribute < Definition
345
478
  # The short form of the attribute.
346
479
  # e.g. `attr :value`.
347
480
  public def short_form: () -> untyped
@@ -351,7 +484,7 @@ module Decode
351
484
  end
352
485
 
353
486
  # A Ruby-specific block which might carry other definitions.
354
- class Block < ::Definition
487
+ class Block < Definition
355
488
  # A block can sometimes be a container for other definitions.
356
489
  public def container?: () -> bool
357
490
 
@@ -375,7 +508,7 @@ module Decode
375
508
  end
376
509
 
377
510
  # A Ruby-specific block which might carry other definitions.
378
- class Call < ::Definition
511
+ class Call < Definition
379
512
  # A block can sometimes be a container for other definitions.
380
513
  public def container?: () -> bool
381
514
 
@@ -393,9 +526,9 @@ module Decode
393
526
  end
394
527
 
395
528
  # A Ruby-specific class.
396
- class Class < ::Definition
529
+ class Class < Definition
397
530
  # Initialize a new class definition.
398
- public def initialize: (Array arguments, String super_class, Hash options) -> void
531
+ public def initialize: (*Array arguments, ?super_class: String, **Hash options) -> void
399
532
 
400
533
  # A class is a container for other definitions.
401
534
  public def container?: () -> bool
@@ -414,7 +547,7 @@ module Decode
414
547
  end
415
548
 
416
549
  # A Ruby-specific singleton class.
417
- class Singleton < ::Definition
550
+ class Singleton < Definition
418
551
  # Generate a nested name for the singleton class.
419
552
  public def nested_name: () -> untyped
420
553
 
@@ -427,19 +560,44 @@ module Decode
427
560
  # The short form of the class.
428
561
  # e.g. `class << self`.
429
562
  public def short_form: () -> untyped
563
+
564
+ private def absolute_path: () -> untyped
430
565
  end
431
566
 
432
567
  # A Ruby-specific block of code.
433
568
  class Code
569
+ attr_reader text(@text): String
570
+
571
+ attr_reader root(@root): untyped
572
+
573
+ attr_reader index(@index): Index
574
+
575
+ attr_reader relative_to(@relative_to): Definition?
576
+
577
+ attr_reader language(@language): Language::Generic
578
+
579
+ @text: String
580
+
581
+ @root: untyped
582
+
583
+ @index: Index
584
+
585
+ @relative_to: Definition?
586
+
587
+ @language: Language::Generic
588
+
434
589
  # Initialize a new code block.
435
- public def initialize: (String text, Index index, Definition relative_to, Language language) -> void
590
+ public def initialize: (String text, Index index, language: Language::Generic, ?relative_to: Definition?) -> void
436
591
 
437
592
  # Extract definitions from the code.
438
- public def extract: (Array into) -> untyped
593
+ public def extract: (?Array into) -> Array
594
+
595
+ # Traverse the syntax tree and extract definitions.
596
+ private def traverse: (untyped node, Array into) -> self
439
597
  end
440
598
 
441
599
  # A Ruby-specific constant.
442
- class Constant < ::Definition
600
+ class Constant < Definition
443
601
  # The short form of the constant.
444
602
  # e.g. `NAME`.
445
603
  public def short_form: () -> untyped
@@ -453,13 +611,27 @@ module Decode
453
611
  end
454
612
 
455
613
  # Represents a Ruby-specific definition extracted from source code.
456
- class Definition < ::Decode::Definition
614
+ class Definition < Decode::Definition
615
+ attr_reader node(@node): Parser::AST::Node
616
+
617
+ attr_reader visibility(@visibility): Symbol
618
+
619
+ @node: Parser::AST::Node
620
+
621
+ @visibility: Symbol
622
+
457
623
  # Initialize the definition from the syntax tree node.
458
- public def initialize: (Array arguments, Symbol visibility, Parser::AST::Node node, Hash options) -> void
624
+ public def initialize: (*Array arguments, ?visibility: Symbol, ?node: Parser::AST::Node, **Hash options) -> void
459
625
 
460
626
  # Check if this definition is public.
461
627
  public def public?: () -> bool
462
628
 
629
+ # Check if this definition is protected.
630
+ public def protected?: () -> bool
631
+
632
+ # Check if this definition is private.
633
+ public def private?: () -> bool
634
+
463
635
  # Check if this definition spans multiple lines.
464
636
  public def multiline?: () -> bool
465
637
 
@@ -467,11 +639,11 @@ module Decode
467
639
  public def text: () -> String
468
640
 
469
641
  # Get the location of this definition.
470
- public def location: () -> (Location | nil)
642
+ public def location: () -> Location?
471
643
  end
472
644
 
473
645
  # A Ruby-specific function.
474
- class Function < ::Method
646
+ class Function < Method
475
647
  # Generate a nested name for the function.
476
648
  public def nested_name: () -> untyped
477
649
 
@@ -480,21 +652,21 @@ module Decode
480
652
  end
481
653
 
482
654
  # Represents the Ruby language implementation for parsing and analysis.
483
- class Generic < ::Language::Generic
655
+ class Generic < Language::Generic
484
656
  # Get the parser for Ruby source code.
485
- public def parser: () -> Parser
657
+ public def parser: () -> Language::Ruby::Parser
486
658
 
487
659
  # Generate a language-specific reference for Ruby.
488
660
  public def reference_for: (String identifier) -> Reference
489
661
 
490
662
  # Generate a code representation with syntax highlighting and link resolution.
491
- public def code_for: (String text, Index index, Definition relative_to) -> Code
663
+ public def code_for: (String text, Index index, ?relative_to: Definition) -> Code
492
664
  end
493
665
 
494
666
  # A Ruby-specific method.
495
- class Method < ::Definition
667
+ class Method < Definition
496
668
  # Initialize a new method definition.
497
- public def initialize: (Array arguments, String receiver, Hash options) -> void
669
+ public def initialize: (*Array arguments, ?receiver: String, **Hash options) -> void
498
670
 
499
671
  # Generate a nested name for the method.
500
672
  public def nested_name: () -> untyped
@@ -522,7 +694,7 @@ module Decode
522
694
  end
523
695
 
524
696
  # A Ruby-specific module.
525
- class Module < ::Definition
697
+ class Module < Definition
526
698
  # A module is a container for other definitions.
527
699
  public def container?: () -> bool
528
700
 
@@ -540,47 +712,111 @@ module Decode
540
712
 
541
713
  # The Ruby source code parser.
542
714
  class Parser
715
+ attr_reader language(@language): Language::Generic
716
+
717
+ attr_reader visibility(@visibility): Symbol
718
+
719
+ attr_reader definitions(@definitions): Hash
720
+
721
+ @language: Language::Generic
722
+
723
+ @visibility: Symbol
724
+
725
+ @definitions: Hash
726
+
543
727
  # Initialize a new Ruby parser.
544
- public def initialize: (Language language) -> void
728
+ public def initialize: (Language::Generic language) -> void
729
+
730
+ # Parse the source code using Prism.
731
+ public def parse_source: (Source source) -> untyped
732
+
733
+ # Parse the given source object, can be a string or a Source instance.
734
+ private def parse_source: (String | Source source) -> untyped
545
735
 
546
736
  # Extract definitions from the given input file.
547
- public def definitions_for: () -> untyped
737
+ public def definitions_for: (Source source) -> Enumerator[Definition]
548
738
 
549
739
  # Walk over the syntax tree and extract relevant definitions with their associated comments.
550
- public def walk_definitions: () -> untyped
740
+ public def walk_definitions: (untyped node, ?Definition? parent, ?Source? source) -> untyped
551
741
 
552
742
  # Extract segments from the given input file.
553
- public def segments_for: () -> untyped
743
+ public def segments_for: (Source source) -> Enumerator[Segment]
744
+
745
+ # Extract clean comment text from a node by removing leading # symbols and whitespace.
746
+ # Only returns comments that directly precede the node (i.e., are adjacent to it).
747
+ # Extract comments that directly precede a node.
748
+ private def comments_for: (untyped node) -> Array[String]
749
+
750
+ # Assign a definition to a parent scope.
751
+ private def assign_definition: (Definition? parent, Definition definition) -> untyped
752
+
753
+ # Look up a definition in the parent scope.
754
+ private def lookup_definition: (Definition? parent, Symbol name) -> Definition?
755
+
756
+ # Store a definition in the parent scope.
757
+ private def store_definition: (Definition? parent, Symbol name, Definition definition) -> untyped
758
+
759
+ private def with_visibility: (?untyped visibility) -> untyped
760
+
761
+ private def attribute_name_for: (untyped node) -> untyped
762
+
763
+ private def nested_path_for: (untyped node, ?untyped path) -> untyped
764
+
765
+ private def nested_name_for: (untyped node) -> untyped
766
+
767
+ private def symbol_name_for: (untyped node) -> untyped
768
+
769
+ private def receiver_for: (untyped node) -> untyped
770
+
771
+ private def singleton_name_for: (untyped node) -> untyped
772
+
773
+ private def kind_for: (untyped node, ?untyped comments) -> untyped
774
+
775
+ private def scope_for: (untyped comments, ?untyped parent) -> untyped
776
+
777
+ private def constant_names_for: (untyped child_nodes) -> untyped
778
+
779
+ private def walk_segments: (untyped node, untyped comments) -> untyped
554
780
  end
555
781
 
556
782
  # An Ruby-specific reference which can be resolved to zero or more definitions.
557
- class Reference < ::Language::Reference
783
+ class Reference < Language::Reference
558
784
  # Create a reference from a constant node.
559
- public def self.from_const: (Prism::Node node, Language language) -> untyped
785
+ public def self.from_const: (Prism::Node node, Language::Generic language) -> Reference
560
786
 
561
787
  # Append a constant node to the path.
562
- public def self.append_const: (Prism::Node node, Array path) -> self
788
+ public def self.append_const: (Prism::Node node, ?Array path) -> Array
563
789
 
564
790
  # Split a Ruby identifier into prefix and name components.
565
- public def split: (String text) -> untyped
791
+ public def split: (String text) -> Array
566
792
  end
567
793
 
568
794
  # A Ruby specific code segment.
569
- class Segment < ::Decode::Segment
795
+ class Segment < Decode::Segment
570
796
  # Initialize a new Ruby segment.
571
- public def initialize: (Array[String] comments, Language language, Prism::Node node, Hash options) -> void
797
+ public def initialize: (Array[String] comments, Generic language, Prism::Node node, **Hash options) -> void
572
798
 
573
799
  # Expand the segment to include another node.
574
800
  public def expand: (Prism::Node node) -> untyped
575
801
 
576
802
  # The source code trailing the comments.
577
- public def code: () -> (String | nil)
803
+ public def code: () -> String?
578
804
  end
579
805
  end
580
806
  end
581
807
 
582
808
  # Represents a context for looking up languages based on file extension or name.
583
809
  class Languages
810
+ REFERENCE: Regexp
811
+
812
+ attr_reader named(@named): Hash[String, Language::Generic]
813
+
814
+ attr_reader extensions(@extensions): Hash[String, Language::Generic]
815
+
816
+ @named: Hash[String, Language::Generic]
817
+
818
+ @extensions: Hash[String, Language::Generic]
819
+
584
820
  # Create a new languages context with all supported languages.
585
821
  public def self.all: () -> Languages
586
822
 
@@ -594,20 +830,31 @@ module Decode
594
830
  public def add: (Language::Generic language) -> self
595
831
 
596
832
  # Fetch a language by name, creating a generic language if needed.
597
- public def fetch: (String name) -> Language::Generic
833
+ public def fetch: (String name) -> Language::Generic?
598
834
 
599
835
  # Create a source object for the given file path.
600
- public def source_for: (String path) -> (Source | nil)
836
+ public def source_for: (String path) -> Source?
601
837
 
602
838
  # Parse a language agnostic reference.
603
- public def parse_reference: (String text, Language::Generic default_language) -> (Language::Reference | nil)
839
+ public def parse_reference: (String text, ?default_language: Language::Generic?) -> Language::Reference?
604
840
 
605
841
  # Create a reference for the given language and identifier.
606
- public def reference_for: (String name, String identifier) -> Language::Reference
842
+ public def reference_for: (String name, String identifier) -> Language::Reference?
607
843
  end
608
844
 
609
845
  # Represents a location in a source file.
610
846
  class Location
847
+ attr_reader path(@path): String
848
+
849
+ attr_reader line(@line): Integer
850
+
851
+ @path: String
852
+
853
+ @line: Integer
854
+
855
+ # Initialize a new location.
856
+ public def initialize: (String path, Integer line) -> void
857
+
611
858
  # Generate a string representation of the location.
612
859
  public def to_s: () -> untyped
613
860
  end
@@ -615,46 +862,147 @@ module Decode
615
862
  # RBS generation functionality for Ruby type signatures.
616
863
  module RBS
617
864
  # Represents a Ruby class definition wrapper for RBS generation.
618
- class Class < ::Wrapper
865
+ class Class < Wrapper
619
866
  # Initialize a new class wrapper.
620
867
  public def initialize: (Decode::Definition definition) -> void
621
868
 
622
869
  # Extract generic type parameters from the class definition.
623
- public def generics: () -> Array
870
+ public def generics: () -> Array[Symbol]
624
871
 
625
872
  # Convert the class definition to RBS AST
626
- public def to_rbs_ast: () -> untyped
873
+ public def to_rbs_ast: (?untyped method_definitions, ?untyped constant_definitions, ?untyped attribute_definitions, ?untyped index) -> untyped
874
+
875
+ private def extract_generics: () -> untyped
876
+
877
+ # Build a constant RBS declaration.
878
+ private def build_constant_rbs: (untyped constant_definition) -> untyped
879
+
880
+ # Convert a simple name to RBS TypeName (not qualified).
881
+ private def simple_name_to_rbs: (untyped name) -> untyped
882
+
883
+ # Build attribute RBS declarations and infer instance variable types.
884
+ private def build_attributes_rbs: (Array attribute_definitions) -> Array
885
+
886
+ # Convert a qualified name to RBS TypeName
887
+ private def qualified_name_to_rbs: (untyped qualified_name) -> untyped
627
888
  end
628
889
 
629
890
  # Represents a generator for RBS type declarations.
630
891
  class Generator
892
+ attr_reader loader(@loader): ::RBS::EnvironmentLoader
893
+
894
+ attr_reader environment(@environment): ::RBS::Environment
895
+
896
+ attr_reader include_private(@include_private): bool
897
+
898
+ @loader: ::RBS::EnvironmentLoader
899
+
900
+ @environment: ::RBS::Environment
901
+
902
+ @include_private: bool
903
+
631
904
  # Initialize a new RBS generator.
632
905
  # Sets up the RBS environment for type resolution.
633
- public def initialize: () -> void
906
+ public def initialize: (?include_private: bool) -> void
634
907
 
635
908
  # Generate RBS declarations for the given index.
636
- public def generate: (Decode::Index index, IO output) -> untyped
909
+ public def generate: (Decode::Index index, ?output: IO) -> untyped
910
+
911
+ # Build nested RBS declarations preserving the parent hierarchy.
912
+ private def build_nested_declaration: (Definition definition, Hash declarations, Index index) -> untyped?
913
+
914
+ # Convert a definition to RBS AST.
915
+ private def definition_to_rbs: (Definition definition, Index index) -> untyped
916
+
917
+ # Get methods for a given definition efficiently using trie lookup.
918
+ private def get_methods_for_definition: (Definition definition, Index index) -> Array
919
+
920
+ # Get constants for a given definition efficiently using trie lookup.
921
+ private def get_constants_for_definition: (Definition definition, Index index) -> Array
922
+
923
+ # Get attributes for a given definition efficiently using trie lookup.
924
+ private def get_attributes_for_definition: (Definition definition, Index index) -> Array
637
925
  end
638
926
 
639
927
  # Represents a Ruby method definition wrapper for RBS generation.
640
- class Method < ::Wrapper
928
+ class Method < Wrapper
641
929
  # Initialize a new method wrapper.
642
930
  public def initialize: (Decode::Definition definition) -> void
643
931
 
644
932
  # Extract method signatures from the method definition.
645
933
  public def signatures: () -> Array
646
934
 
935
+ # Extract keyword arguments from the method definition.
936
+ public def keyword_arguments: () -> Hash
937
+
938
+ # Extract return type from the method definition.
939
+ public def return_type: () -> ::RBS::Types::t
940
+
941
+ # Extract parameters from the method definition.
942
+ public def parameters: () -> Array
943
+
647
944
  # Convert the method definition to RBS AST
648
- public def to_rbs_ast: () -> untyped
945
+ public def to_rbs_ast: (?untyped index) -> untyped
946
+
947
+ # Build a complete RBS function type from AST information.
948
+ public def build_function_type_from_ast: (Definition definition, Index index) -> RBS::Types::Function
949
+
950
+ private def extract_signatures: () -> untyped
951
+
952
+ # Extract return type from method documentation.
953
+ private def extract_return_type: (untyped definition, untyped index) -> untyped
954
+
955
+ # Extract parameter types from method documentation.
956
+ private def extract_parameters: (untyped definition, untyped index) -> untyped
957
+
958
+ # Extract parameter information from the Prism AST node.
959
+ private def extract_parameters_from_ast: (Definition definition) -> Array
960
+
961
+ # Extract keyword arguments from @option tags and AST.
962
+ private def extract_keyword_arguments: (untyped definition, untyped index) -> untyped
963
+
964
+ # Extract keyword arguments from the Prism AST node.
965
+ private def extract_keyword_arguments_from_ast: (Definition definition) -> Hash
966
+
967
+ # Extract documented parameter types into a hash for lookup.
968
+ private def extract_documented_parameter_types: (Definition definition) -> Hash
969
+
970
+ # Make a type optional if it's not already nullable.
971
+ private def make_type_optional_if_needed: (RBS::Types::t type) -> RBS::Types::t
972
+
973
+ # Extract block type from method documentation.
974
+ private def extract_block_type: (untyped definition, untyped index) -> untyped
975
+
976
+ # Infer return type based on method patterns and heuristics.
977
+ private def infer_return_type: (untyped definition) -> untyped
649
978
  end
650
979
 
651
980
  # Represents a Ruby module definition wrapper for RBS generation.
652
- class Module < ::Wrapper
981
+ class Module < Wrapper
653
982
  # Initialize a new module wrapper.
654
983
  public def initialize: (Decode::Definition definition) -> void
655
984
 
656
985
  # Convert the module definition to RBS AST
657
- public def to_rbs_ast: () -> untyped
986
+ public def to_rbs_ast: (?Array[Method] method_definitions, ?Array[Constant] constant_definitions, ?Array[Attribute] attribute_definitions, ?Index? index) -> RBS::AST::Declarations::Module
987
+
988
+ # Build a constant RBS declaration.
989
+ private def build_constant_rbs: (untyped constant_definition) -> untyped
990
+
991
+ # Convert a simple name to RBS TypeName (not qualified).
992
+ private def simple_name_to_rbs: (untyped name) -> untyped
993
+
994
+ # Build attribute RBS declarations and infer instance variable types.
995
+ private def build_attributes_rbs: (Array attribute_definitions) -> Array
996
+ end
997
+
998
+ # Utilities for working with RBS types.
999
+ module Type
1000
+ # Check if an RBS type represents a nullable/optional type
1001
+ # This method recursively traverses the type tree to find nil anywhere
1002
+ public def self.nullable?: (untyped rbs_type) -> bool
1003
+
1004
+ # Parse a type string and convert it to RBS type
1005
+ public def self.parse: (String type_string) -> untyped
658
1006
  end
659
1007
 
660
1008
  # Base wrapper class for RBS generation from definitions.
@@ -664,11 +1012,20 @@ module Decode
664
1012
 
665
1013
  # Extract RBS tags from the definition's documentation.
666
1014
  public def tags: () -> Array
1015
+
1016
+ # Extract comment from the definition's documentation.
1017
+ public def comment: () -> RBS::AST::Comment?
1018
+
1019
+ # Extract RBS tags from the definition's documentation.
1020
+ private def extract_tags: () -> Array
1021
+
1022
+ # Extract comment from definition documentation.
1023
+ private def extract_comment: (?Definition definition) -> RBS::AST::Comment?
667
1024
  end
668
1025
  end
669
1026
 
670
1027
  # An abstract namespace for nesting definitions.
671
- class Scope < ::Definition
1028
+ class Scope < Definition
672
1029
  public def short_form: () -> String
673
1030
 
674
1031
  # Scopes are always containers.
@@ -682,24 +1039,37 @@ module Decode
682
1039
  # segment = source.segments.first
683
1040
  # ~~~
684
1041
  class Segment
1042
+ attr_reader comments(@comments): Array[String]
1043
+
1044
+ attr_reader language(@language): Language::Generic
1045
+
1046
+ @comments: Array[String]
1047
+
1048
+ @language: Language::Generic
1049
+
685
1050
  # Initialize a new segment.
686
1051
  public def initialize: (Array[String] comments, Language::Generic language) -> void
687
1052
 
688
1053
  # An interface for accsssing the documentation of the definition.
689
- public def documentation: () -> (Documentation | nil)
1054
+ public def documentation: () -> Documentation?
690
1055
 
691
1056
  # The source code trailing the comments.
692
- public def code: () -> (String | nil)
1057
+ public def code: () -> String?
693
1058
  end
694
1059
 
695
1060
  # Represents a source file in a specific language.
696
1061
  class Source
1062
+ attr_reader path(@path): StringPath
1063
+
1064
+ attr_reader language(@language): Language::Generic
1065
+
1066
+ @path: StringPath
1067
+
1068
+ @language: Language::Generic
1069
+
697
1070
  # Initialize a new source file.
698
1071
  public def initialize: (String path, Language::Generic language) -> void
699
1072
 
700
- # The relative path of the source, if it is known.
701
- public def relative_path: () -> String
702
-
703
1073
  # Read the source file into an internal buffer/cache.
704
1074
  public def read: () -> String
705
1075
 
@@ -710,13 +1080,13 @@ module Decode
710
1080
  public def segments: () { (Segment segment) -> void } -> Enumerator[Segment]
711
1081
 
712
1082
  # Generate code representation with optional index for link resolution.
713
- public def code: (Index index, Definition relative_to) -> String
1083
+ public def code: (?Index? index, ?relative_to: Definition?) -> String
714
1084
  end
715
1085
 
716
1086
  # Provides syntax rewriting and linking functionality.
717
1087
  module Syntax
718
1088
  # Represents a link to a definition in the documentation.
719
- class Link < ::Match
1089
+ class Link < Match
720
1090
  # Initialize a new link.
721
1091
  public def initialize: (Range range, Definition definition) -> void
722
1092
 
@@ -747,6 +1117,14 @@ module Decode
747
1117
 
748
1118
  # Provides text rewriting functionality with match-based substitutions.
749
1119
  class Rewriter
1120
+ attr_reader text(@text): String
1121
+
1122
+ attr_reader matches(@matches): Array[Match]
1123
+
1124
+ @text: String
1125
+
1126
+ @matches: Array[Match]
1127
+
750
1128
  # Initialize a new rewriter.
751
1129
  public def initialize: (String text) -> void
752
1130
 
@@ -754,10 +1132,10 @@ module Decode
754
1132
  public def <<: (Match match) -> self
755
1133
 
756
1134
  # Returns a chunk of raw text with no formatting.
757
- public def text_for: () -> untyped
1135
+ public def text_for: (untyped range) -> untyped
758
1136
 
759
1137
  # Apply all matches to generate the rewritten output.
760
- public def apply: (Array output) -> untyped
1138
+ public def apply: (?Array output) -> untyped
761
1139
 
762
1140
  # Generate a link to a definition.
763
1141
  public def link_to: (Definition definition, String text) -> untyped
@@ -765,37 +1143,49 @@ module Decode
765
1143
  end
766
1144
 
767
1145
  # Represents a prefix-trie data structure for fast lexical lookups.
768
- class Trie
1146
+ class Trie[T]
1147
+ attr_reader root(@root): Node
1148
+
1149
+ @root: Node
1150
+
769
1151
  # Initialize an empty trie.
770
1152
  public def initialize: () -> void
771
1153
 
772
1154
  # Insert the specified value at the given path into the trie.
773
- public def insert: (Array[String] path, Object value) -> untyped
1155
+ public def insert: (Array[Symbol] path, T value) -> untyped
774
1156
 
775
1157
  # Lookup the values at the specified path.
776
- public def lookup: (Array[String] path) -> (Node | nil)
1158
+ public def lookup: (Array[Symbol] path) -> Node?
777
1159
 
778
1160
  # Enumerate all lexical scopes under the specified path.
779
- public def each: (Array[String] path) { (Array[String] path, Array[Object] | nil values) -> void } -> untyped
1161
+ public def each: (?Array[Symbol]) { (Array[Symbol], Array[T] | nil) -> void } -> void
780
1162
 
781
1163
  # Traverse the trie starting from the specified path.
782
1164
  # See {Node#traverse} for details.
783
- public def traverse: (Array[String] path) { () -> void } -> untyped
1165
+ public def traverse: (?Array[Symbol]) { (Array[Symbol], Node, Proc) -> void } -> void
784
1166
 
785
1167
  # Represents a single node in the trie.
786
1168
  class Node
787
- # Initialize a new trie node.
1169
+ attr_reader values(@values): Array[T]?
1170
+
1171
+ attr_reader children(@children): Hash[Symbol, Node]
1172
+
1173
+ @values: Array[T]?
1174
+
1175
+ @children: Hash[Symbol, Node]
1176
+
1177
+ # Initialize an empty node.
788
1178
  public def initialize: () -> void
789
1179
 
790
1180
  # Generate a string representation of this node.
791
1181
  public def inspect: () -> String
792
1182
 
793
1183
  # Look up a lexical path starting at this node.
794
- public def lookup: (Array[String] path, Integer index) -> (Node | nil)
1184
+ public def lookup: (Array[Symbol] path, ?Integer index) -> Node?
795
1185
 
796
1186
  # Traverse the trie from this node.
797
1187
  # Invoke `descend.call` to traverse the children of the current node.
798
- public def traverse: (Array[String] path) { (Array[String] path, Node node, Proc descend) -> void } -> untyped
1188
+ public def traverse: (?Array[Symbol]) { (Array[Symbol], Node, Proc) -> void } -> void
799
1189
  end
800
1190
  end
801
1191
  end