rubydex 0.1.0.beta12-aarch64-linux

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 (109) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +23 -0
  3. data/README.md +125 -0
  4. data/THIRD_PARTY_LICENSES.html +4562 -0
  5. data/exe/rdx +47 -0
  6. data/ext/rubydex/declaration.c +453 -0
  7. data/ext/rubydex/declaration.h +23 -0
  8. data/ext/rubydex/definition.c +284 -0
  9. data/ext/rubydex/definition.h +28 -0
  10. data/ext/rubydex/diagnostic.c +6 -0
  11. data/ext/rubydex/diagnostic.h +11 -0
  12. data/ext/rubydex/document.c +97 -0
  13. data/ext/rubydex/document.h +10 -0
  14. data/ext/rubydex/extconf.rb +138 -0
  15. data/ext/rubydex/graph.c +681 -0
  16. data/ext/rubydex/graph.h +10 -0
  17. data/ext/rubydex/handle.h +44 -0
  18. data/ext/rubydex/location.c +22 -0
  19. data/ext/rubydex/location.h +15 -0
  20. data/ext/rubydex/reference.c +123 -0
  21. data/ext/rubydex/reference.h +15 -0
  22. data/ext/rubydex/rubydex.c +22 -0
  23. data/ext/rubydex/utils.c +108 -0
  24. data/ext/rubydex/utils.h +34 -0
  25. data/lib/rubydex/3.2/rubydex.so +0 -0
  26. data/lib/rubydex/3.3/rubydex.so +0 -0
  27. data/lib/rubydex/3.4/rubydex.so +0 -0
  28. data/lib/rubydex/4.0/rubydex.so +0 -0
  29. data/lib/rubydex/comment.rb +17 -0
  30. data/lib/rubydex/diagnostic.rb +21 -0
  31. data/lib/rubydex/failures.rb +15 -0
  32. data/lib/rubydex/graph.rb +98 -0
  33. data/lib/rubydex/keyword.rb +17 -0
  34. data/lib/rubydex/keyword_parameter.rb +13 -0
  35. data/lib/rubydex/librubydex_sys.so +0 -0
  36. data/lib/rubydex/location.rb +90 -0
  37. data/lib/rubydex/mixin.rb +22 -0
  38. data/lib/rubydex/version.rb +5 -0
  39. data/lib/rubydex.rb +23 -0
  40. data/rbi/rubydex.rbi +422 -0
  41. data/rust/Cargo.lock +1851 -0
  42. data/rust/Cargo.toml +29 -0
  43. data/rust/about.hbs +78 -0
  44. data/rust/about.toml +10 -0
  45. data/rust/rubydex/Cargo.toml +42 -0
  46. data/rust/rubydex/src/compile_assertions.rs +13 -0
  47. data/rust/rubydex/src/diagnostic.rs +110 -0
  48. data/rust/rubydex/src/errors.rs +28 -0
  49. data/rust/rubydex/src/indexing/local_graph.rs +224 -0
  50. data/rust/rubydex/src/indexing/rbs_indexer.rs +1551 -0
  51. data/rust/rubydex/src/indexing/ruby_indexer.rs +2329 -0
  52. data/rust/rubydex/src/indexing/ruby_indexer_tests.rs +4962 -0
  53. data/rust/rubydex/src/indexing.rs +210 -0
  54. data/rust/rubydex/src/integrity.rs +279 -0
  55. data/rust/rubydex/src/job_queue.rs +205 -0
  56. data/rust/rubydex/src/lib.rs +17 -0
  57. data/rust/rubydex/src/listing.rs +371 -0
  58. data/rust/rubydex/src/main.rs +160 -0
  59. data/rust/rubydex/src/model/built_in.rs +83 -0
  60. data/rust/rubydex/src/model/comment.rs +24 -0
  61. data/rust/rubydex/src/model/declaration.rs +671 -0
  62. data/rust/rubydex/src/model/definitions.rs +1682 -0
  63. data/rust/rubydex/src/model/document.rs +222 -0
  64. data/rust/rubydex/src/model/encoding.rs +22 -0
  65. data/rust/rubydex/src/model/graph.rs +3754 -0
  66. data/rust/rubydex/src/model/id.rs +110 -0
  67. data/rust/rubydex/src/model/identity_maps.rs +58 -0
  68. data/rust/rubydex/src/model/ids.rs +60 -0
  69. data/rust/rubydex/src/model/keywords.rs +256 -0
  70. data/rust/rubydex/src/model/name.rs +298 -0
  71. data/rust/rubydex/src/model/references.rs +111 -0
  72. data/rust/rubydex/src/model/string_ref.rs +50 -0
  73. data/rust/rubydex/src/model/visibility.rs +41 -0
  74. data/rust/rubydex/src/model.rs +15 -0
  75. data/rust/rubydex/src/offset.rs +147 -0
  76. data/rust/rubydex/src/position.rs +6 -0
  77. data/rust/rubydex/src/query.rs +1841 -0
  78. data/rust/rubydex/src/resolution.rs +6517 -0
  79. data/rust/rubydex/src/stats/memory.rs +71 -0
  80. data/rust/rubydex/src/stats/orphan_report.rs +264 -0
  81. data/rust/rubydex/src/stats/timer.rs +127 -0
  82. data/rust/rubydex/src/stats.rs +11 -0
  83. data/rust/rubydex/src/test_utils/context.rs +226 -0
  84. data/rust/rubydex/src/test_utils/graph_test.rs +730 -0
  85. data/rust/rubydex/src/test_utils/local_graph_test.rs +602 -0
  86. data/rust/rubydex/src/test_utils.rs +52 -0
  87. data/rust/rubydex/src/visualization/dot.rs +192 -0
  88. data/rust/rubydex/src/visualization.rs +6 -0
  89. data/rust/rubydex/tests/cli.rs +185 -0
  90. data/rust/rubydex-mcp/Cargo.toml +28 -0
  91. data/rust/rubydex-mcp/src/main.rs +48 -0
  92. data/rust/rubydex-mcp/src/server.rs +1145 -0
  93. data/rust/rubydex-mcp/src/tools.rs +49 -0
  94. data/rust/rubydex-mcp/tests/mcp.rs +302 -0
  95. data/rust/rubydex-sys/Cargo.toml +20 -0
  96. data/rust/rubydex-sys/build.rs +14 -0
  97. data/rust/rubydex-sys/cbindgen.toml +12 -0
  98. data/rust/rubydex-sys/src/declaration_api.rs +485 -0
  99. data/rust/rubydex-sys/src/definition_api.rs +443 -0
  100. data/rust/rubydex-sys/src/diagnostic_api.rs +99 -0
  101. data/rust/rubydex-sys/src/document_api.rs +85 -0
  102. data/rust/rubydex-sys/src/graph_api.rs +948 -0
  103. data/rust/rubydex-sys/src/lib.rs +79 -0
  104. data/rust/rubydex-sys/src/location_api.rs +79 -0
  105. data/rust/rubydex-sys/src/name_api.rs +135 -0
  106. data/rust/rubydex-sys/src/reference_api.rs +267 -0
  107. data/rust/rubydex-sys/src/utils.rs +70 -0
  108. data/rust/rustfmt.toml +2 -0
  109. metadata +159 -0
