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
data/exe/rdx ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
5
+ require "optparse"
6
+
7
+ OptionParser.new do |parser|
8
+ parser.banner = "Usage: [path1, path2]"
9
+
10
+ parser.on("--version", "Print the gem's version") do
11
+ require "rubydex/version"
12
+ puts "v#{Rubydex::VERSION}"
13
+ exit
14
+ end
15
+
16
+ parser.on("-h", "--help", "Prints this help") do
17
+ puts parser
18
+ exit
19
+ end
20
+ end.parse!
21
+
22
+ require "rubydex"
23
+
24
+ workspace_path = ARGV.first
25
+
26
+ # If a workspace path is passed, we need to ensure that Bundler is setup in that context so that we find the
27
+ # dependencies for that project
28
+ if workspace_path
29
+ gemfile_path = File.join(workspace_path, "Gemfile")
30
+
31
+ if File.exist?(gemfile_path)
32
+ ENV["BUNDLE_GEMFILE"] = gemfile_path
33
+
34
+ begin
35
+ Bundler.setup
36
+ rescue Bundler::BundlerError => e
37
+ $stderr.puts(<<~MESSAGE)
38
+ Bundle setup failed for #{gemfile_path}. Indexing of dependencies may be partial
39
+ Error:
40
+ #{e.message}
41
+ MESSAGE
42
+ end
43
+ end
44
+ end
45
+
46
+ graph = Rubydex::Graph.new(workspace_path: workspace_path)
47
+ graph.index_workspace
@@ -0,0 +1,453 @@
1
+ #include "declaration.h"
2
+ #include "definition.h"
3
+ #include "graph.h"
4
+ #include "handle.h"
5
+ #include "rustbindings.h"
6
+ #include "utils.h"
7
+
8
+ VALUE cDeclaration;
9
+ VALUE cNamespace;
10
+ VALUE cClass;
11
+ VALUE cModule;
12
+ VALUE cSingletonClass;
13
+ VALUE cTodo;
14
+ VALUE cConstant;
15
+ VALUE cConstantAlias;
16
+ VALUE cMethod;
17
+ VALUE cGlobalVariable;
18
+ VALUE cInstanceVariable;
19
+ VALUE cClassVariable;
20
+
21
+ // Keep this in sync with declaration_api.rs
22
+ VALUE rdxi_declaration_class_for_kind(CDeclarationKind kind) {
23
+ switch (kind) {
24
+ case CDeclarationKind_Class:
25
+ return cClass;
26
+ case CDeclarationKind_Module:
27
+ return cModule;
28
+ case CDeclarationKind_SingletonClass:
29
+ return cSingletonClass;
30
+ case CDeclarationKind_Todo:
31
+ return cTodo;
32
+ case CDeclarationKind_Constant:
33
+ return cConstant;
34
+ case CDeclarationKind_ConstantAlias:
35
+ return cConstantAlias;
36
+ case CDeclarationKind_Method:
37
+ return cMethod;
38
+ case CDeclarationKind_GlobalVariable:
39
+ return cGlobalVariable;
40
+ case CDeclarationKind_InstanceVariable:
41
+ return cInstanceVariable;
42
+ case CDeclarationKind_ClassVariable:
43
+ return cClassVariable;
44
+ default:
45
+ rb_raise(rb_eRuntimeError, "Unknown CDeclarationKind: %d", kind);
46
+ }
47
+ }
48
+
49
+ // Declaration#name -> String
50
+ static VALUE rdxr_declaration_name(VALUE self) {
51
+ HandleData *data;
52
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
53
+
54
+ void *graph;
55
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
56
+ const char *name = rdx_declaration_name(graph, data->id);
57
+
58
+ if (name == NULL) {
59
+ return Qnil;
60
+ }
61
+
62
+ VALUE str = rb_utf8_str_new_cstr(name);
63
+ free_c_string(name);
64
+
65
+ return str;
66
+ }
67
+
68
+ // Declaration#unqualified_name -> String
69
+ static VALUE rdxr_declaration_unqualified_name(VALUE self) {
70
+ HandleData *data;
71
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
72
+
73
+ void *graph;
74
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
75
+ const char *name = rdx_declaration_unqualified_name(graph, data->id);
76
+
77
+ if (name == NULL) {
78
+ return Qnil;
79
+ }
80
+
81
+ VALUE str = rb_utf8_str_new_cstr(name);
82
+ free_c_string(name);
83
+
84
+ return str;
85
+ }
86
+
87
+ // Body function for rb_ensure in Declaration#definitions
88
+ static VALUE declaration_definitions_yield(VALUE args) {
89
+ VALUE self = rb_ary_entry(args, 0);
90
+ void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
91
+
92
+ HandleData *data;
93
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
94
+
95
+ CDefinition defn;
96
+ while (rdx_definitions_iter_next(iter, &defn)) {
97
+ VALUE argv[] = {data->graph_obj, ULL2NUM(defn.id)};
98
+ VALUE defn_class = rdxi_definition_class_for_kind(defn.kind);
99
+ VALUE handle = rb_class_new_instance(2, argv, defn_class);
100
+ rb_yield(handle);
101
+ }
102
+
103
+ return Qnil;
104
+ }
105
+
106
+ // Ensure function for rb_ensure in Declaration#definitions to always free the
107
+ // iterator
108
+ static VALUE declaration_definitions_ensure(VALUE args) {
109
+ void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1));
110
+ rdx_definitions_iter_free(iter);
111
+
112
+ return Qnil;
113
+ }
114
+
115
+ // Size function for the Declaration#definitions enumerator
116
+ static VALUE declaration_definitions_size(VALUE self, VALUE _args, VALUE _eobj) {
117
+ HandleData *data;
118
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
119
+
120
+ void *graph;
121
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
122
+ struct DefinitionsIter *iter = rdx_declaration_definitions_iter_new(graph, data->id);
123
+ size_t len = rdx_definitions_iter_len(iter);
124
+ rdx_definitions_iter_free(iter);
125
+
126
+ return SIZET2NUM(len);
127
+ }
128
+
129
+ // Declaration#definitions: () -> Enumerator[Definition]
130
+ // Returns an enumerator that yields all definitions for this declaration lazily
131
+ static VALUE rdxr_declaration_definitions(VALUE self) {
132
+ if (!rb_block_given_p()) {
133
+ return rb_enumeratorize_with_size(self, rb_str_new2("definitions"), 0, NULL, declaration_definitions_size);
134
+ }
135
+
136
+ HandleData *data;
137
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
138
+
139
+ void *graph;
140
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
141
+
142
+ void *iter = rdx_declaration_definitions_iter_new(graph, data->id);
143
+ VALUE args = rb_ary_new_from_args(2, self, ULL2NUM((uintptr_t)iter));
144
+ rb_ensure(declaration_definitions_yield, args, declaration_definitions_ensure, args);
145
+
146
+ return self;
147
+ }
148
+
149
+ // Declaration#member: (String member) -> Declaration
150
+ // Returns a declaration handle for the given member
151
+ static VALUE rdxr_declaration_member(VALUE self, VALUE name) {
152
+ HandleData *data;
153
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
154
+
155
+ void *graph;
156
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
157
+
158
+ if (TYPE(name) != T_STRING) {
159
+ rb_raise(rb_eTypeError, "expected String");
160
+ }
161
+
162
+ const CDeclaration *decl = rdx_declaration_member(graph, data->id, StringValueCStr(name));
163
+ if (decl == NULL) {
164
+ return Qnil;
165
+ }
166
+
167
+ VALUE decl_class = rdxi_declaration_class_for_kind(decl->kind);
168
+ VALUE argv[] = {data->graph_obj, ULL2NUM(decl->id)};
169
+ free_c_declaration(decl);
170
+
171
+ return rb_class_new_instance(2, argv, decl_class);
172
+ }
173
+
174
+ // Namespace#find_member: (String member, only_inherited: false) -> Declaration?
175
+ // Searches for a member in the ancestor chain of the declaration
176
+ static VALUE rdxr_declaration_find_member(int argc, VALUE *argv, VALUE self) {
177
+ VALUE member, opts;
178
+ rb_scan_args(argc, argv, "1:", &member, &opts);
179
+ Check_Type(member, T_STRING);
180
+
181
+ bool only_inherited = false;
182
+ if (!NIL_P(opts)) {
183
+ ID kwarg_id = rb_intern("only_inherited");
184
+ VALUE kwarg_val;
185
+ rb_get_kwargs(opts, &kwarg_id, 0, 1, &kwarg_val);
186
+
187
+ if (kwarg_val != Qundef) {
188
+ only_inherited = RTEST(kwarg_val);
189
+ }
190
+ }
191
+
192
+ HandleData *data;
193
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
194
+
195
+ void *graph;
196
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
197
+
198
+ const CDeclaration *decl = rdx_declaration_find_member(graph, data->id, StringValueCStr(member), only_inherited);
199
+ if (decl == NULL) {
200
+ return Qnil;
201
+ }
202
+
203
+ VALUE decl_class = rdxi_declaration_class_for_kind(decl->kind);
204
+ VALUE result_argv[] = {data->graph_obj, ULL2NUM(decl->id)};
205
+ free_c_declaration(decl);
206
+
207
+ return rb_class_new_instance(2, result_argv, decl_class);
208
+ }
209
+
210
+ // Declaration#singleton_class -> SingletonClass
211
+ static VALUE rdxr_declaration_singleton_class(VALUE self) {
212
+ HandleData *data;
213
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
214
+
215
+ void *graph;
216
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
217
+ const CDeclaration *decl = rdx_declaration_singleton_class(graph, data->id);
218
+
219
+ if (decl == NULL) {
220
+ return Qnil;
221
+ }
222
+
223
+ VALUE decl_class = rdxi_declaration_class_for_kind(decl->kind);
224
+ VALUE argv[] = {data->graph_obj, ULL2NUM(decl->id)};
225
+ free_c_declaration(decl);
226
+
227
+ return rb_class_new_instance(2, argv, decl_class);
228
+ }
229
+
230
+ // Declaration#owner -> Declaration
231
+ static VALUE rdxr_declaration_owner(VALUE self) {
232
+ HandleData *data;
233
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
234
+
235
+ void *graph;
236
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
237
+ const CDeclaration *decl = rdx_declaration_owner(graph, data->id);
238
+
239
+ if (decl == NULL) {
240
+ rb_raise(rb_eRuntimeError, "owner can never be nil for any declarations");
241
+ }
242
+
243
+ VALUE decl_class = rdxi_declaration_class_for_kind(decl->kind);
244
+ VALUE argv[] = {data->graph_obj, ULL2NUM(decl->id)};
245
+ free_c_declaration(decl);
246
+
247
+ return rb_class_new_instance(2, argv, decl_class);
248
+ }
249
+
250
+ // Declaration#ancestors: () -> Enumerator[Declaration]
251
+ static VALUE rdxr_declaration_ancestors(VALUE self) {
252
+ if (!rb_block_given_p()) {
253
+ return rb_enumeratorize(self, rb_str_new2("ancestors"), 0, NULL);
254
+ }
255
+
256
+ HandleData *data;
257
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
258
+
259
+ void *graph;
260
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
261
+
262
+ void *iter = rdx_declaration_ancestors(graph, data->id);
263
+ if (iter == NULL) {
264
+ rb_raise(rb_eRuntimeError, "failed to create iterator");
265
+ }
266
+
267
+ VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
268
+ rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
269
+
270
+ return self;
271
+ }
272
+
273
+ // Declaration#descendants: () -> Enumerator[Declaration]
274
+ static VALUE rdxr_declaration_descendants(VALUE self) {
275
+ if (!rb_block_given_p()) {
276
+ return rb_enumeratorize(self, rb_str_new2("descendants"), 0, NULL);
277
+ }
278
+
279
+ HandleData *data;
280
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
281
+
282
+ void *graph;
283
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
284
+
285
+ void *iter = rdx_declaration_descendants(graph, data->id);
286
+ if (iter == NULL) {
287
+ rb_raise(rb_eRuntimeError, "failed to create iterator");
288
+ }
289
+
290
+ VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
291
+ rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
292
+
293
+ return self;
294
+ }
295
+
296
+ // Namespace#members: () -> Enumerator[Declaration]
297
+ static VALUE rdxr_declaration_members(VALUE self) {
298
+ if (!rb_block_given_p()) {
299
+ return rb_enumeratorize(self, rb_str_new2("members"), 0, NULL);
300
+ }
301
+
302
+ HandleData *data;
303
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
304
+
305
+ void *graph;
306
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
307
+
308
+ void *iter = rdx_declaration_members(graph, data->id);
309
+ if (iter == NULL) {
310
+ rb_raise(rb_eRuntimeError, "failed to create iterator");
311
+ }
312
+
313
+ VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
314
+ rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
315
+
316
+ return self;
317
+ }
318
+
319
+ // Size function for constant declaration references enumerator
320
+ static VALUE constant_declaration_references_size(VALUE self, VALUE _args, VALUE _eobj) {
321
+ HandleData *data;
322
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
323
+
324
+ void *graph;
325
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
326
+
327
+ struct ConstantReferencesIter *iter = rdx_declaration_constant_references_iter_new(graph, data->id);
328
+ if (iter == NULL) {
329
+ rb_raise(rb_eRuntimeError, "Declaration not found");
330
+ }
331
+
332
+ size_t len = rdx_constant_references_iter_len(iter);
333
+ rdx_constant_references_iter_free(iter);
334
+ return SIZET2NUM(len);
335
+ }
336
+
337
+ // Namespace#references, Constant#references, ConstantAlias#references
338
+ // Returns an enumerator that yields constant references to this declaration
339
+ static VALUE rdxr_constant_declaration_references(VALUE self) {
340
+ if (!rb_block_given_p()) {
341
+ return rb_enumeratorize_with_size(self, rb_str_new2("references"), 0, NULL,
342
+ constant_declaration_references_size);
343
+ }
344
+
345
+ HandleData *data;
346
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
347
+
348
+ void *graph;
349
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
350
+
351
+ void *iter = rdx_declaration_constant_references_iter_new(graph, data->id);
352
+ if (iter == NULL) {
353
+ rb_raise(rb_eRuntimeError, "Declaration not found");
354
+ }
355
+
356
+ VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
357
+ rb_ensure(rdxi_constant_references_yield, args, rdxi_constant_references_ensure, args);
358
+
359
+ return self;
360
+ }
361
+
362
+ // Size function for method declaration references enumerator
363
+ static VALUE method_declaration_references_size(VALUE self, VALUE _args, VALUE _eobj) {
364
+ HandleData *data;
365
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
366
+
367
+ void *graph;
368
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
369
+
370
+ struct MethodReferencesIter *iter = rdx_declaration_method_references_iter_new(graph, data->id);
371
+ if (iter == NULL) {
372
+ rb_raise(rb_eRuntimeError, "Declaration not found");
373
+ }
374
+
375
+ size_t len = rdx_method_references_iter_len(iter);
376
+ rdx_method_references_iter_free(iter);
377
+ return SIZET2NUM(len);
378
+ }
379
+
380
+ // Method#references
381
+ // Returns an enumerator that yields method references to this declaration
382
+ static VALUE rdxr_method_declaration_references(VALUE self) {
383
+ if (!rb_block_given_p()) {
384
+ return rb_enumeratorize_with_size(self, rb_str_new2("references"), 0, NULL,
385
+ method_declaration_references_size);
386
+ }
387
+
388
+ HandleData *data;
389
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
390
+
391
+ void *graph;
392
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
393
+
394
+ void *iter = rdx_declaration_method_references_iter_new(graph, data->id);
395
+ if (iter == NULL) {
396
+ rb_raise(rb_eRuntimeError, "Declaration not found");
397
+ }
398
+
399
+ VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
400
+ rb_ensure(rdxi_method_references_yield, args, rdxi_method_references_ensure, args);
401
+
402
+ return self;
403
+ }
404
+
405
+ // Placeholder for variable declarations that don't yet support references
406
+ static VALUE rdxr_variable_declaration_references(VALUE self) {
407
+ return rb_ary_new();
408
+ }
409
+
410
+ void rdxi_initialize_declaration(VALUE mRubydex) {
411
+ cDeclaration = rb_define_class_under(mRubydex, "Declaration", rb_cObject);
412
+ cNamespace = rb_define_class_under(mRubydex, "Namespace", cDeclaration);
413
+ cClass = rb_define_class_under(mRubydex, "Class", cNamespace);
414
+ cModule = rb_define_class_under(mRubydex, "Module", cNamespace);
415
+ cSingletonClass = rb_define_class_under(mRubydex, "SingletonClass", cNamespace);
416
+ cTodo = rb_define_class_under(mRubydex, "Todo", cNamespace);
417
+ cConstant = rb_define_class_under(mRubydex, "Constant", cDeclaration);
418
+ cConstantAlias = rb_define_class_under(mRubydex, "ConstantAlias", cDeclaration);
419
+ cMethod = rb_define_class_under(mRubydex, "Method", cDeclaration);
420
+ cGlobalVariable = rb_define_class_under(mRubydex, "GlobalVariable", cDeclaration);
421
+ cInstanceVariable = rb_define_class_under(mRubydex, "InstanceVariable", cDeclaration);
422
+ cClassVariable = rb_define_class_under(mRubydex, "ClassVariable", cDeclaration);
423
+
424
+ rb_define_alloc_func(cDeclaration, rdxr_handle_alloc);
425
+ rb_define_method(cDeclaration, "initialize", rdxr_handle_initialize, 2);
426
+ rb_define_method(cDeclaration, "name", rdxr_declaration_name, 0);
427
+ rb_define_method(cDeclaration, "unqualified_name", rdxr_declaration_unqualified_name, 0);
428
+ rb_define_method(cDeclaration, "definitions", rdxr_declaration_definitions, 0);
429
+ rb_define_method(cDeclaration, "owner", rdxr_declaration_owner, 0);
430
+
431
+ // Namespace only methods
432
+ rb_define_method(cNamespace, "references", rdxr_constant_declaration_references, 0);
433
+ rb_define_method(cNamespace, "member", rdxr_declaration_member, 1);
434
+ rb_define_method(cNamespace, "find_member", rdxr_declaration_find_member, -1);
435
+ rb_define_method(cNamespace, "singleton_class", rdxr_declaration_singleton_class, 0);
436
+ rb_define_method(cNamespace, "ancestors", rdxr_declaration_ancestors, 0);
437
+ rb_define_method(cNamespace, "descendants", rdxr_declaration_descendants, 0);
438
+ rb_define_method(cNamespace, "members", rdxr_declaration_members, 0);
439
+
440
+ // Constant and ConstantAlias have constant references
441
+ rb_define_method(cConstant, "references", rdxr_constant_declaration_references, 0);
442
+ rb_define_method(cConstantAlias, "references", rdxr_constant_declaration_references, 0);
443
+
444
+ // Method has method references
445
+ rb_define_method(cMethod, "references", rdxr_method_declaration_references, 0);
446
+
447
+ // Variable declarations don't yet support references
448
+ rb_define_method(cGlobalVariable, "references", rdxr_variable_declaration_references, 0);
449
+ rb_define_method(cInstanceVariable, "references", rdxr_variable_declaration_references, 0);
450
+ rb_define_method(cClassVariable, "references", rdxr_variable_declaration_references, 0);
451
+
452
+ rb_funcall(rb_singleton_class(cDeclaration), rb_intern("private"), 1, ID2SYM(rb_intern("new")));
453
+ }
@@ -0,0 +1,23 @@
1
+ #ifndef RUBYDEX_DECLARATION_H
2
+ #define RUBYDEX_DECLARATION_H
3
+
4
+ #include "ruby.h"
5
+ #include "rustbindings.h"
6
+
7
+ extern VALUE cDeclaration;
8
+ extern VALUE cNamespace;
9
+ extern VALUE cClass;
10
+ extern VALUE cModule;
11
+ extern VALUE cSingletonClass;
12
+ extern VALUE cTodo;
13
+ extern VALUE cConstant;
14
+ extern VALUE cConstantAlias;
15
+ extern VALUE cMethod;
16
+ extern VALUE cGlobalVariable;
17
+ extern VALUE cInstanceVariable;
18
+ extern VALUE cClassVariable;
19
+
20
+ VALUE rdxi_declaration_class_for_kind(CDeclarationKind kind);
21
+ void rdxi_initialize_declaration(VALUE mRubydex);
22
+
23
+ #endif // RUBYDEX_DECLARATION_H