decode 0.24.2 → 0.24.4

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 +5 -2
  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 +6 -2
  13. data/lib/decode/comment/rbs.rb +8 -8
  14. data/lib/decode/comment/tag.rb +19 -0
  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 +12 -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 -65
  35. data/lib/decode/rbs/module.rb +81 -5
  36. data/lib/decode/rbs/type.rb +51 -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 +29 -21
  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 +1189 -0
  47. data.tar.gz.sig +0 -0
  48. metadata +5 -15
  49. metadata.gz.sig +0 -0
data/sig/decode.rbs ADDED
@@ -0,0 +1,1189 @@
1
+ module Decode
2
+ VERSION: String
3
+
4
+ # Represents comment parsing and processing functionality.
5
+ module Comment
6
+ # Describes an attribute type.
7
+ #
8
+ # - `@attribute [Integer] The person's age.`
9
+ class Attribute < Tag
10
+ PATTERN: Regexp
11
+
12
+ attr_reader type(@type): String
13
+
14
+ @type: String
15
+
16
+ # Build an attribute from a directive and match.
17
+ public def self.build: (String directive, MatchData match) -> untyped
18
+
19
+ # Initialize a new attribute.
20
+ public def initialize: (String directive, String type) -> void
21
+ end
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
+
40
+ # Represents a node in a comment tree structure.
41
+ class Node
42
+ attr_reader children(@children): Array[Node | Text]?
43
+
44
+ @children: Array[Node | Text]?
45
+
46
+ # Initialize the node.
47
+ public def initialize: (Array[Node | Text]? children) -> void
48
+
49
+ # Whether this node has any children nodes.
50
+ # Ignores {Text} instances.
51
+ public def children?: () -> bool
52
+
53
+ # Add a child node to this node.
54
+ public def add: (Node | Text child) -> self
55
+
56
+ # Enumerate all non-text children nodes.
57
+ public def each: () { (Node node) -> void } -> (Enumerator[Node] | self)
58
+
59
+ # Filter children nodes by class type.
60
+ public def filter: (Class klass) { (Object node) -> void } -> (Enumerator[Node] | self)
61
+
62
+ # Any lines of text associated with this node.
63
+ public def text: () -> Array[String]?
64
+
65
+ # Traverse the tags from this node using {each}. Invoke `descend.call(child)` to recursively traverse the specified child.
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]?
70
+ end
71
+
72
+ # Describes a method option (keyword argument).
73
+ #
74
+ # - `@option :cached [bool] Whether to cache the value.`
75
+ class Option < Parameter
76
+ end
77
+
78
+ # Represents a named method parameter.
79
+ #
80
+ # - `@parameter age [Float] The users age.`
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
+
92
+ # Build a parameter from a directive and regex match.
93
+ public def self.build: (String directive, MatchData match) -> Parameter
94
+
95
+ # Initialize a new parameter.
96
+ public def initialize: (String directive, String name, String type) -> void
97
+ end
98
+
99
+ # Asserts a specific property about the method signature.
100
+ #
101
+ # - `@reentrant This method is thread-safe.`
102
+ # - `@deprecated Please use {other_method} instead.`
103
+ # - `@blocking This method may block.`
104
+ # - `@asynchronous This method may yield.`
105
+ class Pragma < Tag
106
+ # Parse a pragma directive from text.
107
+ public def self.parse: (String directive, String text, Array[String] lines, Array[Tag] tags, ?Integer level) -> untyped
108
+
109
+ # Build a pragma from a directive and text.
110
+ public def self.build: (String directive, String text) -> untyped
111
+
112
+ # Initialize a new pragma.
113
+ public def initialize: (String directive) -> void
114
+ end
115
+
116
+ # Identifies that a method might raise an exception.
117
+ #
118
+ # - `@raises [ArgumentError] If the argument cannot be coerced.`
119
+ class Raises < Attribute
120
+ end
121
+
122
+ # Represents an RBS type annotation following rbs-inline syntax.
123
+ #
124
+ # Examples:
125
+ # - `@rbs generic T` - Declares a generic type parameter for a class
126
+ # - `@rbs [T] () { () -> T } -> Task[T]` - Complete method type signature
127
+ class RBS < Tag
128
+ attr_reader text(@text): String
129
+
130
+ @text: String
131
+
132
+ # Parse an RBS pragma from text.
133
+ public def self.parse: (String directive, String text, Array[String] lines, Array[Tag] tags, ?Integer level) -> untyped
134
+
135
+ # Build an RBS pragma from a directive and text.
136
+ public def self.build: (String directive, String text) -> untyped
137
+
138
+ # Initialize a new RBS pragma.
139
+ public def initialize: (String directive, String? text) -> void
140
+
141
+ # Check if this is a generic type declaration.
142
+ public def generic?: () -> bool
143
+
144
+ # Extract the generic type parameter name.
145
+ public def generic_parameter: () -> String?
146
+
147
+ # Check if this is a method type signature.
148
+ public def method_signature?: () -> bool
149
+
150
+ # Get the method type signature text.
151
+ public def method_signature: () -> String?
152
+ end
153
+
154
+ # Represents a return value.
155
+ #
156
+ # Example: `@returns [Integer] The person's age.`
157
+ class Returns < Attribute
158
+ end
159
+
160
+ # Represents a documentation tag parsed from a comment directive.
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
+
173
+ # Build a pattern for bracketed content, supporting nested brackets.
174
+ public def self.bracketed_content: (Symbol name) -> String
175
+
176
+ # Match text against the tag pattern.
177
+ public def self.match: (String text) -> untyped
178
+
179
+ # Parse a tag from a directive and text.
180
+ public def self.parse: (String directive, String text, Array[String] lines, Tags tags, ?Integer level) -> untyped
181
+
182
+ # Initialize a new tag.
183
+ public def initialize: (String directive) -> void
184
+ end
185
+
186
+ # Represents a collection of documentation tags and their parsing logic.
187
+ class Tags
188
+ PATTERN: Regexp
189
+
190
+ # Build a tags parser with directive mappings.
191
+ public def self.build: () { (Hash[String, Class]) -> void } -> Tags
192
+
193
+ # Initialize a new tags parser.
194
+ public def initialize: (Hash[String, _Directive] directives) -> void
195
+
196
+ # Check if a line has valid indentation for the given level.
197
+ public def valid_indentation?: (String line, Integer level) -> bool
198
+
199
+ # Parse documentation tags from lines.
200
+ public def parse: (Array[String] lines, ?Integer level) { (Node | Text) -> void } -> void
201
+
202
+ # Ignore lines at the specified indentation level.
203
+ public def ignore: (Array[String] lines, ?Integer level) -> untyped
204
+ end
205
+
206
+ # A structured comment.
207
+ class Text
208
+ attr_reader line(@line): String
209
+
210
+ @line: String
211
+
212
+ # Initialize a new text node.
213
+ public def initialize: (String line) -> void
214
+
215
+ # Traverse the text node.
216
+ public def traverse: () -> untyped
217
+ end
218
+
219
+ # Identifies that a method might throw a specific symbol.
220
+ #
221
+ # - `@throws [:skip] To skip recursion.`
222
+ class Throws < Attribute
223
+ end
224
+
225
+ # Describes a block parameter.
226
+ #
227
+ # - `@yields {|person| ... } If a block is given.`
228
+ #
229
+ # Should contain nested parameters.
230
+ class Yields < Tag
231
+ PATTERN: Regexp
232
+
233
+ # Build a yields tag from a directive and match.
234
+ public def self.build: (String directive, MatchData match) -> untyped
235
+
236
+ # Initialize a new yields tag.
237
+ public def initialize: (String directive, String block) -> void
238
+ end
239
+ end
240
+
241
+ # A symbol with attached documentation.
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
+
267
+ # Initialize the symbol.
268
+ public def initialize: (Symbol | Array[Symbol] path, ?parent: Definition?, ?language: Language::Generic?, ?comments: Array[String]?, ?visibility: Symbol, ?source: Source?) -> void
269
+
270
+ # Generate a debug representation of the definition.
271
+ public def inspect: () -> untyped
272
+
273
+ public def name: () -> untyped
274
+
275
+ # The full path to the definition.
276
+ public def full_path: () -> Array[Symbol]
277
+
278
+ # Whether the definition is considered part of the public interface.
279
+ # This is used to determine whether the definition should be documented for coverage purposes.
280
+ public def public?: () -> bool
281
+
282
+ # Whether the definition has documentation.
283
+ public def documented?: () -> bool
284
+
285
+ # The qualified name is an absolute name which includes any and all namespacing.
286
+ public def qualified_name: () -> String
287
+
288
+ public def nested_name: () -> String
289
+
290
+ # Does the definition name match the specified prefix?
291
+ public def start_with?: (String prefix) -> bool
292
+
293
+ # Convert this definition into another kind of definition.
294
+ public def convert: (Symbol kind) -> untyped
295
+
296
+ # A short form of the definition.
297
+ # e.g. `def short_form`.
298
+ public def short_form: () -> String?
299
+
300
+ # A long form of the definition.
301
+ # e.g. `def initialize(kind, name, comments, **options)`.
302
+ public def long_form: () -> String?
303
+
304
+ # A long form which uses the qualified name if possible.
305
+ # Defaults to {long_form}.
306
+ public def qualified_form: () -> String?
307
+
308
+ # Whether the definition spans multiple lines.
309
+ public def multiline?: () -> bool
310
+
311
+ # The full text of the definition.
312
+ public def text: () -> String?
313
+
314
+ # Whether this definition can contain nested definitions.
315
+ public def container?: () -> bool
316
+
317
+ # Whether this represents a single entity to be documented (along with it's contents).
318
+ public def nested?: () -> bool
319
+
320
+ # Structured access to the definitions comments.
321
+ public def documentation: () -> Documentation?
322
+
323
+ # The location of the definition.
324
+ public def location: () -> Location?
325
+ end
326
+
327
+ # Structured access to a set of comment lines.
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
+
337
+ # Initialize the documentation with an array of comments, within a specific language.
338
+ public def initialize: (Array[String] comments, Language::Generic? language) -> void
339
+ end
340
+
341
+ # Represents a list of definitions organised for quick lookup and lexical enumeration.
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
+
359
+ # Create and populate an index from the given paths.
360
+ public def self.for: (*String, ?languages: Languages) -> Index
361
+
362
+ # Initialize an empty index.
363
+ public def initialize: (?Languages languages) -> void
364
+
365
+ # Generate a string representation of this index.
366
+ public def inspect: () -> String
367
+
368
+ # Updates the index by parsing the specified files.
369
+ # All extracted definitions are merged into the existing index.
370
+ public def update: (Array[String] paths) -> untyped
371
+
372
+ # Lookup the specified reference and return matching definitions.
373
+ public def lookup: (Language::Reference reference, ?relative_to: Definition?) -> Definition?
374
+ end
375
+
376
+ # Language specific parsers and definitions.
377
+ module Language
378
+ # Represents a generic language implementation that can be extended for specific languages.
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
+
392
+ # Initialize a new generic language.
393
+ public def initialize: (String name, ?extensions: Array[String], ?tags: Comment::Tags) -> void
394
+
395
+ # Get all names for this language.
396
+ public def names: () -> Array[String]
397
+
398
+ # Generate a language-specific reference.
399
+ public def reference_for: (String identifier) -> Reference
400
+
401
+ # Get the parser for this language.
402
+ public def parser: () -> untyped
403
+
404
+ # Parse the input yielding definitions.
405
+ public def definitions_for: (Source source) { (Definition definition) -> void } -> Enumerator[Segment]
406
+
407
+ # Parse the input yielding segments.
408
+ # Segments are constructed from a block of top level comments followed by a block of code.
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
413
+ end
414
+
415
+ # An reference which can be resolved to zero or more definitions.
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
+
425
+ # Initialize the reference.
426
+ public def initialize: (String identifier, Language::Generic language, ?Array[String]? lexical_path) -> void
427
+
428
+ # Generate a string representation of the reference.
429
+ public def to_s: () -> untyped
430
+
431
+ # Generate a debug representation of the reference.
432
+ public def inspect: () -> untyped
433
+
434
+ # Whether the reference starts at the base of the lexical tree.
435
+ public def absolute?: () -> bool
436
+
437
+ # Check if this is a relative reference.
438
+ public def relative?: () -> bool
439
+
440
+ # Split an identifier into prefix and name components.
441
+ public def split: (String identifier) -> untyped
442
+
443
+ # Get the lexical path of this reference.
444
+ public def lexical_path: () -> untyped
445
+
446
+ # Calculate the priority of a definition for matching.
447
+ public def priority: (String definition, String prefix) -> untyped
448
+
449
+ # Find the best matching definition from a list.
450
+ public def best: (Array[Definition] definitions) -> Definition?
451
+
452
+ # The lexical path of the reference.
453
+ public def path: () -> Array[Symbol]
454
+ end
455
+
456
+ # Represents an interface for extracting information from Ruby source code.
457
+ module Ruby
458
+ # Create a new Ruby language instance.
459
+ public def self.new: () -> Ruby::Generic
460
+
461
+ # Represents an alias statement, e.g., `alias new_name old_name` or `alias_method :new_name, :old_name`
462
+ class Alias < Definition
463
+ # Initialize a new alias definition.
464
+ public def initialize: (String new_name, String old_name, **Hash options) -> void
465
+
466
+ # Generate a short form representation of the alias.
467
+ public def short_form: () -> untyped
468
+
469
+ # Generate a long form representation of the alias.
470
+ public def long_form: () -> untyped
471
+
472
+ # Generate a string representation of the alias.
473
+ public def to_s: () -> untyped
474
+ end
475
+
476
+ # A Ruby-specific attribute.
477
+ class Attribute < Definition
478
+ # The short form of the attribute.
479
+ # e.g. `attr :value`.
480
+ public def short_form: () -> untyped
481
+
482
+ # Generate a long form representation of the attribute.
483
+ public def long_form: () -> untyped
484
+ end
485
+
486
+ # A Ruby-specific block which might carry other definitions.
487
+ class Block < Definition
488
+ # A block can sometimes be a container for other definitions.
489
+ public def container?: () -> bool
490
+
491
+ # Generate a nested name for the block.
492
+ public def nested_name: () -> untyped
493
+
494
+ # The short form of the block.
495
+ # e.g. `foo`.
496
+ public def short_form: () -> untyped
497
+
498
+ # The long form of the block.
499
+ # e.g. `foo(:bar)`.
500
+ public def long_form: () -> untyped
501
+
502
+ # The fully qualified name of the block.
503
+ # e.g. `::Barnyard::foo`.
504
+ public def qualified_form: () -> untyped
505
+
506
+ # Convert the block to a different kind of definition.
507
+ public def convert: (Symbol kind) -> untyped
508
+ end
509
+
510
+ # A Ruby-specific block which might carry other definitions.
511
+ class Call < Definition
512
+ # A block can sometimes be a container for other definitions.
513
+ public def container?: () -> bool
514
+
515
+ # The short form of the class.
516
+ # e.g. `foo`.
517
+ public def short_form: () -> untyped
518
+
519
+ # The long form of the class.
520
+ # e.g. `foo(:bar)`.
521
+ public def long_form: () -> untyped
522
+
523
+ # The fully qualified name of the block.
524
+ # e.g. `class ::Barnyard::Dog`.
525
+ public def qualified_form: () -> untyped
526
+ end
527
+
528
+ # A Ruby-specific class.
529
+ class Class < Definition
530
+ # Initialize a new class definition.
531
+ public def initialize: (*Array arguments, ?super_class: String, **Hash options) -> void
532
+
533
+ # A class is a container for other definitions.
534
+ public def container?: () -> bool
535
+
536
+ # The short form of the class.
537
+ # e.g. `class Animal`.
538
+ public def short_form: () -> untyped
539
+
540
+ # The long form of the class.
541
+ # e.g. `class Dog < Animal`.
542
+ public def long_form: () -> untyped
543
+
544
+ # The fully qualified name of the class.
545
+ # e.g. `class ::Barnyard::Dog`.
546
+ public def qualified_form: () -> untyped
547
+ end
548
+
549
+ # A Ruby-specific singleton class.
550
+ class Singleton < Definition
551
+ # Generate a nested name for the singleton class.
552
+ public def nested_name: () -> untyped
553
+
554
+ # A singleton class is a container for other definitions.
555
+ public def container?: () -> bool
556
+
557
+ # Typically, a singleton class does not contain other definitions.
558
+ public def nested?: () -> bool
559
+
560
+ # The short form of the class.
561
+ # e.g. `class << self`.
562
+ public def short_form: () -> untyped
563
+
564
+ private def absolute_path: () -> untyped
565
+ end
566
+
567
+ # A Ruby-specific block of code.
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
+
589
+ # Initialize a new code block.
590
+ public def initialize: (String text, Index index, language: Language::Generic, ?relative_to: Definition?) -> void
591
+
592
+ # Extract definitions from the code.
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
597
+ end
598
+
599
+ # A Ruby-specific constant.
600
+ class Constant < Definition
601
+ # The short form of the constant.
602
+ # e.g. `NAME`.
603
+ public def short_form: () -> untyped
604
+
605
+ # Generate a nested name for the constant.
606
+ public def nested_name: () -> untyped
607
+
608
+ # The long form of the constant.
609
+ # e.g. `NAME = "Alice"`.
610
+ public def long_form: () -> untyped
611
+ end
612
+
613
+ # Represents a Ruby-specific definition extracted from source code.
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
+
623
+ # Initialize the definition from the syntax tree node.
624
+ public def initialize: (*Array arguments, ?visibility: Symbol, ?node: Parser::AST::Node, **Hash options) -> void
625
+
626
+ # Check if this definition is public.
627
+ public def public?: () -> bool
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
+
635
+ # Check if this definition spans multiple lines.
636
+ public def multiline?: () -> bool
637
+
638
+ # The source code associated with the definition.
639
+ public def text: () -> String
640
+
641
+ # Get the location of this definition.
642
+ public def location: () -> Location?
643
+ end
644
+
645
+ # A Ruby-specific function.
646
+ class Function < Method
647
+ # Generate a nested name for the function.
648
+ public def nested_name: () -> untyped
649
+
650
+ # The node which contains the function arguments.
651
+ public def arguments_node: () -> untyped
652
+ end
653
+
654
+ # Represents the Ruby language implementation for parsing and analysis.
655
+ class Generic < Language::Generic
656
+ # Get the parser for Ruby source code.
657
+ public def parser: () -> Language::Ruby::Parser
658
+
659
+ # Generate a language-specific reference for Ruby.
660
+ public def reference_for: (String identifier) -> Reference
661
+
662
+ # Generate a code representation with syntax highlighting and link resolution.
663
+ public def code_for: (String text, Index index, ?relative_to: Definition) -> Code
664
+ end
665
+
666
+ # A Ruby-specific method.
667
+ class Method < Definition
668
+ # Initialize a new method definition.
669
+ public def initialize: (*Array arguments, ?receiver: String, **Hash options) -> void
670
+
671
+ # Generate a nested name for the method.
672
+ public def nested_name: () -> untyped
673
+
674
+ # The short form of the method.
675
+ # e.g. `def puts` or `def self.puts`.
676
+ public def short_form: () -> untyped
677
+
678
+ # The node which contains the function arguments.
679
+ public def arguments_node: () -> untyped
680
+
681
+ # The long form of the method.
682
+ # e.g. `def puts(*lines, separator: "\n")` or `def self.puts(*lines, separator: "\n")`.
683
+ public def long_form: () -> untyped
684
+
685
+ # The fully qualified name of the block.
686
+ # e.g. `::Barnyard#foo`.
687
+ public def qualified_form: () -> untyped
688
+
689
+ # Override the qualified_name method to handle method name joining correctly
690
+ public def qualified_name: () -> untyped
691
+
692
+ # Convert the method to a different kind of definition.
693
+ public def convert: (Symbol kind) -> untyped
694
+ end
695
+
696
+ # A Ruby-specific module.
697
+ class Module < Definition
698
+ # A module is a container for other definitions.
699
+ public def container?: () -> bool
700
+
701
+ # The short form of the module.
702
+ # e.g. `module Barnyard`.
703
+ public def short_form: () -> untyped
704
+
705
+ # Generate a long form representation of the module.
706
+ public def long_form: () -> untyped
707
+
708
+ # The fully qualified name of the module.
709
+ # e.g. `module ::Barnyard::Dog`.
710
+ public def qualified_form: () -> untyped
711
+ end
712
+
713
+ # The Ruby source code parser.
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
+
727
+ # Initialize a new Ruby parser.
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
735
+
736
+ # Extract definitions from the given input file.
737
+ public def definitions_for: (Source source) -> Enumerator[Definition]
738
+
739
+ # Walk over the syntax tree and extract relevant definitions with their associated comments.
740
+ public def walk_definitions: (untyped node, ?Definition? parent, ?Source? source) -> untyped
741
+
742
+ # Extract segments from the given input file.
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
780
+ end
781
+
782
+ # An Ruby-specific reference which can be resolved to zero or more definitions.
783
+ class Reference < Language::Reference
784
+ # Create a reference from a constant node.
785
+ public def self.from_const: (Prism::Node node, Language::Generic language) -> Reference
786
+
787
+ # Append a constant node to the path.
788
+ public def self.append_const: (Prism::Node node, ?Array path) -> Array
789
+
790
+ # Split a Ruby identifier into prefix and name components.
791
+ public def split: (String text) -> Array
792
+ end
793
+
794
+ # A Ruby specific code segment.
795
+ class Segment < Decode::Segment
796
+ # Initialize a new Ruby segment.
797
+ public def initialize: (Array[String] comments, Generic language, Prism::Node node, **Hash options) -> void
798
+
799
+ # Expand the segment to include another node.
800
+ public def expand: (Prism::Node node) -> untyped
801
+
802
+ # The source code trailing the comments.
803
+ public def code: () -> String?
804
+ end
805
+ end
806
+ end
807
+
808
+ # Represents a context for looking up languages based on file extension or name.
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
+
820
+ # Create a new languages context with all supported languages.
821
+ public def self.all: () -> Languages
822
+
823
+ # Initialize a new languages context.
824
+ public def initialize: () -> void
825
+
826
+ # Freeze the languages context to prevent further modifications.
827
+ public def freeze: () -> untyped
828
+
829
+ # Add a language to this context.
830
+ public def add: (Language::Generic language) -> self
831
+
832
+ # Fetch a language by name, creating a generic language if needed.
833
+ public def fetch: (String name) -> Language::Generic?
834
+
835
+ # Create a source object for the given file path.
836
+ public def source_for: (String path) -> Source?
837
+
838
+ # Parse a language agnostic reference.
839
+ public def parse_reference: (String text, ?default_language: Language::Generic?) -> Language::Reference?
840
+
841
+ # Create a reference for the given language and identifier.
842
+ public def reference_for: (String name, String identifier) -> Language::Reference?
843
+ end
844
+
845
+ # Represents a location in a source file.
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
+ public def initialize: (untyped path, untyped line) -> void
856
+
857
+ # Generate a string representation of the location.
858
+ public def to_s: () -> untyped
859
+ end
860
+
861
+ # RBS generation functionality for Ruby type signatures.
862
+ module RBS
863
+ # Represents a Ruby class definition wrapper for RBS generation.
864
+ class Class < Wrapper
865
+ # Initialize a new class wrapper.
866
+ public def initialize: (Decode::Definition definition) -> void
867
+
868
+ # Extract generic type parameters from the class definition.
869
+ public def generics: () -> Array[Symbol]
870
+
871
+ # Convert the class definition to RBS AST
872
+ public def to_rbs_ast: (?untyped method_definitions, ?untyped constant_definitions, ?untyped attribute_definitions, ?untyped index) -> untyped
873
+
874
+ private def extract_generics: () -> untyped
875
+
876
+ # Build a constant RBS declaration.
877
+ private def build_constant_rbs: (untyped constant_definition) -> untyped
878
+
879
+ # Convert a simple name to RBS TypeName (not qualified).
880
+ private def simple_name_to_rbs: (untyped name) -> untyped
881
+
882
+ # Build attribute RBS declarations and infer instance variable types.
883
+ private def build_attributes_rbs: (Array attribute_definitions) -> Array
884
+
885
+ # Convert a qualified name to RBS TypeName
886
+ private def qualified_name_to_rbs: (untyped qualified_name) -> untyped
887
+ end
888
+
889
+ # Represents a generator for RBS type declarations.
890
+ class Generator
891
+ attr_reader loader(@loader): ::RBS::EnvironmentLoader
892
+
893
+ attr_reader environment(@environment): ::RBS::Environment
894
+
895
+ attr_reader include_private(@include_private): bool
896
+
897
+ @loader: ::RBS::EnvironmentLoader
898
+
899
+ @environment: ::RBS::Environment
900
+
901
+ @include_private: bool
902
+
903
+ # Initialize a new RBS generator.
904
+ # Sets up the RBS environment for type resolution.
905
+ public def initialize: (?include_private: bool) -> void
906
+
907
+ # Generate RBS declarations for the given index.
908
+ public def generate: (Decode::Index index, ?output: IO) -> untyped
909
+
910
+ # Build nested RBS declarations preserving the parent hierarchy.
911
+ private def build_nested_declaration: (Definition definition, Hash declarations, Index index) -> untyped?
912
+
913
+ # Convert a definition to RBS AST.
914
+ private def definition_to_rbs: (Definition definition, Index index) -> untyped
915
+
916
+ # Get methods for a given definition efficiently using trie lookup.
917
+ private def get_methods_for_definition: (Definition definition, Index index) -> Array
918
+
919
+ # Get constants for a given definition efficiently using trie lookup.
920
+ private def get_constants_for_definition: (Definition definition, Index index) -> Array
921
+
922
+ # Get attributes for a given definition efficiently using trie lookup.
923
+ private def get_attributes_for_definition: (Definition definition, Index index) -> Array
924
+ end
925
+
926
+ # Represents a Ruby method definition wrapper for RBS generation.
927
+ class Method < Wrapper
928
+ # Initialize a new method wrapper.
929
+ public def initialize: (Decode::Definition definition) -> void
930
+
931
+ # Extract method signatures from the method definition.
932
+ public def signatures: () -> Array
933
+
934
+ # Extract keyword arguments from the method definition.
935
+ public def keyword_arguments: () -> Hash
936
+
937
+ # Extract return type from the method definition.
938
+ public def return_type: () -> ::RBS::Types::t
939
+
940
+ # Extract parameters from the method definition.
941
+ public def parameters: () -> Array
942
+
943
+ # Convert the method definition to RBS AST
944
+ public def to_rbs_ast: (?untyped index) -> untyped
945
+
946
+ # Build a complete RBS function type from AST information.
947
+ public def build_function_type_from_ast: (Definition definition, Index index) -> RBS::Types::Function
948
+
949
+ private def extract_signatures: () -> untyped
950
+
951
+ # Extract return type from method documentation.
952
+ private def extract_return_type: (untyped definition, untyped index) -> untyped
953
+
954
+ # Extract parameter types from method documentation.
955
+ private def extract_parameters: (untyped definition, untyped index) -> untyped
956
+
957
+ # Extract parameter information from the Prism AST node.
958
+ private def extract_parameters_from_ast: (Definition definition) -> Array
959
+
960
+ # Extract keyword arguments from @option tags and AST.
961
+ private def extract_keyword_arguments: (untyped definition, untyped index) -> untyped
962
+
963
+ # Extract keyword arguments from the Prism AST node.
964
+ private def extract_keyword_arguments_from_ast: (Definition definition) -> Hash
965
+
966
+ # Extract documented parameter types into a hash for lookup.
967
+ private def extract_documented_parameter_types: (Definition definition) -> Hash
968
+
969
+ # Make a type optional if it's not already nullable.
970
+ private def make_type_optional_if_needed: (RBS::Types::t type) -> RBS::Types::t
971
+
972
+ # Extract block type from method documentation.
973
+ private def extract_block_type: (untyped definition, untyped index) -> untyped
974
+
975
+ # Infer return type based on method patterns and heuristics.
976
+ private def infer_return_type: (untyped definition) -> untyped
977
+ end
978
+
979
+ # Represents a Ruby module definition wrapper for RBS generation.
980
+ class Module < Wrapper
981
+ # Initialize a new module wrapper.
982
+ public def initialize: (Decode::Definition definition) -> void
983
+
984
+ # Convert the module definition to RBS AST
985
+ public def to_rbs_ast: (?Array[Method] method_definitions, ?Array[Constant] constant_definitions, ?Array[Attribute] attribute_definitions, ?Index? index) -> RBS::AST::Declarations::Module
986
+
987
+ # Build a constant RBS declaration.
988
+ private def build_constant_rbs: (untyped constant_definition) -> untyped
989
+
990
+ # Convert a simple name to RBS TypeName (not qualified).
991
+ private def simple_name_to_rbs: (untyped name) -> untyped
992
+
993
+ # Build attribute RBS declarations and infer instance variable types.
994
+ private def build_attributes_rbs: (Array attribute_definitions) -> Array
995
+ end
996
+
997
+ module Type
998
+ # Check if an RBS type represents a nullable/optional type
999
+ # This method recursively traverses the type tree to find nil anywhere
1000
+ public def self.nullable?: (untyped rbs_type) -> bool
1001
+
1002
+ # Parse a type string and convert it to RBS type
1003
+ public def self.parse: (String type_string) -> untyped
1004
+ end
1005
+
1006
+ # Base wrapper class for RBS generation from definitions.
1007
+ class Wrapper
1008
+ # Initialize the wrapper instance variables.
1009
+ public def initialize: (Definition definition) -> void
1010
+
1011
+ # Extract RBS tags from the definition's documentation.
1012
+ public def tags: () -> Array
1013
+
1014
+ # Extract comment from the definition's documentation.
1015
+ public def comment: () -> RBS::AST::Comment?
1016
+
1017
+ # Extract RBS tags from the definition's documentation.
1018
+ private def extract_tags: () -> Array
1019
+
1020
+ # Extract comment from definition documentation.
1021
+ private def extract_comment: (?Definition definition) -> RBS::AST::Comment?
1022
+ end
1023
+ end
1024
+
1025
+ # An abstract namespace for nesting definitions.
1026
+ class Scope < Definition
1027
+ public def short_form: () -> String
1028
+
1029
+ # Scopes are always containers.
1030
+ public def container?: () -> bool
1031
+ end
1032
+
1033
+ # A chunk of code with an optional preceeding comment block.
1034
+ #
1035
+ # ~~~ ruby
1036
+ # # Get the first segment from a source file:
1037
+ # segment = source.segments.first
1038
+ # ~~~
1039
+ class Segment
1040
+ attr_reader comments(@comments): Array[String]
1041
+
1042
+ attr_reader language(@language): Language::Generic
1043
+
1044
+ @comments: Array[String]
1045
+
1046
+ @language: Language::Generic
1047
+
1048
+ # Initialize a new segment.
1049
+ public def initialize: (Array[String] comments, Language::Generic language) -> void
1050
+
1051
+ # An interface for accsssing the documentation of the definition.
1052
+ public def documentation: () -> Documentation?
1053
+
1054
+ # The source code trailing the comments.
1055
+ public def code: () -> String?
1056
+ end
1057
+
1058
+ # Represents a source file in a specific language.
1059
+ class Source
1060
+ attr_reader path(@path): StringPath
1061
+
1062
+ attr_reader language(@language): Language::Generic
1063
+
1064
+ @path: StringPath
1065
+
1066
+ @language: Language::Generic
1067
+
1068
+ # Initialize a new source file.
1069
+ public def initialize: (String path, Language::Generic language) -> void
1070
+
1071
+ # Read the source file into an internal buffer/cache.
1072
+ public def read: () -> String
1073
+
1074
+ # Open the source file and read all definitions.
1075
+ public def definitions: () { (Definition definition) -> void } -> Enumerator[Definition]
1076
+
1077
+ # Open the source file and read all segments.
1078
+ public def segments: () { (Segment segment) -> void } -> Enumerator[Segment]
1079
+
1080
+ # Generate code representation with optional index for link resolution.
1081
+ public def code: (?Index? index, ?relative_to: Definition?) -> String
1082
+ end
1083
+
1084
+ # Provides syntax rewriting and linking functionality.
1085
+ module Syntax
1086
+ # Represents a link to a definition in the documentation.
1087
+ class Link < Match
1088
+ # Initialize a new link.
1089
+ public def initialize: (Range range, Definition definition) -> void
1090
+
1091
+ # Apply the link to the output.
1092
+ public def apply: (String output, Rewriter rewriter) -> untyped
1093
+ end
1094
+
1095
+ # Represents a match in the source text for syntax rewriting.
1096
+ class Match
1097
+ # Initialize a new match.
1098
+ public def initialize: (Range range) -> void
1099
+
1100
+ # Apply the match to extract text from source.
1101
+ public def apply: (String source) -> untyped
1102
+
1103
+ # Apply the match to the output.
1104
+ public def apply: (String output, Rewriter rewriter) -> untyped
1105
+
1106
+ # Compare matches by their starting position.
1107
+ public def <=>: (Match other) -> untyped
1108
+
1109
+ # Get the starting offset of this match.
1110
+ public def offset: () -> untyped
1111
+
1112
+ # Get the size of this match.
1113
+ public def size: () -> untyped
1114
+ end
1115
+
1116
+ # Provides text rewriting functionality with match-based substitutions.
1117
+ class Rewriter
1118
+ attr_reader text(@text): String
1119
+
1120
+ attr_reader matches(@matches): Array[Match]
1121
+
1122
+ @text: String
1123
+
1124
+ @matches: Array[Match]
1125
+
1126
+ # Initialize a new rewriter.
1127
+ public def initialize: (String text) -> void
1128
+
1129
+ # Add a match to the rewriter.
1130
+ public def <<: (Match match) -> self
1131
+
1132
+ # Returns a chunk of raw text with no formatting.
1133
+ public def text_for: (untyped range) -> untyped
1134
+
1135
+ # Apply all matches to generate the rewritten output.
1136
+ public def apply: (?Array output) -> untyped
1137
+
1138
+ # Generate a link to a definition.
1139
+ public def link_to: (Definition definition, String text) -> untyped
1140
+ end
1141
+ end
1142
+
1143
+ # Represents a prefix-trie data structure for fast lexical lookups.
1144
+ class Trie[T]
1145
+ attr_reader root(@root): Node
1146
+
1147
+ @root: Node
1148
+
1149
+ # Initialize an empty trie.
1150
+ public def initialize: () -> void
1151
+
1152
+ # Insert the specified value at the given path into the trie.
1153
+ public def insert: (Array[Symbol] path, T value) -> untyped
1154
+
1155
+ # Lookup the values at the specified path.
1156
+ public def lookup: (Array[Symbol] path) -> Node?
1157
+
1158
+ # Enumerate all lexical scopes under the specified path.
1159
+ public def each: (?Array[Symbol]) { (Array[Symbol], Array[T] | nil) -> void } -> void
1160
+
1161
+ # Traverse the trie starting from the specified path.
1162
+ # See {Node#traverse} for details.
1163
+ public def traverse: (?Array[Symbol]) { (Array[Symbol], Node, Proc) -> void } -> void
1164
+
1165
+ # Represents a single node in the trie.
1166
+ class Node
1167
+ attr_reader values(@values): Array[T]?
1168
+
1169
+ attr_reader children(@children): Hash[Symbol, Node]
1170
+
1171
+ @values: Array[T]?
1172
+
1173
+ @children: Hash[Symbol, Node]
1174
+
1175
+ # Initialize an empty node.
1176
+ public def initialize: () -> void
1177
+
1178
+ # Generate a string representation of this node.
1179
+ public def inspect: () -> String
1180
+
1181
+ # Look up a lexical path starting at this node.
1182
+ public def lookup: (Array[Symbol] path, ?Integer index) -> Node?
1183
+
1184
+ # Traverse the trie from this node.
1185
+ # Invoke `descend.call` to traverse the children of the current node.
1186
+ public def traverse: (?Array[Symbol]) { (Array[Symbol], Node, Proc) -> void } -> void
1187
+ end
1188
+ end
1189
+ end