@@ -0,0 +1,1682 @@
1
+ //! The definitions of the Ruby constructs in the source code.
2
+ //!
3
+ //! All the definitions constitute the `Declaration` of a name.
4
+ //!
5
+ //! Consider the following example:
6
+ //!
7
+ //! ```ruby
8
+ //! module Foo
9
+ //! class Bar; end
10
+ //! end
11
+ //!
12
+ //! class Foo::Bar; end
13
+ //! ```
14
+ //!
15
+ //! There are 3 definitions:
16
+ //!
17
+ //! 1. The module definition for `Foo`
18
+ //! 2. The class definition for `Foo::Bar` inside `Foo`
19
+ //! 3. The class definition for `Foo::Bar` again
20
+ //!
21
+ //! And there are 2 declarations:
22
+ //!
23
+ //! 1. The declaration for the name `Foo`
24
+ //! 2. The declaration for the name `Foo::Bar`
25
+
26
+ use bitflags::bitflags;
27
+
28
+ use crate::{
29
+ assert_mem_size,
30
+ model::{
31
+ comment::Comment,
32
+ ids::{ConstantReferenceId, DefinitionId, NameId, StringId, UriId},
33
+ visibility::Visibility,
34
+ },
35
+ offset::Offset,
36
+ };
37
+
38
+ bitflags! {
39
+ #[derive(Debug, Clone)]
40
+ pub struct DefinitionFlags: u8 {
41
+ const DEPRECATED = 0b0001;
42
+ const PROMOTABLE = 0b0010;
43
+ }
44
+ }
45
+
46
+ impl DefinitionFlags {
47
+ #[must_use]
48
+ pub fn is_deprecated(&self) -> bool {
49
+ self.contains(Self::DEPRECATED)
50
+ }
51
+
52
+ #[must_use]
53
+ pub fn is_promotable(&self) -> bool {
54
+ self.contains(Self::PROMOTABLE)
55
+ }
56
+ }
57
+
58
+ #[derive(Debug)]
59
+ pub enum Definition {
60
+ Class(Box<ClassDefinition>),
61
+ SingletonClass(Box<SingletonClassDefinition>),
62
+ Module(Box<ModuleDefinition>),
63
+ Constant(Box<ConstantDefinition>),
64
+ ConstantAlias(Box<ConstantAliasDefinition>),
65
+ ConstantVisibility(Box<ConstantVisibilityDefinition>),
66
+ MethodVisibility(Box<MethodVisibilityDefinition>),
67
+ Method(Box<MethodDefinition>),
68
+ AttrAccessor(Box<AttrAccessorDefinition>),
69
+ AttrReader(Box<AttrReaderDefinition>),
70
+ AttrWriter(Box<AttrWriterDefinition>),
71
+ GlobalVariable(Box<GlobalVariableDefinition>),
72
+ InstanceVariable(Box<InstanceVariableDefinition>),
73
+ ClassVariable(Box<ClassVariableDefinition>),
74
+ MethodAlias(Box<MethodAliasDefinition>),
75
+ GlobalVariableAlias(Box<GlobalVariableAliasDefinition>),
76
+ }
77
+ assert_mem_size!(Definition, 16);
78
+
79
+ macro_rules! all_definitions {
80
+ ($value:expr, $var:ident => $expr:expr) => {
81
+ match $value {
82
+ Definition::Class($var) => $expr,
83
+ Definition::SingletonClass($var) => $expr,
84
+ Definition::Module($var) => $expr,
85
+ Definition::Constant($var) => $expr,
86
+ Definition::ConstantAlias($var) => $expr,
87
+ Definition::ConstantVisibility($var) => $expr,
88
+ Definition::MethodVisibility($var) => $expr,
89
+ Definition::GlobalVariable($var) => $expr,
90
+ Definition::InstanceVariable($var) => $expr,
91
+ Definition::ClassVariable($var) => $expr,
92
+ Definition::AttrAccessor($var) => $expr,
93
+ Definition::AttrReader($var) => $expr,
94
+ Definition::AttrWriter($var) => $expr,
95
+ Definition::Method($var) => $expr,
96
+ Definition::MethodAlias($var) => $expr,
97
+ Definition::GlobalVariableAlias($var) => $expr,
98
+ }
99
+ };
100
+ }
101
+
102
+ impl Definition {
103
+ #[must_use]
104
+ pub fn id(&self) -> DefinitionId {
105
+ all_definitions!(self, it => it.id())
106
+ }
107
+
108
+ #[must_use]
109
+ pub fn uri_id(&self) -> &UriId {
110
+ all_definitions!(self, it => &it.uri_id())
111
+ }
112
+
113
+ #[must_use]
114
+ pub fn offset(&self) -> &Offset {
115
+ all_definitions!(self, it => &it.offset())
116
+ }
117
+
118
+ #[must_use]
119
+ pub fn comments(&self) -> &[Comment] {
120
+ all_definitions!(self, it => it.comments())
121
+ }
122
+
123
+ #[must_use]
124
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
125
+ all_definitions!(self, it => &it.lexical_nesting_id())
126
+ }
127
+
128
+ #[must_use]
129
+ pub fn kind(&self) -> &'static str {
130
+ match self {
131
+ Definition::Class(_) => "Class",
132
+ Definition::SingletonClass(_) => "SingletonClass",
133
+ Definition::Module(_) => "Module",
134
+ Definition::Constant(_) => "Constant",
135
+ Definition::ConstantAlias(_) => "ConstantAlias",
136
+ Definition::ConstantVisibility(_) => "ConstantVisibility",
137
+ Definition::MethodVisibility(_) => "MethodVisibility",
138
+ Definition::Method(_) => "Method",
139
+ Definition::AttrAccessor(_) => "AttrAccessor",
140
+ Definition::AttrReader(_) => "AttrReader",
141
+ Definition::AttrWriter(_) => "AttrWriter",
142
+ Definition::GlobalVariable(_) => "GlobalVariable",
143
+ Definition::InstanceVariable(_) => "InstanceVariable",
144
+ Definition::ClassVariable(_) => "ClassVariable",
145
+ Definition::MethodAlias(_) => "AliasMethod",
146
+ Definition::GlobalVariableAlias(_) => "GlobalVariableAlias",
147
+ }
148
+ }
149
+
150
+ #[must_use]
151
+ pub fn name_id(&self) -> Option<&NameId> {
152
+ match self {
153
+ Definition::Class(d) => Some(d.name_id()),
154
+ Definition::SingletonClass(d) => Some(d.name_id()),
155
+ Definition::Module(d) => Some(d.name_id()),
156
+ Definition::Constant(d) => Some(d.name_id()),
157
+ Definition::ConstantAlias(d) => Some(d.name_id()),
158
+ Definition::ConstantVisibility(d) => Some(d.name_id()),
159
+ Definition::MethodVisibility(_)
160
+ | Definition::GlobalVariable(_)
161
+ | Definition::InstanceVariable(_)
162
+ | Definition::ClassVariable(_)
163
+ | Definition::AttrAccessor(_)
164
+ | Definition::AttrReader(_)
165
+ | Definition::AttrWriter(_)
166
+ | Definition::Method(_)
167
+ | Definition::MethodAlias(_)
168
+ | Definition::GlobalVariableAlias(_) => None,
169
+ }
170
+ }
171
+
172
+ #[must_use]
173
+ pub fn name_offset(&self) -> Option<&Offset> {
174
+ match self {
175
+ Definition::Class(d) => Some(d.name_offset()),
176
+ Definition::Module(d) => Some(d.name_offset()),
177
+ Definition::SingletonClass(d) => Some(d.name_offset()),
178
+ _ => None,
179
+ }
180
+ }
181
+
182
+ #[must_use]
183
+ pub fn is_deprecated(&self) -> bool {
184
+ all_definitions!(self, it => it.flags().is_deprecated())
185
+ }
186
+ }
187
+
188
+ /// Represents a mixin: include, prepend, or extend.
189
+ /// During resolution, `Extend` mixins are attached to the singleton class.
190
+ #[derive(Debug, Clone)]
191
+ pub enum Mixin {
192
+ Include(IncludeDefinition),
193
+ Prepend(PrependDefinition),
194
+ Extend(ExtendDefinition),
195
+ }
196
+
197
+ impl Mixin {
198
+ #[must_use]
199
+ pub fn constant_reference_id(&self) -> &ConstantReferenceId {
200
+ match self {
201
+ Mixin::Include(def) => def.constant_reference_id(),
202
+ Mixin::Prepend(def) => def.constant_reference_id(),
203
+ Mixin::Extend(def) => def.constant_reference_id(),
204
+ }
205
+ }
206
+ }
207
+
208
+ macro_rules! mixin_definition {
209
+ ($variant:ident, $name:ident) => {
210
+ #[derive(Debug, Clone)]
211
+ pub struct $name {
212
+ constant_reference_id: ConstantReferenceId,
213
+ }
214
+
215
+ impl $name {
216
+ #[must_use]
217
+ pub const fn new(constant_reference_id: ConstantReferenceId) -> Self {
218
+ Self {
219
+ constant_reference_id,
220
+ }
221
+ }
222
+
223
+ #[must_use]
224
+ pub fn constant_reference_id(&self) -> &ConstantReferenceId {
225
+ &self.constant_reference_id
226
+ }
227
+ }
228
+ };
229
+ }
230
+
231
+ mixin_definition!(Include, IncludeDefinition);
232
+ mixin_definition!(Prepend, PrependDefinition);
233
+ mixin_definition!(Extend, ExtendDefinition);
234
+
235
+ /// A class definition
236
+ ///
237
+ /// # Example
238
+ /// ```ruby
239
+ /// class Foo
240
+ /// end
241
+ /// ```
242
+ #[derive(Debug)]
243
+ pub struct ClassDefinition {
244
+ name_id: NameId,
245
+ uri_id: UriId,
246
+ offset: Offset,
247
+ name_offset: Offset,
248
+ flags: DefinitionFlags,
249
+ comments: Box<[Comment]>,
250
+ lexical_nesting_id: Option<DefinitionId>,
251
+ members: Vec<DefinitionId>,
252
+ superclass_ref: Option<ConstantReferenceId>,
253
+ mixins: Vec<Mixin>,
254
+ }
255
+ assert_mem_size!(ClassDefinition, 120);
256
+
257
+ impl ClassDefinition {
258
+ #[must_use]
259
+ #[allow(clippy::too_many_arguments)]
260
+ pub const fn new(
261
+ name_id: NameId,
262
+ uri_id: UriId,
263
+ offset: Offset,
264
+ name_offset: Offset,
265
+ comments: Box<[Comment]>,
266
+ flags: DefinitionFlags,
267
+ lexical_nesting_id: Option<DefinitionId>,
268
+ superclass_ref: Option<ConstantReferenceId>,
269
+ ) -> Self {
270
+ Self {
271
+ name_id,
272
+ uri_id,
273
+ offset,
274
+ name_offset,
275
+ flags,
276
+ comments,
277
+ lexical_nesting_id,
278
+ superclass_ref,
279
+ members: Vec::new(),
280
+ mixins: Vec::new(),
281
+ }
282
+ }
283
+
284
+ #[must_use]
285
+ pub fn id(&self) -> DefinitionId {
286
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id))
287
+ }
288
+
289
+ #[must_use]
290
+ pub fn name_id(&self) -> &NameId {
291
+ &self.name_id
292
+ }
293
+
294
+ #[must_use]
295
+ pub fn uri_id(&self) -> &UriId {
296
+ &self.uri_id
297
+ }
298
+
299
+ #[must_use]
300
+ pub fn offset(&self) -> &Offset {
301
+ &self.offset
302
+ }
303
+
304
+ #[must_use]
305
+ pub fn name_offset(&self) -> &Offset {
306
+ &self.name_offset
307
+ }
308
+
309
+ #[must_use]
310
+ pub fn comments(&self) -> &[Comment] {
311
+ &self.comments
312
+ }
313
+
314
+ #[must_use]
315
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
316
+ &self.lexical_nesting_id
317
+ }
318
+
319
+ #[must_use]
320
+ pub fn superclass_ref(&self) -> Option<&ConstantReferenceId> {
321
+ self.superclass_ref.as_ref()
322
+ }
323
+
324
+ #[must_use]
325
+ pub fn members(&self) -> &[DefinitionId] {
326
+ &self.members
327
+ }
328
+
329
+ pub fn add_member(&mut self, member_id: DefinitionId) {
330
+ self.members.push(member_id);
331
+ }
332
+
333
+ #[must_use]
334
+ pub fn mixins(&self) -> &[Mixin] {
335
+ &self.mixins
336
+ }
337
+
338
+ pub fn add_mixin(&mut self, mixin: Mixin) {
339
+ self.mixins.push(mixin);
340
+ }
341
+
342
+ #[must_use]
343
+ pub fn flags(&self) -> &DefinitionFlags {
344
+ &self.flags
345
+ }
346
+ }
347
+
348
+ /// A singleton class definition created from `class << X` syntax.
349
+ /// This is created only when `class << X` syntax is encountered, NOT for `def self.foo`.
350
+ /// Methods with receivers (like `def self.foo`) have their `receiver` field set instead.
351
+ ///
352
+ /// # Examples
353
+ /// ```ruby
354
+ /// class Foo
355
+ /// class << self # attached_target = NameId("Foo")
356
+ /// def bar; end
357
+ /// end
358
+ /// end
359
+ ///
360
+ /// class << Foo # attached_target = NameId("Foo")
361
+ /// def baz; end
362
+ /// end
363
+ /// ```
364
+ #[derive(Debug)]
365
+ pub struct SingletonClassDefinition {
366
+ /// The name of this singleton class (e.g., `<Foo>` for `class << self` inside `class Foo`)
367
+ name_id: NameId,
368
+ uri_id: UriId,
369
+ offset: Offset,
370
+ name_offset: Offset,
371
+ flags: DefinitionFlags,
372
+ comments: Box<[Comment]>,
373
+ /// The definition where `class << X` was found (lexical owner)
374
+ lexical_nesting_id: Option<DefinitionId>,
375
+ /// Members defined directly in this singleton class
376
+ members: Vec<DefinitionId>,
377
+ /// Mixins declared in this singleton class
378
+ mixins: Vec<Mixin>,
379
+ }
380
+ assert_mem_size!(SingletonClassDefinition, 112);
381
+
382
+ impl SingletonClassDefinition {
383
+ #[must_use]
384
+ pub const fn new(
385
+ name_id: NameId,
386
+ uri_id: UriId,
387
+ offset: Offset,
388
+ name_offset: Offset,
389
+ comments: Box<[Comment]>,
390
+ flags: DefinitionFlags,
391
+ lexical_nesting_id: Option<DefinitionId>,
392
+ ) -> Self {
393
+ Self {
394
+ name_id,
395
+ uri_id,
396
+ offset,
397
+ name_offset,
398
+ flags,
399
+ comments,
400
+ lexical_nesting_id,
401
+ members: Vec::new(),
402
+ mixins: Vec::new(),
403
+ }
404
+ }
405
+
406
+ #[must_use]
407
+ pub fn id(&self) -> DefinitionId {
408
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id))
409
+ }
410
+
411
+ #[must_use]
412
+ pub fn name_id(&self) -> &NameId {
413
+ &self.name_id
414
+ }
415
+
416
+ #[must_use]
417
+ pub fn uri_id(&self) -> &UriId {
418
+ &self.uri_id
419
+ }
420
+
421
+ #[must_use]
422
+ pub fn offset(&self) -> &Offset {
423
+ &self.offset
424
+ }
425
+
426
+ #[must_use]
427
+ pub fn name_offset(&self) -> &Offset {
428
+ &self.name_offset
429
+ }
430
+
431
+ #[must_use]
432
+ pub fn comments(&self) -> &[Comment] {
433
+ &self.comments
434
+ }
435
+
436
+ #[must_use]
437
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
438
+ &self.lexical_nesting_id
439
+ }
440
+
441
+ #[must_use]
442
+ pub fn members(&self) -> &[DefinitionId] {
443
+ &self.members
444
+ }
445
+
446
+ pub fn add_member(&mut self, member_id: DefinitionId) {
447
+ self.members.push(member_id);
448
+ }
449
+
450
+ #[must_use]
451
+ pub fn mixins(&self) -> &[Mixin] {
452
+ &self.mixins
453
+ }
454
+
455
+ pub fn add_mixin(&mut self, mixin: Mixin) {
456
+ self.mixins.push(mixin);
457
+ }
458
+
459
+ #[must_use]
460
+ pub fn flags(&self) -> &DefinitionFlags {
461
+ &self.flags
462
+ }
463
+ }
464
+
465
+ /// A module definition
466
+ ///
467
+ /// # Example
468
+ /// ```ruby
469
+ /// module Foo
470
+ /// end
471
+ /// ```
472
+ #[derive(Debug)]
473
+ pub struct ModuleDefinition {
474
+ name_id: NameId,
475
+ uri_id: UriId,
476
+ offset: Offset,
477
+ name_offset: Offset,
478
+ flags: DefinitionFlags,
479
+ comments: Box<[Comment]>,
480
+ lexical_nesting_id: Option<DefinitionId>,
481
+ members: Vec<DefinitionId>,
482
+ mixins: Vec<Mixin>,
483
+ }
484
+ assert_mem_size!(ModuleDefinition, 112);
485
+
486
+ impl ModuleDefinition {
487
+ #[must_use]
488
+ pub const fn new(
489
+ name_id: NameId,
490
+ uri_id: UriId,
491
+ offset: Offset,
492
+ name_offset: Offset,
493
+ comments: Box<[Comment]>,
494
+ flags: DefinitionFlags,
495
+ lexical_nesting_id: Option<DefinitionId>,
496
+ ) -> Self {
497
+ Self {
498
+ name_id,
499
+ uri_id,
500
+ offset,
501
+ name_offset,
502
+ flags,
503
+ comments,
504
+ lexical_nesting_id,
505
+ members: Vec::new(),
506
+ mixins: Vec::new(),
507
+ }
508
+ }
509
+
510
+ #[must_use]
511
+ pub fn id(&self) -> DefinitionId {
512
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id))
513
+ }
514
+
515
+ #[must_use]
516
+ pub fn name_id(&self) -> &NameId {
517
+ &self.name_id
518
+ }
519
+
520
+ #[must_use]
521
+ pub fn uri_id(&self) -> &UriId {
522
+ &self.uri_id
523
+ }
524
+
525
+ #[must_use]
526
+ pub fn offset(&self) -> &Offset {
527
+ &self.offset
528
+ }
529
+
530
+ #[must_use]
531
+ pub fn name_offset(&self) -> &Offset {
532
+ &self.name_offset
533
+ }
534
+
535
+ #[must_use]
536
+ pub fn comments(&self) -> &[Comment] {
537
+ &self.comments
538
+ }
539
+
540
+ #[must_use]
541
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
542
+ &self.lexical_nesting_id
543
+ }
544
+
545
+ #[must_use]
546
+ pub fn members(&self) -> &[DefinitionId] {
547
+ &self.members
548
+ }
549
+
550
+ pub fn add_member(&mut self, member_id: DefinitionId) {
551
+ self.members.push(member_id);
552
+ }
553
+
554
+ #[must_use]
555
+ pub fn mixins(&self) -> &[Mixin] {
556
+ &self.mixins
557
+ }
558
+
559
+ pub fn add_mixin(&mut self, mixin: Mixin) {
560
+ self.mixins.push(mixin);
561
+ }
562
+
563
+ #[must_use]
564
+ pub fn flags(&self) -> &DefinitionFlags {
565
+ &self.flags
566
+ }
567
+ }
568
+
569
+ /// A constant definition
570
+ ///
571
+ /// # Example
572
+ /// ```ruby
573
+ /// FOO = 1
574
+ /// ```
575
+ #[derive(Debug)]
576
+ pub struct ConstantDefinition {
577
+ name_id: NameId,
578
+ uri_id: UriId,
579
+ offset: Offset,
580
+ flags: DefinitionFlags,
581
+ comments: Box<[Comment]>,
582
+ lexical_nesting_id: Option<DefinitionId>,
583
+ }
584
+ assert_mem_size!(ConstantDefinition, 56);
585
+
586
+ impl ConstantDefinition {
587
+ #[must_use]
588
+ pub const fn new(
589
+ name_id: NameId,
590
+ uri_id: UriId,
591
+ offset: Offset,
592
+ comments: Box<[Comment]>,
593
+ flags: DefinitionFlags,
594
+ lexical_nesting_id: Option<DefinitionId>,
595
+ ) -> Self {
596
+ Self {
597
+ name_id,
598
+ uri_id,
599
+ offset,
600
+ flags,
601
+ comments,
602
+ lexical_nesting_id,
603
+ }
604
+ }
605
+
606
+ #[must_use]
607
+ pub fn id(&self) -> DefinitionId {
608
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id))
609
+ }
610
+
611
+ #[must_use]
612
+ pub fn name_id(&self) -> &NameId {
613
+ &self.name_id
614
+ }
615
+
616
+ #[must_use]
617
+ pub fn uri_id(&self) -> &UriId {
618
+ &self.uri_id
619
+ }
620
+
621
+ #[must_use]
622
+ pub fn offset(&self) -> &Offset {
623
+ &self.offset
624
+ }
625
+
626
+ #[must_use]
627
+ pub fn comments(&self) -> &[Comment] {
628
+ &self.comments
629
+ }
630
+
631
+ #[must_use]
632
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
633
+ &self.lexical_nesting_id
634
+ }
635
+
636
+ #[must_use]
637
+ pub fn flags(&self) -> &DefinitionFlags {
638
+ &self.flags
639
+ }
640
+ }
641
+
642
+ /// A constant alias definition
643
+ ///
644
+ /// # Example
645
+ /// ```ruby
646
+ /// module Foo; end
647
+ /// ALIAS = Foo
648
+ /// ```
649
+ #[derive(Debug)]
650
+ pub struct ConstantAliasDefinition {
651
+ alias_constant: ConstantDefinition,
652
+ target_name_id: NameId,
653
+ }
654
+ assert_mem_size!(ConstantAliasDefinition, 64);
655
+
656
+ impl ConstantAliasDefinition {
657
+ #[must_use]
658
+ pub const fn new(target_name_id: NameId, alias_constant: ConstantDefinition) -> Self {
659
+ Self {
660
+ alias_constant,
661
+ target_name_id,
662
+ }
663
+ }
664
+
665
+ #[must_use]
666
+ pub fn id(&self) -> DefinitionId {
667
+ DefinitionId::from(&format!(
668
+ "{}{}{}{}",
669
+ *self.alias_constant.uri_id(),
670
+ self.alias_constant.offset().start(),
671
+ *self.alias_constant.name_id(),
672
+ *self.target_name_id,
673
+ ))
674
+ }
675
+
676
+ #[must_use]
677
+ pub fn name_id(&self) -> &NameId {
678
+ self.alias_constant.name_id()
679
+ }
680
+
681
+ #[must_use]
682
+ pub fn target_name_id(&self) -> &NameId {
683
+ &self.target_name_id
684
+ }
685
+
686
+ #[must_use]
687
+ pub fn uri_id(&self) -> &UriId {
688
+ self.alias_constant.uri_id()
689
+ }
690
+
691
+ #[must_use]
692
+ pub fn offset(&self) -> &Offset {
693
+ self.alias_constant.offset()
694
+ }
695
+
696
+ #[must_use]
697
+ pub fn comments(&self) -> &[Comment] {
698
+ self.alias_constant.comments()
699
+ }
700
+
701
+ #[must_use]
702
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
703
+ self.alias_constant.lexical_nesting_id()
704
+ }
705
+
706
+ #[must_use]
707
+ pub fn flags(&self) -> &DefinitionFlags {
708
+ self.alias_constant.flags()
709
+ }
710
+ }
711
+
712
+ #[derive(Debug)]
713
+ pub struct ConstantVisibilityDefinition {
714
+ name_id: NameId,
715
+ visibility: Visibility,
716
+ uri_id: UriId,
717
+ offset: Offset,
718
+ flags: DefinitionFlags,
719
+ comments: Box<[Comment]>,
720
+ lexical_nesting_id: Option<DefinitionId>,
721
+ }
722
+
723
+ impl ConstantVisibilityDefinition {
724
+ #[must_use]
725
+ pub const fn new(
726
+ name_id: NameId,
727
+ visibility: Visibility,
728
+ uri_id: UriId,
729
+ offset: Offset,
730
+ comments: Box<[Comment]>,
731
+ flags: DefinitionFlags,
732
+ lexical_nesting_id: Option<DefinitionId>,
733
+ ) -> Self {
734
+ Self {
735
+ name_id,
736
+ visibility,
737
+ uri_id,
738
+ offset,
739
+ flags,
740
+ comments,
741
+ lexical_nesting_id,
742
+ }
743
+ }
744
+
745
+ #[must_use]
746
+ pub fn id(&self) -> DefinitionId {
747
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id))
748
+ }
749
+
750
+ #[must_use]
751
+ pub fn name_id(&self) -> &NameId {
752
+ &self.name_id
753
+ }
754
+
755
+ #[must_use]
756
+ pub fn visibility(&self) -> &Visibility {
757
+ &self.visibility
758
+ }
759
+
760
+ #[must_use]
761
+ pub fn uri_id(&self) -> &UriId {
762
+ &self.uri_id
763
+ }
764
+
765
+ #[must_use]
766
+ pub fn offset(&self) -> &Offset {
767
+ &self.offset
768
+ }
769
+
770
+ #[must_use]
771
+ pub fn comments(&self) -> &[Comment] {
772
+ &self.comments
773
+ }
774
+
775
+ #[must_use]
776
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
777
+ &self.lexical_nesting_id
778
+ }
779
+
780
+ #[must_use]
781
+ pub fn flags(&self) -> &DefinitionFlags {
782
+ &self.flags
783
+ }
784
+ }
785
+ assert_mem_size!(ConstantVisibilityDefinition, 56);
786
+
787
+ #[derive(Debug)]
788
+ pub struct MethodVisibilityDefinition {
789
+ str_id: StringId,
790
+ visibility: Visibility,
791
+ uri_id: UriId,
792
+ offset: Offset,
793
+ flags: DefinitionFlags,
794
+ comments: Box<[Comment]>,
795
+ lexical_nesting_id: Option<DefinitionId>,
796
+ }
797
+
798
+ impl MethodVisibilityDefinition {
799
+ #[must_use]
800
+ pub const fn new(
801
+ str_id: StringId,
802
+ visibility: Visibility,
803
+ uri_id: UriId,
804
+ offset: Offset,
805
+ comments: Box<[Comment]>,
806
+ flags: DefinitionFlags,
807
+ lexical_nesting_id: Option<DefinitionId>,
808
+ ) -> Self {
809
+ Self {
810
+ str_id,
811
+ visibility,
812
+ uri_id,
813
+ offset,
814
+ flags,
815
+ comments,
816
+ lexical_nesting_id,
817
+ }
818
+ }
819
+
820
+ #[must_use]
821
+ pub fn id(&self) -> DefinitionId {
822
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id))
823
+ }
824
+
825
+ #[must_use]
826
+ pub fn str_id(&self) -> &StringId {
827
+ &self.str_id
828
+ }
829
+
830
+ #[must_use]
831
+ pub fn visibility(&self) -> &Visibility {
832
+ &self.visibility
833
+ }
834
+
835
+ #[must_use]
836
+ pub fn uri_id(&self) -> &UriId {
837
+ &self.uri_id
838
+ }
839
+
840
+ #[must_use]
841
+ pub fn offset(&self) -> &Offset {
842
+ &self.offset
843
+ }
844
+
845
+ #[must_use]
846
+ pub fn comments(&self) -> &[Comment] {
847
+ &self.comments
848
+ }
849
+
850
+ #[must_use]
851
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
852
+ &self.lexical_nesting_id
853
+ }
854
+
855
+ #[must_use]
856
+ pub fn flags(&self) -> &DefinitionFlags {
857
+ &self.flags
858
+ }
859
+ }
860
+ assert_mem_size!(MethodVisibilityDefinition, 56);
861
+
862
+ /// The signature of a method
863
+ ///
864
+ /// Currently only supports the parameter names and kinds.
865
+ pub type Signature = Box<[Parameter]>;
866
+
867
+ #[derive(Debug, Clone)]
868
+ pub enum Signatures {
869
+ /// A single method signature, for definitions without overloads.
870
+ ///
871
+ /// Used for Ruby definitions and RBS definitions with one signature.
872
+ Simple(Signature),
873
+
874
+ /// Multiple method signatures, for overloaded definitions.
875
+ ///
876
+ /// Used for RBS definitions with more than one overload.
877
+ Overloaded(Box<[Signature]>),
878
+ }
879
+
880
+ impl Signatures {
881
+ /// Returns all signatures as a slice, regardless of variant.
882
+ #[must_use]
883
+ pub fn as_slice(&self) -> &[Signature] {
884
+ match self {
885
+ Signatures::Simple(sig) => std::slice::from_ref(sig),
886
+ Signatures::Overloaded(sigs) => sigs,
887
+ }
888
+ }
889
+ }
890
+
891
+ /// A method definition
892
+ ///
893
+ /// # Example
894
+ /// ```ruby
895
+ /// def foo(bar, baz)
896
+ /// end
897
+ /// ```
898
+ #[derive(Debug)]
899
+ pub struct MethodDefinition {
900
+ str_id: StringId,
901
+ uri_id: UriId,
902
+ offset: Offset,
903
+ flags: DefinitionFlags,
904
+ comments: Box<[Comment]>,
905
+ lexical_nesting_id: Option<DefinitionId>,
906
+ signatures: Signatures,
907
+ visibility: Visibility,
908
+ receiver: Option<Receiver>,
909
+ }
910
+
911
+ assert_mem_size!(MethodDefinition, 96);
912
+
913
+ /// The receiver of a singleton method definition.
914
+ #[derive(Debug)]
915
+ pub enum Receiver {
916
+ /// `def self.foo` - receiver is the enclosing definition (class, module, singleton class or DSL)
917
+ SelfReceiver(DefinitionId),
918
+ /// `def Foo.bar` - receiver is an explicit constant that needs resolution
919
+ ConstantReceiver(NameId),
920
+ }
921
+
922
+ assert_mem_size!(Receiver, 16);
923
+
924
+ impl MethodDefinition {
925
+ #[allow(clippy::too_many_arguments)]
926
+ #[must_use]
927
+ pub const fn new(
928
+ str_id: StringId,
929
+ uri_id: UriId,
930
+ offset: Offset,
931
+ comments: Box<[Comment]>,
932
+ flags: DefinitionFlags,
933
+ lexical_nesting_id: Option<DefinitionId>,
934
+ signatures: Signatures,
935
+ visibility: Visibility,
936
+ receiver: Option<Receiver>,
937
+ ) -> Self {
938
+ Self {
939
+ str_id,
940
+ uri_id,
941
+ offset,
942
+ flags,
943
+ comments,
944
+ lexical_nesting_id,
945
+ signatures,
946
+ visibility,
947
+ receiver,
948
+ }
949
+ }
950
+
951
+ #[must_use]
952
+ pub fn id(&self) -> DefinitionId {
953
+ let mut formatted_id = format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id);
954
+
955
+ if let Some(receiver) = &self.receiver {
956
+ match receiver {
957
+ Receiver::SelfReceiver(def_id) => formatted_id.push_str(&def_id.to_string()),
958
+ Receiver::ConstantReceiver(name_id) => {
959
+ formatted_id.push_str(&name_id.to_string());
960
+ }
961
+ }
962
+ }
963
+
964
+ DefinitionId::from(&formatted_id)
965
+ }
966
+
967
+ #[must_use]
968
+ pub fn str_id(&self) -> &StringId {
969
+ &self.str_id
970
+ }
971
+
972
+ #[must_use]
973
+ pub fn uri_id(&self) -> &UriId {
974
+ &self.uri_id
975
+ }
976
+
977
+ #[must_use]
978
+ pub fn offset(&self) -> &Offset {
979
+ &self.offset
980
+ }
981
+
982
+ #[must_use]
983
+ pub fn comments(&self) -> &[Comment] {
984
+ &self.comments
985
+ }
986
+
987
+ #[must_use]
988
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
989
+ &self.lexical_nesting_id
990
+ }
991
+
992
+ #[must_use]
993
+ pub fn signatures(&self) -> &Signatures {
994
+ &self.signatures
995
+ }
996
+
997
+ #[must_use]
998
+ pub fn receiver(&self) -> &Option<Receiver> {
999
+ &self.receiver
1000
+ }
1001
+
1002
+ #[must_use]
1003
+ pub fn visibility(&self) -> &Visibility {
1004
+ &self.visibility
1005
+ }
1006
+
1007
+ #[must_use]
1008
+ pub fn flags(&self) -> &DefinitionFlags {
1009
+ &self.flags
1010
+ }
1011
+ }
1012
+
1013
+ #[derive(Debug, Clone)]
1014
+ pub enum Parameter {
1015
+ RequiredPositional(ParameterStruct),
1016
+ OptionalPositional(ParameterStruct),
1017
+ RestPositional(ParameterStruct),
1018
+ Post(ParameterStruct),
1019
+ RequiredKeyword(ParameterStruct),
1020
+ OptionalKeyword(ParameterStruct),
1021
+ RestKeyword(ParameterStruct),
1022
+ Forward(ParameterStruct),
1023
+ Block(ParameterStruct),
1024
+ }
1025
+ assert_mem_size!(Parameter, 24);
1026
+
1027
+ #[derive(Debug, Clone)]
1028
+ pub struct ParameterStruct {
1029
+ offset: Offset,
1030
+ str: StringId,
1031
+ }
1032
+ assert_mem_size!(ParameterStruct, 16);
1033
+
1034
+ impl ParameterStruct {
1035
+ #[must_use]
1036
+ pub const fn new(offset: Offset, str: StringId) -> Self {
1037
+ Self { offset, str }
1038
+ }
1039
+
1040
+ #[must_use]
1041
+ pub fn offset(&self) -> &Offset {
1042
+ &self.offset
1043
+ }
1044
+
1045
+ #[must_use]
1046
+ pub fn str(&self) -> &StringId {
1047
+ &self.str
1048
+ }
1049
+ }
1050
+
1051
+ /// An attr accessor definition
1052
+ ///
1053
+ /// # Example
1054
+ /// ```ruby
1055
+ /// attr_accessor :foo
1056
+ /// ```
1057
+ #[derive(Debug)]
1058
+ pub struct AttrAccessorDefinition {
1059
+ str_id: StringId,
1060
+ uri_id: UriId,
1061
+ offset: Offset,
1062
+ flags: DefinitionFlags,
1063
+ comments: Box<[Comment]>,
1064
+ lexical_nesting_id: Option<DefinitionId>,
1065
+ visibility: Visibility,
1066
+ }
1067
+ assert_mem_size!(AttrAccessorDefinition, 56);
1068
+
1069
+ impl AttrAccessorDefinition {
1070
+ #[must_use]
1071
+ pub const fn new(
1072
+ str_id: StringId,
1073
+ uri_id: UriId,
1074
+ offset: Offset,
1075
+ comments: Box<[Comment]>,
1076
+ flags: DefinitionFlags,
1077
+ lexical_nesting_id: Option<DefinitionId>,
1078
+ visibility: Visibility,
1079
+ ) -> Self {
1080
+ Self {
1081
+ str_id,
1082
+ uri_id,
1083
+ offset,
1084
+ flags,
1085
+ comments,
1086
+ lexical_nesting_id,
1087
+ visibility,
1088
+ }
1089
+ }
1090
+
1091
+ #[must_use]
1092
+ pub fn id(&self) -> DefinitionId {
1093
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id))
1094
+ }
1095
+
1096
+ #[must_use]
1097
+ pub fn str_id(&self) -> &StringId {
1098
+ &self.str_id
1099
+ }
1100
+
1101
+ #[must_use]
1102
+ pub fn uri_id(&self) -> &UriId {
1103
+ &self.uri_id
1104
+ }
1105
+
1106
+ #[must_use]
1107
+ pub fn offset(&self) -> &Offset {
1108
+ &self.offset
1109
+ }
1110
+
1111
+ #[must_use]
1112
+ pub fn comments(&self) -> &[Comment] {
1113
+ &self.comments
1114
+ }
1115
+
1116
+ #[must_use]
1117
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
1118
+ &self.lexical_nesting_id
1119
+ }
1120
+
1121
+ #[must_use]
1122
+ pub fn visibility(&self) -> &Visibility {
1123
+ &self.visibility
1124
+ }
1125
+
1126
+ #[must_use]
1127
+ pub fn flags(&self) -> &DefinitionFlags {
1128
+ &self.flags
1129
+ }
1130
+ }
1131
+
1132
+ /// An attr reader definition
1133
+ ///
1134
+ /// # Example
1135
+ /// ```ruby
1136
+ /// attr_reader :foo
1137
+ /// ```
1138
+ #[derive(Debug)]
1139
+ pub struct AttrReaderDefinition {
1140
+ str_id: StringId,
1141
+ uri_id: UriId,
1142
+ offset: Offset,
1143
+ flags: DefinitionFlags,
1144
+ comments: Box<[Comment]>,
1145
+ lexical_nesting_id: Option<DefinitionId>,
1146
+ visibility: Visibility,
1147
+ }
1148
+ assert_mem_size!(AttrReaderDefinition, 56);
1149
+
1150
+ impl AttrReaderDefinition {
1151
+ #[must_use]
1152
+ pub const fn new(
1153
+ str_id: StringId,
1154
+ uri_id: UriId,
1155
+ offset: Offset,
1156
+ comments: Box<[Comment]>,
1157
+ flags: DefinitionFlags,
1158
+ lexical_nesting_id: Option<DefinitionId>,
1159
+ visibility: Visibility,
1160
+ ) -> Self {
1161
+ Self {
1162
+ str_id,
1163
+ uri_id,
1164
+ offset,
1165
+ flags,
1166
+ comments,
1167
+ lexical_nesting_id,
1168
+ visibility,
1169
+ }
1170
+ }
1171
+
1172
+ #[must_use]
1173
+ pub fn id(&self) -> DefinitionId {
1174
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id))
1175
+ }
1176
+
1177
+ #[must_use]
1178
+ pub fn str_id(&self) -> &StringId {
1179
+ &self.str_id
1180
+ }
1181
+
1182
+ #[must_use]
1183
+ pub fn uri_id(&self) -> &UriId {
1184
+ &self.uri_id
1185
+ }
1186
+
1187
+ #[must_use]
1188
+ pub fn offset(&self) -> &Offset {
1189
+ &self.offset
1190
+ }
1191
+
1192
+ #[must_use]
1193
+ pub fn comments(&self) -> &[Comment] {
1194
+ &self.comments
1195
+ }
1196
+
1197
+ #[must_use]
1198
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
1199
+ &self.lexical_nesting_id
1200
+ }
1201
+
1202
+ #[must_use]
1203
+ pub fn visibility(&self) -> &Visibility {
1204
+ &self.visibility
1205
+ }
1206
+
1207
+ #[must_use]
1208
+ pub fn flags(&self) -> &DefinitionFlags {
1209
+ &self.flags
1210
+ }
1211
+ }
1212
+
1213
+ /// An attr writer definition
1214
+ ///
1215
+ /// # Example
1216
+ /// ```ruby
1217
+ /// attr_writer :foo
1218
+ /// ```
1219
+ #[derive(Debug)]
1220
+ pub struct AttrWriterDefinition {
1221
+ str_id: StringId,
1222
+ uri_id: UriId,
1223
+ offset: Offset,
1224
+ flags: DefinitionFlags,
1225
+ comments: Box<[Comment]>,
1226
+ lexical_nesting_id: Option<DefinitionId>,
1227
+ visibility: Visibility,
1228
+ }
1229
+ assert_mem_size!(AttrWriterDefinition, 56);
1230
+
1231
+ impl AttrWriterDefinition {
1232
+ #[must_use]
1233
+ pub const fn new(
1234
+ str_id: StringId,
1235
+ uri_id: UriId,
1236
+ offset: Offset,
1237
+ comments: Box<[Comment]>,
1238
+ flags: DefinitionFlags,
1239
+ lexical_nesting_id: Option<DefinitionId>,
1240
+ visibility: Visibility,
1241
+ ) -> Self {
1242
+ Self {
1243
+ str_id,
1244
+ uri_id,
1245
+ offset,
1246
+ flags,
1247
+ comments,
1248
+ lexical_nesting_id,
1249
+ visibility,
1250
+ }
1251
+ }
1252
+
1253
+ #[must_use]
1254
+ pub fn id(&self) -> DefinitionId {
1255
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id))
1256
+ }
1257
+
1258
+ #[must_use]
1259
+ pub fn str_id(&self) -> &StringId {
1260
+ &self.str_id
1261
+ }
1262
+
1263
+ #[must_use]
1264
+ pub fn comments(&self) -> &[Comment] {
1265
+ &self.comments
1266
+ }
1267
+
1268
+ #[must_use]
1269
+ pub fn uri_id(&self) -> &UriId {
1270
+ &self.uri_id
1271
+ }
1272
+
1273
+ #[must_use]
1274
+ pub fn offset(&self) -> &Offset {
1275
+ &self.offset
1276
+ }
1277
+
1278
+ #[must_use]
1279
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
1280
+ &self.lexical_nesting_id
1281
+ }
1282
+
1283
+ #[must_use]
1284
+ pub fn visibility(&self) -> &Visibility {
1285
+ &self.visibility
1286
+ }
1287
+
1288
+ #[must_use]
1289
+ pub fn flags(&self) -> &DefinitionFlags {
1290
+ &self.flags
1291
+ }
1292
+ }
1293
+
1294
+ /// A global variable definition
1295
+ ///
1296
+ /// # Example
1297
+ /// ```ruby
1298
+ /// $foo = 1
1299
+ /// ```
1300
+ #[derive(Debug)]
1301
+ pub struct GlobalVariableDefinition {
1302
+ str_id: StringId,
1303
+ uri_id: UriId,
1304
+ offset: Offset,
1305
+ flags: DefinitionFlags,
1306
+ comments: Box<[Comment]>,
1307
+ lexical_nesting_id: Option<DefinitionId>,
1308
+ }
1309
+ assert_mem_size!(GlobalVariableDefinition, 56);
1310
+
1311
+ impl GlobalVariableDefinition {
1312
+ #[must_use]
1313
+ pub const fn new(
1314
+ str_id: StringId,
1315
+ uri_id: UriId,
1316
+ offset: Offset,
1317
+ comments: Box<[Comment]>,
1318
+ flags: DefinitionFlags,
1319
+ lexical_nesting_id: Option<DefinitionId>,
1320
+ ) -> Self {
1321
+ Self {
1322
+ str_id,
1323
+ uri_id,
1324
+ offset,
1325
+ flags,
1326
+ comments,
1327
+ lexical_nesting_id,
1328
+ }
1329
+ }
1330
+
1331
+ #[must_use]
1332
+ pub fn id(&self) -> DefinitionId {
1333
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id))
1334
+ }
1335
+
1336
+ #[must_use]
1337
+ pub fn str_id(&self) -> &StringId {
1338
+ &self.str_id
1339
+ }
1340
+
1341
+ #[must_use]
1342
+ pub fn uri_id(&self) -> &UriId {
1343
+ &self.uri_id
1344
+ }
1345
+
1346
+ #[must_use]
1347
+ pub fn offset(&self) -> &Offset {
1348
+ &self.offset
1349
+ }
1350
+
1351
+ #[must_use]
1352
+ pub fn comments(&self) -> &[Comment] {
1353
+ &self.comments
1354
+ }
1355
+
1356
+ #[must_use]
1357
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
1358
+ &self.lexical_nesting_id
1359
+ }
1360
+
1361
+ #[must_use]
1362
+ pub fn flags(&self) -> &DefinitionFlags {
1363
+ &self.flags
1364
+ }
1365
+ }
1366
+
1367
+ /// An instance variable definition
1368
+ ///
1369
+ /// # Example
1370
+ /// ```ruby
1371
+ /// @foo = 1
1372
+ /// ```
1373
+ #[derive(Debug)]
1374
+ pub struct InstanceVariableDefinition {
1375
+ str_id: StringId,
1376
+ uri_id: UriId,
1377
+ offset: Offset,
1378
+ flags: DefinitionFlags,
1379
+ comments: Box<[Comment]>,
1380
+ lexical_nesting_id: Option<DefinitionId>,
1381
+ }
1382
+ assert_mem_size!(InstanceVariableDefinition, 56);
1383
+
1384
+ impl InstanceVariableDefinition {
1385
+ #[must_use]
1386
+ pub const fn new(
1387
+ str_id: StringId,
1388
+ uri_id: UriId,
1389
+ offset: Offset,
1390
+ comments: Box<[Comment]>,
1391
+ flags: DefinitionFlags,
1392
+ lexical_nesting_id: Option<DefinitionId>,
1393
+ ) -> Self {
1394
+ Self {
1395
+ str_id,
1396
+ uri_id,
1397
+ offset,
1398
+ flags,
1399
+ comments,
1400
+ lexical_nesting_id,
1401
+ }
1402
+ }
1403
+
1404
+ #[must_use]
1405
+ pub fn id(&self) -> DefinitionId {
1406
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id))
1407
+ }
1408
+
1409
+ #[must_use]
1410
+ pub fn str_id(&self) -> &StringId {
1411
+ &self.str_id
1412
+ }
1413
+
1414
+ #[must_use]
1415
+ pub fn uri_id(&self) -> &UriId {
1416
+ &self.uri_id
1417
+ }
1418
+
1419
+ #[must_use]
1420
+ pub fn offset(&self) -> &Offset {
1421
+ &self.offset
1422
+ }
1423
+
1424
+ #[must_use]
1425
+ pub fn comments(&self) -> &[Comment] {
1426
+ &self.comments
1427
+ }
1428
+
1429
+ #[must_use]
1430
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
1431
+ &self.lexical_nesting_id
1432
+ }
1433
+
1434
+ #[must_use]
1435
+ pub fn flags(&self) -> &DefinitionFlags {
1436
+ &self.flags
1437
+ }
1438
+ }
1439
+
1440
+ /// A class variable definition
1441
+ ///
1442
+ /// # Example
1443
+ /// ```ruby
1444
+ /// @@foo = 1
1445
+ /// ```
1446
+ #[derive(Debug)]
1447
+ pub struct ClassVariableDefinition {
1448
+ str_id: StringId,
1449
+ uri_id: UriId,
1450
+ offset: Offset,
1451
+ flags: DefinitionFlags,
1452
+ comments: Box<[Comment]>,
1453
+ lexical_nesting_id: Option<DefinitionId>,
1454
+ }
1455
+ assert_mem_size!(ClassVariableDefinition, 56);
1456
+
1457
+ impl ClassVariableDefinition {
1458
+ #[must_use]
1459
+ pub const fn new(
1460
+ str_id: StringId,
1461
+ uri_id: UriId,
1462
+ offset: Offset,
1463
+ comments: Box<[Comment]>,
1464
+ flags: DefinitionFlags,
1465
+ lexical_nesting_id: Option<DefinitionId>,
1466
+ ) -> Self {
1467
+ Self {
1468
+ str_id,
1469
+ uri_id,
1470
+ offset,
1471
+ flags,
1472
+ comments,
1473
+ lexical_nesting_id,
1474
+ }
1475
+ }
1476
+
1477
+ #[must_use]
1478
+ pub fn id(&self) -> DefinitionId {
1479
+ DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id))
1480
+ }
1481
+
1482
+ #[must_use]
1483
+ pub fn str_id(&self) -> &StringId {
1484
+ &self.str_id
1485
+ }
1486
+
1487
+ #[must_use]
1488
+ pub fn uri_id(&self) -> &UriId {
1489
+ &self.uri_id
1490
+ }
1491
+
1492
+ #[must_use]
1493
+ pub fn offset(&self) -> &Offset {
1494
+ &self.offset
1495
+ }
1496
+
1497
+ #[must_use]
1498
+ pub fn comments(&self) -> &[Comment] {
1499
+ &self.comments
1500
+ }
1501
+
1502
+ #[must_use]
1503
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
1504
+ &self.lexical_nesting_id
1505
+ }
1506
+
1507
+ #[must_use]
1508
+ pub fn flags(&self) -> &DefinitionFlags {
1509
+ &self.flags
1510
+ }
1511
+ }
1512
+
1513
+ #[derive(Debug)]
1514
+ pub struct MethodAliasDefinition {
1515
+ new_name_str_id: StringId,
1516
+ old_name_str_id: StringId,
1517
+ uri_id: UriId,
1518
+ offset: Offset,
1519
+ flags: DefinitionFlags,
1520
+ comments: Box<[Comment]>,
1521
+ lexical_nesting_id: Option<DefinitionId>,
1522
+ receiver: Option<Receiver>,
1523
+ }
1524
+ assert_mem_size!(MethodAliasDefinition, 80);
1525
+
1526
+ impl MethodAliasDefinition {
1527
+ #[allow(clippy::too_many_arguments)]
1528
+ #[must_use]
1529
+ pub const fn new(
1530
+ new_name_str_id: StringId,
1531
+ old_name_str_id: StringId,
1532
+ uri_id: UriId,
1533
+ offset: Offset,
1534
+ comments: Box<[Comment]>,
1535
+ flags: DefinitionFlags,
1536
+ lexical_nesting_id: Option<DefinitionId>,
1537
+ receiver: Option<Receiver>,
1538
+ ) -> Self {
1539
+ Self {
1540
+ new_name_str_id,
1541
+ old_name_str_id,
1542
+ uri_id,
1543
+ offset,
1544
+ flags,
1545
+ comments,
1546
+ lexical_nesting_id,
1547
+ receiver,
1548
+ }
1549
+ }
1550
+
1551
+ #[must_use]
1552
+ pub fn id(&self) -> DefinitionId {
1553
+ DefinitionId::from(&format!(
1554
+ "{}{}{}{}",
1555
+ *self.uri_id,
1556
+ self.offset.start(),
1557
+ *self.new_name_str_id,
1558
+ *self.old_name_str_id,
1559
+ ))
1560
+ }
1561
+
1562
+ #[must_use]
1563
+ pub fn new_name_str_id(&self) -> &StringId {
1564
+ &self.new_name_str_id
1565
+ }
1566
+
1567
+ #[must_use]
1568
+ pub fn old_name_str_id(&self) -> &StringId {
1569
+ &self.old_name_str_id
1570
+ }
1571
+
1572
+ #[must_use]
1573
+ pub fn uri_id(&self) -> &UriId {
1574
+ &self.uri_id
1575
+ }
1576
+
1577
+ #[must_use]
1578
+ pub fn offset(&self) -> &Offset {
1579
+ &self.offset
1580
+ }
1581
+
1582
+ #[must_use]
1583
+ pub fn comments(&self) -> &[Comment] {
1584
+ &self.comments
1585
+ }
1586
+
1587
+ #[must_use]
1588
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
1589
+ &self.lexical_nesting_id
1590
+ }
1591
+
1592
+ #[must_use]
1593
+ pub fn receiver(&self) -> &Option<Receiver> {
1594
+ &self.receiver
1595
+ }
1596
+
1597
+ #[must_use]
1598
+ pub fn flags(&self) -> &DefinitionFlags {
1599
+ &self.flags
1600
+ }
1601
+ }
1602
+
1603
+ #[derive(Debug)]
1604
+ pub struct GlobalVariableAliasDefinition {
1605
+ new_name_str_id: StringId,
1606
+ old_name_str_id: StringId,
1607
+ uri_id: UriId,
1608
+ offset: Offset,
1609
+ flags: DefinitionFlags,
1610
+ comments: Box<[Comment]>,
1611
+ lexical_nesting_id: Option<DefinitionId>,
1612
+ }
1613
+ assert_mem_size!(GlobalVariableAliasDefinition, 64);
1614
+
1615
+ impl GlobalVariableAliasDefinition {
1616
+ #[must_use]
1617
+ pub const fn new(
1618
+ new_name_str_id: StringId,
1619
+ old_name_str_id: StringId,
1620
+ uri_id: UriId,
1621
+ offset: Offset,
1622
+ comments: Box<[Comment]>,
1623
+ flags: DefinitionFlags,
1624
+ lexical_nesting_id: Option<DefinitionId>,
1625
+ ) -> Self {
1626
+ Self {
1627
+ new_name_str_id,
1628
+ old_name_str_id,
1629
+ uri_id,
1630
+ offset,
1631
+ flags,
1632
+ comments,
1633
+ lexical_nesting_id,
1634
+ }
1635
+ }
1636
+
1637
+ #[must_use]
1638
+ pub fn id(&self) -> DefinitionId {
1639
+ DefinitionId::from(&format!(
1640
+ "{}{}{}{}",
1641
+ *self.uri_id,
1642
+ self.offset.start(),
1643
+ *self.new_name_str_id,
1644
+ *self.old_name_str_id,
1645
+ ))
1646
+ }
1647
+
1648
+ #[must_use]
1649
+ pub fn new_name_str_id(&self) -> &StringId {
1650
+ &self.new_name_str_id
1651
+ }
1652
+
1653
+ #[must_use]
1654
+ pub fn old_name_str_id(&self) -> &StringId {
1655
+ &self.old_name_str_id
1656
+ }
1657
+
1658
+ #[must_use]
1659
+ pub fn uri_id(&self) -> &UriId {
1660
+ &self.uri_id
1661
+ }
1662
+
1663
+ #[must_use]
1664
+ pub fn offset(&self) -> &Offset {
1665
+ &self.offset
1666
+ }
1667
+
1668
+ #[must_use]
1669
+ pub fn comments(&self) -> &[Comment] {
1670
+ &self.comments
1671
+ }
1672
+
1673
+ #[must_use]
1674
+ pub fn lexical_nesting_id(&self) -> &Option<DefinitionId> {
1675
+ &self.lexical_nesting_id
1676
+ }
1677
+
1678
+ #[must_use]
1679
+ pub fn flags(&self) -> &DefinitionFlags {
1680
+ &self.flags
1681
+ }
1682
+ }