rubydex 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/THIRD_PARTY_LICENSES.html +39 -6
- data/exe/rdx +2 -0
- data/ext/rubydex/declaration.c +115 -106
- data/ext/rubydex/definition.c +100 -80
- data/ext/rubydex/diagnostic.c +5 -0
- data/ext/rubydex/document.c +23 -31
- data/ext/rubydex/extconf.rb +1 -1
- data/ext/rubydex/graph.c +233 -60
- data/ext/rubydex/handle.h +13 -0
- data/ext/rubydex/location.c +5 -0
- data/ext/rubydex/reference.c +51 -46
- data/ext/rubydex/rubydex.c +5 -0
- data/ext/rubydex/signature.c +5 -0
- data/ext/rubydex/utils.c +13 -0
- data/ext/rubydex/utils.h +4 -0
- data/lib/rubydex/bin/rubydex_mcp.exe +0 -0
- data/lib/rubydex/errors.rb +3 -0
- data/lib/rubydex/graph.rb +9 -28
- data/lib/rubydex/version.rb +1 -1
- data/rbi/rubydex.rbi +11 -3
- data/rust/Cargo.lock +119 -14
- data/rust/rubydex/Cargo.toml +19 -1
- data/rust/rubydex/benches/graph_memory.rs +46 -0
- data/rust/rubydex/src/config.rs +275 -0
- data/rust/rubydex/src/errors.rs +2 -0
- data/rust/rubydex/src/lib.rs +7 -0
- data/rust/rubydex/src/model/declaration.rs +12 -51
- data/rust/rubydex/src/model/graph.rs +38 -15
- data/rust/rubydex/src/resolution.rs +2 -12
- data/rust/rubydex-sys/src/graph_api.rs +73 -3
- metadata +4 -2
data/ext/rubydex/graph.c
CHANGED
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
#include "rustbindings.h"
|
|
9
9
|
#include "utils.h"
|
|
10
10
|
|
|
11
|
+
/*
|
|
12
|
+
* RDoc parser workaround for https://github.com/ruby/rdoc/issues/1744:
|
|
13
|
+
* mRubydex = rb_define_module("Rubydex")
|
|
14
|
+
*/
|
|
15
|
+
|
|
11
16
|
static VALUE cGraph;
|
|
12
17
|
static VALUE mRubydex;
|
|
13
18
|
static VALUE cKeyword;
|
|
@@ -68,8 +73,12 @@ static VALUE rdxr_graph_alloc(VALUE klass) {
|
|
|
68
73
|
return TypedData_Wrap_Struct(klass, &graph_type, graph);
|
|
69
74
|
}
|
|
70
75
|
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
/*
|
|
77
|
+
* call-seq:
|
|
78
|
+
* index_all(file_paths) -> Array[String]
|
|
79
|
+
*
|
|
80
|
+
* Returns an array of I/O error messages encountered during indexing.
|
|
81
|
+
*/
|
|
73
82
|
static VALUE rdxr_graph_index_all(VALUE self, VALUE file_paths) {
|
|
74
83
|
rdxi_check_array_of_strings(file_paths);
|
|
75
84
|
|
|
@@ -99,9 +108,12 @@ static VALUE rdxr_graph_index_all(VALUE self, VALUE file_paths) {
|
|
|
99
108
|
return array;
|
|
100
109
|
}
|
|
101
110
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
/*
|
|
112
|
+
* call-seq:
|
|
113
|
+
* index_source(uri, source, language_id) -> nil
|
|
114
|
+
*
|
|
115
|
+
* Indexes a single source string in memory, dispatching to the appropriate indexer based on language_id.
|
|
116
|
+
*/
|
|
105
117
|
static VALUE rdxr_graph_index_source(VALUE self, VALUE uri, VALUE source, VALUE language_id) {
|
|
106
118
|
Check_Type(uri, T_STRING);
|
|
107
119
|
Check_Type(source, T_STRING);
|
|
@@ -148,8 +160,12 @@ static VALUE graph_declarations_size(VALUE self, VALUE _args, VALUE _eobj) {
|
|
|
148
160
|
return SIZET2NUM(len);
|
|
149
161
|
}
|
|
150
162
|
|
|
151
|
-
|
|
152
|
-
|
|
163
|
+
/*
|
|
164
|
+
* call-seq:
|
|
165
|
+
* declarations -> Enumerator[Rubydex::Declaration]
|
|
166
|
+
*
|
|
167
|
+
* Returns an enumerator that yields all declarations lazily.
|
|
168
|
+
*/
|
|
153
169
|
static VALUE rdxr_graph_declarations(VALUE self) {
|
|
154
170
|
if (!rb_block_given_p()) {
|
|
155
171
|
return rb_enumeratorize_with_size(self, rb_str_new2("declarations"), 0, NULL, graph_declarations_size);
|
|
@@ -178,8 +194,12 @@ static VALUE rdxr_graph_yield_search_results(VALUE self, void *iter) {
|
|
|
178
194
|
return self;
|
|
179
195
|
}
|
|
180
196
|
|
|
181
|
-
|
|
182
|
-
|
|
197
|
+
/*
|
|
198
|
+
* call-seq:
|
|
199
|
+
* search(query) -> Enumerator[Rubydex::Declaration]
|
|
200
|
+
*
|
|
201
|
+
* Returns an enumerator that yields declarations matching the query exactly by substring.
|
|
202
|
+
*/
|
|
183
203
|
static VALUE rdxr_graph_search(VALUE self, VALUE query) {
|
|
184
204
|
Check_Type(query, T_STRING);
|
|
185
205
|
|
|
@@ -193,8 +213,12 @@ static VALUE rdxr_graph_search(VALUE self, VALUE query) {
|
|
|
193
213
|
return rdxr_graph_yield_search_results(self, rdx_graph_declarations_search(graph, StringValueCStr(query)));
|
|
194
214
|
}
|
|
195
215
|
|
|
196
|
-
|
|
197
|
-
|
|
216
|
+
/*
|
|
217
|
+
* call-seq:
|
|
218
|
+
* fuzzy_search(query) -> Enumerator[Rubydex::Declaration]
|
|
219
|
+
*
|
|
220
|
+
* Returns an enumerator that yields declarations matching the query fuzzily.
|
|
221
|
+
*/
|
|
198
222
|
static VALUE rdxr_graph_fuzzy_search(VALUE self, VALUE query) {
|
|
199
223
|
Check_Type(query, T_STRING);
|
|
200
224
|
|
|
@@ -243,8 +267,12 @@ static VALUE graph_documents_size(VALUE self, VALUE _args, VALUE _eobj) {
|
|
|
243
267
|
return SIZET2NUM(len);
|
|
244
268
|
}
|
|
245
269
|
|
|
246
|
-
|
|
247
|
-
|
|
270
|
+
/*
|
|
271
|
+
* call-seq:
|
|
272
|
+
* documents -> Enumerator[Rubydex::Document]
|
|
273
|
+
*
|
|
274
|
+
* Returns an enumerator that yields all documents lazily.
|
|
275
|
+
*/
|
|
248
276
|
static VALUE rdxr_graph_documents(VALUE self) {
|
|
249
277
|
if (!rb_block_given_p()) {
|
|
250
278
|
return rb_enumeratorize_with_size(self, rb_str_new2("documents"), 0, NULL, graph_documents_size);
|
|
@@ -260,8 +288,12 @@ static VALUE rdxr_graph_documents(VALUE self) {
|
|
|
260
288
|
return self;
|
|
261
289
|
}
|
|
262
290
|
|
|
263
|
-
|
|
264
|
-
|
|
291
|
+
/*
|
|
292
|
+
* call-seq:
|
|
293
|
+
* graph[fully_qualified_name] -> Rubydex::Declaration?
|
|
294
|
+
*
|
|
295
|
+
* Returns the declaration for the fully qualified name, or nil when no declaration exists.
|
|
296
|
+
*/
|
|
265
297
|
static VALUE rdxr_graph_aref(VALUE self, VALUE key) {
|
|
266
298
|
void *graph;
|
|
267
299
|
TypedData_Get_Struct(self, void *, &graph_type, graph);
|
|
@@ -294,8 +326,12 @@ static VALUE graph_constant_references_size(VALUE self, VALUE _args, VALUE _eobj
|
|
|
294
326
|
return SIZET2NUM(len);
|
|
295
327
|
}
|
|
296
328
|
|
|
297
|
-
|
|
298
|
-
|
|
329
|
+
/*
|
|
330
|
+
* call-seq:
|
|
331
|
+
* constant_references -> Enumerator[Rubydex::ConstantReference]
|
|
332
|
+
*
|
|
333
|
+
* Returns an enumerator that yields constant references lazily.
|
|
334
|
+
*/
|
|
299
335
|
static VALUE rdxr_graph_constant_references(VALUE self) {
|
|
300
336
|
if (!rb_block_given_p()) {
|
|
301
337
|
return rb_enumeratorize_with_size(self, rb_str_new2("constant_references"), 0, NULL,
|
|
@@ -324,8 +360,12 @@ static VALUE graph_method_references_size(VALUE self, VALUE _args, VALUE _eobj)
|
|
|
324
360
|
return SIZET2NUM(len);
|
|
325
361
|
}
|
|
326
362
|
|
|
327
|
-
|
|
328
|
-
|
|
363
|
+
/*
|
|
364
|
+
* call-seq:
|
|
365
|
+
* method_references -> Enumerator[Rubydex::MethodReference]
|
|
366
|
+
*
|
|
367
|
+
* Returns an enumerator that yields method references lazily.
|
|
368
|
+
*/
|
|
329
369
|
static VALUE rdxr_graph_method_references(VALUE self) {
|
|
330
370
|
if (!rb_block_given_p()) {
|
|
331
371
|
return rb_enumeratorize_with_size(self, rb_str_new2("method_references"), 0, NULL,
|
|
@@ -342,8 +382,12 @@ static VALUE rdxr_graph_method_references(VALUE self) {
|
|
|
342
382
|
return self;
|
|
343
383
|
}
|
|
344
384
|
|
|
345
|
-
|
|
346
|
-
|
|
385
|
+
/*
|
|
386
|
+
* call-seq:
|
|
387
|
+
* document(uri) -> Rubydex::Document?
|
|
388
|
+
*
|
|
389
|
+
* Returns the document for the URI, or nil if it does not exist.
|
|
390
|
+
*/
|
|
347
391
|
static VALUE rdxr_graph_document(VALUE self, VALUE uri) {
|
|
348
392
|
Check_Type(uri, T_STRING);
|
|
349
393
|
|
|
@@ -360,9 +404,13 @@ static VALUE rdxr_graph_document(VALUE self, VALUE uri) {
|
|
|
360
404
|
return rb_class_new_instance(2, argv, cDocument);
|
|
361
405
|
}
|
|
362
406
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
407
|
+
/*
|
|
408
|
+
* call-seq:
|
|
409
|
+
* delete_document(uri) -> Rubydex::Document?
|
|
410
|
+
*
|
|
411
|
+
* Deletes a document and all of its definitions from the graph. Returns the removed document, or nil if it does not
|
|
412
|
+
* exist.
|
|
413
|
+
*/
|
|
366
414
|
static VALUE rdxr_graph_delete_document(VALUE self, VALUE uri) {
|
|
367
415
|
Check_Type(uri, T_STRING);
|
|
368
416
|
|
|
@@ -379,8 +427,12 @@ static VALUE rdxr_graph_delete_document(VALUE self, VALUE uri) {
|
|
|
379
427
|
return rb_class_new_instance(2, argv, cDocument);
|
|
380
428
|
}
|
|
381
429
|
|
|
382
|
-
|
|
383
|
-
|
|
430
|
+
/*
|
|
431
|
+
* call-seq:
|
|
432
|
+
* resolve -> self
|
|
433
|
+
*
|
|
434
|
+
* Runs the resolver to compute declarations and ownership.
|
|
435
|
+
*/
|
|
384
436
|
static VALUE rdxr_graph_resolve(VALUE self) {
|
|
385
437
|
void *graph;
|
|
386
438
|
TypedData_Get_Struct(self, void *, &graph_type, graph);
|
|
@@ -388,8 +440,12 @@ static VALUE rdxr_graph_resolve(VALUE self) {
|
|
|
388
440
|
return self;
|
|
389
441
|
}
|
|
390
442
|
|
|
391
|
-
|
|
392
|
-
|
|
443
|
+
/*
|
|
444
|
+
* call-seq:
|
|
445
|
+
* encoding=(encoding) -> nil
|
|
446
|
+
*
|
|
447
|
+
* Sets the encoding used for transforming byte offsets into LSP code unit line and column positions.
|
|
448
|
+
*/
|
|
393
449
|
static VALUE rdxr_graph_set_encoding(VALUE self, VALUE encoding) {
|
|
394
450
|
Check_Type(encoding, T_STRING);
|
|
395
451
|
|
|
@@ -404,8 +460,12 @@ static VALUE rdxr_graph_set_encoding(VALUE self, VALUE encoding) {
|
|
|
404
460
|
return Qnil;
|
|
405
461
|
}
|
|
406
462
|
|
|
407
|
-
|
|
408
|
-
|
|
463
|
+
/*
|
|
464
|
+
* call-seq:
|
|
465
|
+
* resolve_constant(name, nesting) -> Rubydex::Declaration?
|
|
466
|
+
*
|
|
467
|
+
* Runs the resolver on a single constant reference to determine what it points to.
|
|
468
|
+
*/
|
|
409
469
|
static VALUE rdxr_graph_resolve_constant(VALUE self, VALUE const_name, VALUE nesting) {
|
|
410
470
|
Check_Type(const_name, T_STRING);
|
|
411
471
|
rdxi_check_array_of_strings(nesting);
|
|
@@ -433,8 +493,12 @@ static VALUE rdxr_graph_resolve_constant(VALUE self, VALUE const_name, VALUE nes
|
|
|
433
493
|
return rb_class_new_instance(2, argv, decl_class);
|
|
434
494
|
}
|
|
435
495
|
|
|
436
|
-
|
|
437
|
-
|
|
496
|
+
/*
|
|
497
|
+
* call-seq:
|
|
498
|
+
* resolve_require_path(require_path, load_paths) -> Rubydex::Document?
|
|
499
|
+
*
|
|
500
|
+
* Resolves a require path to its document.
|
|
501
|
+
*/
|
|
438
502
|
static VALUE rdxr_graph_resolve_require_path(VALUE self, VALUE require_path, VALUE load_paths) {
|
|
439
503
|
Check_Type(require_path, T_STRING);
|
|
440
504
|
rdxi_check_array_of_strings(load_paths);
|
|
@@ -459,8 +523,12 @@ static VALUE rdxr_graph_resolve_require_path(VALUE self, VALUE require_path, VAL
|
|
|
459
523
|
return rb_class_new_instance(2, argv, cDocument);
|
|
460
524
|
}
|
|
461
525
|
|
|
462
|
-
|
|
463
|
-
|
|
526
|
+
/*
|
|
527
|
+
* call-seq:
|
|
528
|
+
* require_paths(load_paths) -> Array[String]
|
|
529
|
+
*
|
|
530
|
+
* Returns all require paths for completion.
|
|
531
|
+
*/
|
|
464
532
|
static VALUE rdxr_graph_require_paths(VALUE self, VALUE load_path) {
|
|
465
533
|
rdxi_check_array_of_strings(load_path);
|
|
466
534
|
|
|
@@ -488,8 +556,12 @@ static VALUE rdxr_graph_require_paths(VALUE self, VALUE load_path) {
|
|
|
488
556
|
return array;
|
|
489
557
|
}
|
|
490
558
|
|
|
491
|
-
|
|
492
|
-
|
|
559
|
+
/*
|
|
560
|
+
* call-seq:
|
|
561
|
+
* check_integrity -> Array[Rubydex::IntegrityFailure]
|
|
562
|
+
*
|
|
563
|
+
* Returns an array of integrity failures, or an empty array if no issues were found.
|
|
564
|
+
*/
|
|
493
565
|
static VALUE rdxr_graph_check_integrity(VALUE self) {
|
|
494
566
|
void *graph;
|
|
495
567
|
TypedData_Get_Struct(self, void *, &graph_type, graph);
|
|
@@ -514,7 +586,12 @@ static VALUE rdxr_graph_check_integrity(VALUE self) {
|
|
|
514
586
|
return array;
|
|
515
587
|
}
|
|
516
588
|
|
|
517
|
-
|
|
589
|
+
/*
|
|
590
|
+
* call-seq:
|
|
591
|
+
* diagnostics -> Array[Rubydex::Diagnostic]
|
|
592
|
+
*
|
|
593
|
+
* Returns diagnostics emitted while indexing or resolving the graph.
|
|
594
|
+
*/
|
|
518
595
|
static VALUE rdxr_graph_diagnostics(VALUE self) {
|
|
519
596
|
void *graph;
|
|
520
597
|
TypedData_Get_Struct(self, void *, &graph_type, graph);
|
|
@@ -531,7 +608,7 @@ static VALUE rdxr_graph_diagnostics(VALUE self) {
|
|
|
531
608
|
for (size_t i = 0; i < array->len; i++) {
|
|
532
609
|
DiagnosticEntry entry = array->items[i];
|
|
533
610
|
VALUE message = entry.message == NULL ? Qnil : rb_utf8_str_new_cstr(entry.message);
|
|
534
|
-
VALUE rule = rb_str_new2(entry.rule);
|
|
611
|
+
VALUE rule = rb_str_intern(rb_str_new2(entry.rule));
|
|
535
612
|
VALUE location = rdxi_build_location_value(entry.location);
|
|
536
613
|
|
|
537
614
|
VALUE kwargs = rb_hash_new();
|
|
@@ -603,10 +680,13 @@ static VALUE completion_result_to_ruby_array(struct CompletionResult result, VAL
|
|
|
603
680
|
return ruby_array;
|
|
604
681
|
}
|
|
605
682
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
683
|
+
/*
|
|
684
|
+
* call-seq:
|
|
685
|
+
* complete_expression(nesting, self_receiver:) -> Array[Rubydex::Declaration | Rubydex::Keyword]
|
|
686
|
+
*
|
|
687
|
+
* Returns completion candidates for an expression context. The nesting array represents the lexical scope stack. The
|
|
688
|
+
* required self_receiver keyword argument overrides the self type; pass nil when the self type is unknown.
|
|
689
|
+
*/
|
|
610
690
|
static VALUE rdxr_graph_complete_expression(int argc, VALUE *argv, VALUE self) {
|
|
611
691
|
VALUE nesting, opts;
|
|
612
692
|
rb_scan_args(argc, argv, "1:", &nesting, &opts);
|
|
@@ -627,11 +707,13 @@ static VALUE rdxr_graph_complete_expression(int argc, VALUE *argv, VALUE self) {
|
|
|
627
707
|
return completion_result_to_ruby_array(result, self);
|
|
628
708
|
}
|
|
629
709
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
710
|
+
/*
|
|
711
|
+
* call-seq:
|
|
712
|
+
* complete_namespace_access(name, self_receiver:) -> Array[Rubydex::Declaration]
|
|
713
|
+
*
|
|
714
|
+
* Returns completion candidates after a namespace access operator such as Foo::. The required self_receiver keyword
|
|
715
|
+
* argument is the caller's runtime self type; pass nil when there is no caller context.
|
|
716
|
+
*/
|
|
635
717
|
static VALUE rdxr_graph_complete_namespace_access(int argc, VALUE *argv, VALUE self) {
|
|
636
718
|
VALUE name, opts;
|
|
637
719
|
rb_scan_args(argc, argv, "1:", &name, &opts);
|
|
@@ -647,10 +729,13 @@ static VALUE rdxr_graph_complete_namespace_access(int argc, VALUE *argv, VALUE s
|
|
|
647
729
|
return completion_result_to_ruby_array(result, self);
|
|
648
730
|
}
|
|
649
731
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
732
|
+
/*
|
|
733
|
+
* call-seq:
|
|
734
|
+
* complete_method_call(name, self_receiver:) -> Array[Rubydex::Method]
|
|
735
|
+
*
|
|
736
|
+
* Returns completion candidates after a method call operator such as foo. The required self_receiver keyword argument
|
|
737
|
+
* is the caller's runtime self type; pass nil when there is no caller context.
|
|
738
|
+
*/
|
|
654
739
|
static VALUE rdxr_graph_complete_method_call(int argc, VALUE *argv, VALUE self) {
|
|
655
740
|
VALUE name, opts;
|
|
656
741
|
rb_scan_args(argc, argv, "1:", &name, &opts);
|
|
@@ -666,9 +751,13 @@ static VALUE rdxr_graph_complete_method_call(int argc, VALUE *argv, VALUE self)
|
|
|
666
751
|
return completion_result_to_ruby_array(result, self);
|
|
667
752
|
}
|
|
668
753
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
754
|
+
/*
|
|
755
|
+
* call-seq:
|
|
756
|
+
* complete_method_argument(name, nesting, self_receiver:) -> Array[Rubydex::Declaration | Rubydex::Keyword | Rubydex::KeywordParameter]
|
|
757
|
+
*
|
|
758
|
+
* Returns completion candidates inside a method call's argument list. See complete_expression for self_receiver
|
|
759
|
+
* semantics.
|
|
760
|
+
*/
|
|
672
761
|
static VALUE rdxr_graph_complete_method_argument(int argc, VALUE *argv, VALUE self) {
|
|
673
762
|
VALUE name, nesting, opts;
|
|
674
763
|
rb_scan_args(argc, argv, "2:", &name, &nesting, &opts);
|
|
@@ -691,8 +780,12 @@ static VALUE rdxr_graph_complete_method_argument(int argc, VALUE *argv, VALUE se
|
|
|
691
780
|
return completion_result_to_ruby_array(result, self);
|
|
692
781
|
}
|
|
693
782
|
|
|
694
|
-
|
|
695
|
-
|
|
783
|
+
/*
|
|
784
|
+
* call-seq:
|
|
785
|
+
* exclude_paths(paths) -> nil
|
|
786
|
+
*
|
|
787
|
+
* Excludes the paths from file discovery during indexing.
|
|
788
|
+
*/
|
|
696
789
|
static VALUE rdxr_graph_exclude_paths(VALUE self, VALUE paths) {
|
|
697
790
|
Check_Type(paths, T_ARRAY);
|
|
698
791
|
rdxi_check_array_of_strings(paths);
|
|
@@ -709,8 +802,12 @@ static VALUE rdxr_graph_exclude_paths(VALUE self, VALUE paths) {
|
|
|
709
802
|
return Qnil;
|
|
710
803
|
}
|
|
711
804
|
|
|
712
|
-
|
|
713
|
-
|
|
805
|
+
/*
|
|
806
|
+
* call-seq:
|
|
807
|
+
* excluded_paths -> Array[String]
|
|
808
|
+
*
|
|
809
|
+
* Returns the paths currently excluded from file discovery.
|
|
810
|
+
*/
|
|
714
811
|
static VALUE rdxr_graph_excluded_paths(VALUE self) {
|
|
715
812
|
void *graph;
|
|
716
813
|
TypedData_Get_Struct(self, void*, &graph_type, graph);
|
|
@@ -731,8 +828,81 @@ static VALUE rdxr_graph_excluded_paths(VALUE self) {
|
|
|
731
828
|
return array;
|
|
732
829
|
}
|
|
733
830
|
|
|
734
|
-
|
|
735
|
-
|
|
831
|
+
/*
|
|
832
|
+
* call-seq:
|
|
833
|
+
* workspace_path -> String
|
|
834
|
+
*
|
|
835
|
+
* Returns the root directory of the workspace being indexed.
|
|
836
|
+
*/
|
|
837
|
+
static VALUE rdxr_graph_workspace_path(VALUE self) {
|
|
838
|
+
void *graph;
|
|
839
|
+
TypedData_Get_Struct(self, void*, &graph_type, graph);
|
|
840
|
+
|
|
841
|
+
const char *result = rdx_graph_workspace_path(graph);
|
|
842
|
+
if (result == NULL) {
|
|
843
|
+
rb_raise(rb_eRuntimeError, "Converting workspace path to Ruby string failed");
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
VALUE path = rdxi_owned_c_string_to_ruby(result);
|
|
847
|
+
return path;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/*
|
|
851
|
+
* call-seq:
|
|
852
|
+
* workspace_path=(path) -> void
|
|
853
|
+
*
|
|
854
|
+
* Sets the root directory of the workspace being indexed.
|
|
855
|
+
*/
|
|
856
|
+
static VALUE rdxr_graph_set_workspace_path(VALUE self, VALUE path) {
|
|
857
|
+
Check_Type(path, T_STRING);
|
|
858
|
+
|
|
859
|
+
void *graph;
|
|
860
|
+
TypedData_Get_Struct(self, void*, &graph_type, graph);
|
|
861
|
+
|
|
862
|
+
rdx_graph_set_workspace_path(graph, StringValueCStr(path));
|
|
863
|
+
return path;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/*
|
|
867
|
+
* call-seq:
|
|
868
|
+
* load_config(config_path = nil) -> void
|
|
869
|
+
*
|
|
870
|
+
* Loads a configuration file for the graph. If `config_path` is nil, loads the default configuration file at
|
|
871
|
+
* `workspace_path/rubydex.toml` if it exists. Will raise on malformed files or if an explicit path is given but the
|
|
872
|
+
* file does not exist.
|
|
873
|
+
*/
|
|
874
|
+
static VALUE rdxr_graph_load_config(int argc, VALUE *argv, VALUE self) {
|
|
875
|
+
VALUE config_path;
|
|
876
|
+
rb_scan_args(argc, argv, "01", &config_path);
|
|
877
|
+
|
|
878
|
+
void *graph;
|
|
879
|
+
TypedData_Get_Struct(self, void *, &graph_type, graph);
|
|
880
|
+
|
|
881
|
+
const char *config_path_cstr = NULL;
|
|
882
|
+
|
|
883
|
+
if (!NIL_P(config_path)) {
|
|
884
|
+
Check_Type(config_path, T_STRING);
|
|
885
|
+
config_path_cstr = StringValueCStr(config_path);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
const char *error = rdx_graph_load_config(graph, config_path_cstr);
|
|
889
|
+
if (error == NULL) {
|
|
890
|
+
return Qnil;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
VALUE message = rb_utf8_str_new_cstr(error);
|
|
894
|
+
free_c_string(error);
|
|
895
|
+
|
|
896
|
+
VALUE config_error = rb_const_get(mRubydex, rb_intern("ConfigError"));
|
|
897
|
+
rb_exc_raise(rb_exc_new_str(config_error, message));
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/*
|
|
901
|
+
* call-seq:
|
|
902
|
+
* keyword(name) -> Rubydex::Keyword?
|
|
903
|
+
*
|
|
904
|
+
* Returns the keyword object for the name, or nil if it is not a Ruby keyword.
|
|
905
|
+
*/
|
|
736
906
|
static VALUE rdxr_graph_keyword(VALUE self, VALUE name) {
|
|
737
907
|
Check_Type(name, T_STRING);
|
|
738
908
|
|
|
@@ -783,5 +953,8 @@ void rdxi_initialize_graph(VALUE moduleRubydex) {
|
|
|
783
953
|
rb_define_method(cGraph, "complete_method_argument", rdxr_graph_complete_method_argument, -1);
|
|
784
954
|
rb_define_method(cGraph, "exclude_paths", rdxr_graph_exclude_paths, 1);
|
|
785
955
|
rb_define_method(cGraph, "excluded_paths", rdxr_graph_excluded_paths, 0);
|
|
956
|
+
rb_define_method(cGraph, "workspace_path", rdxr_graph_workspace_path, 0);
|
|
957
|
+
rb_define_method(cGraph, "workspace_path=", rdxr_graph_set_workspace_path, 1);
|
|
958
|
+
rb_define_method(cGraph, "load_config", rdxr_graph_load_config, -1);
|
|
786
959
|
rb_define_method(cGraph, "keyword", rdxr_graph_keyword, 1);
|
|
787
960
|
}
|
data/ext/rubydex/handle.h
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#ifndef RUBYDEX_HANDLE_H
|
|
2
2
|
#define RUBYDEX_HANDLE_H
|
|
3
3
|
|
|
4
|
+
#include "graph.h"
|
|
4
5
|
#include "ruby.h"
|
|
5
6
|
|
|
6
7
|
typedef struct {
|
|
@@ -34,6 +35,18 @@ static const rb_data_type_t handle_type = {
|
|
|
34
35
|
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
|
35
36
|
};
|
|
36
37
|
|
|
38
|
+
static inline void *rdxi_graph_from_handle(VALUE self, HandleData **out_data) {
|
|
39
|
+
HandleData *data;
|
|
40
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
41
|
+
|
|
42
|
+
void *graph;
|
|
43
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
44
|
+
|
|
45
|
+
*out_data = data;
|
|
46
|
+
|
|
47
|
+
return graph;
|
|
48
|
+
}
|
|
49
|
+
|
|
37
50
|
static VALUE rdxr_handle_alloc(VALUE klass) {
|
|
38
51
|
HandleData *data = ALLOC(HandleData);
|
|
39
52
|
|
data/ext/rubydex/location.c
CHANGED
data/ext/rubydex/reference.c
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
#include "handle.h"
|
|
5
5
|
#include "location.h"
|
|
6
6
|
#include "rustbindings.h"
|
|
7
|
+
#include "utils.h"
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* RDoc parser workaround for https://github.com/ruby/rdoc/issues/1744:
|
|
11
|
+
* mRubydex = rb_define_module("Rubydex")
|
|
12
|
+
*/
|
|
7
13
|
|
|
8
14
|
VALUE cReference;
|
|
9
15
|
VALUE cConstantReference;
|
|
@@ -11,31 +17,29 @@ VALUE cUnresolvedConstantReference;
|
|
|
11
17
|
VALUE cResolvedConstantReference;
|
|
12
18
|
VALUE cMethodReference;
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
/*
|
|
21
|
+
* call-seq:
|
|
22
|
+
* name -> String
|
|
23
|
+
*
|
|
24
|
+
* Returns the unresolved constant name.
|
|
25
|
+
*/
|
|
15
26
|
static VALUE rdxr_constant_reference_name(VALUE self) {
|
|
16
27
|
HandleData *data;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
void *graph;
|
|
20
|
-
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
28
|
+
void *graph = rdxi_graph_from_handle(self, &data);
|
|
21
29
|
|
|
22
30
|
const char *name = rdx_constant_reference_name(graph, data->id);
|
|
23
|
-
|
|
24
|
-
return Qnil;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
VALUE str = rb_utf8_str_new_cstr(name);
|
|
28
|
-
free_c_string(name);
|
|
29
|
-
return str;
|
|
31
|
+
return rdxi_owned_c_string_to_ruby(name);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
/*
|
|
35
|
+
* call-seq:
|
|
36
|
+
* location -> Rubydex::Location
|
|
37
|
+
*
|
|
38
|
+
* Returns the source location for this constant reference.
|
|
39
|
+
*/
|
|
33
40
|
static VALUE rdxr_constant_reference_location(VALUE self) {
|
|
34
41
|
HandleData *data;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
void *graph;
|
|
38
|
-
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
42
|
+
void *graph = rdxi_graph_from_handle(self, &data);
|
|
39
43
|
|
|
40
44
|
Location *loc = rdx_constant_reference_location(graph, data->id);
|
|
41
45
|
VALUE location = rdxi_build_location_value(loc);
|
|
@@ -43,31 +47,29 @@ static VALUE rdxr_constant_reference_location(VALUE self) {
|
|
|
43
47
|
return location;
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
/*
|
|
51
|
+
* call-seq:
|
|
52
|
+
* name -> String
|
|
53
|
+
*
|
|
54
|
+
* Returns the referenced method name.
|
|
55
|
+
*/
|
|
47
56
|
static VALUE rdxr_method_reference_name(VALUE self) {
|
|
48
57
|
HandleData *data;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
void *graph;
|
|
52
|
-
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
58
|
+
void *graph = rdxi_graph_from_handle(self, &data);
|
|
53
59
|
|
|
54
60
|
const char *name = rdx_method_reference_name(graph, data->id);
|
|
55
|
-
|
|
56
|
-
return Qnil;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
VALUE str = rb_utf8_str_new_cstr(name);
|
|
60
|
-
free_c_string(name);
|
|
61
|
-
return str;
|
|
61
|
+
return rdxi_owned_c_string_to_ruby(name);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
/*
|
|
65
|
+
* call-seq:
|
|
66
|
+
* location -> Rubydex::Location
|
|
67
|
+
*
|
|
68
|
+
* Returns the source location for this method reference.
|
|
69
|
+
*/
|
|
65
70
|
static VALUE rdxr_method_reference_location(VALUE self) {
|
|
66
71
|
HandleData *data;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
void *graph;
|
|
70
|
-
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
72
|
+
void *graph = rdxi_graph_from_handle(self, &data);
|
|
71
73
|
|
|
72
74
|
Location *loc = rdx_method_reference_location(graph, data->id);
|
|
73
75
|
VALUE location = rdxi_build_location_value(loc);
|
|
@@ -75,15 +77,16 @@ static VALUE rdxr_method_reference_location(VALUE self) {
|
|
|
75
77
|
return location;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
/*
|
|
81
|
+
* call-seq:
|
|
82
|
+
* receiver -> Rubydex::Declaration?
|
|
83
|
+
*
|
|
84
|
+
* Returns the resolved declaration for the receiver of the method call. Returns nil when the receiver is not a tracked
|
|
85
|
+
* constant or cannot be resolved.
|
|
86
|
+
*/
|
|
81
87
|
static VALUE rdxr_method_reference_receiver(VALUE self) {
|
|
82
88
|
HandleData *data;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
void *graph;
|
|
86
|
-
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
89
|
+
void *graph = rdxi_graph_from_handle(self, &data);
|
|
87
90
|
|
|
88
91
|
const struct CDeclaration *decl = rdx_method_reference_receiver_declaration(graph, data->id);
|
|
89
92
|
if (decl == NULL) {
|
|
@@ -97,13 +100,15 @@ static VALUE rdxr_method_reference_receiver(VALUE self) {
|
|
|
97
100
|
return rb_class_new_instance(2, argv, decl_class);
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
|
|
103
|
+
/*
|
|
104
|
+
* call-seq:
|
|
105
|
+
* declaration -> Rubydex::Declaration
|
|
106
|
+
*
|
|
107
|
+
* Returns the resolved declaration.
|
|
108
|
+
*/
|
|
101
109
|
static VALUE rdxr_resolved_constant_reference_declaration(VALUE self) {
|
|
102
110
|
HandleData *data;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
void *graph;
|
|
106
|
-
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
111
|
+
void *graph = rdxi_graph_from_handle(self, &data);
|
|
107
112
|
|
|
108
113
|
const struct CDeclaration *decl = rdx_resolved_constant_reference_declaration(graph, data->id);
|
|
109
114
|
if (decl == NULL) {
|
data/ext/rubydex/rubydex.c
CHANGED
|
@@ -12,6 +12,11 @@ VALUE mRubydex;
|
|
|
12
12
|
void Init_rubydex(void) {
|
|
13
13
|
rb_ext_ractor_safe(true);
|
|
14
14
|
|
|
15
|
+
/*
|
|
16
|
+
* Document-module: Rubydex
|
|
17
|
+
*
|
|
18
|
+
* Namespace for Rubydex's Ruby API.
|
|
19
|
+
*/
|
|
15
20
|
mRubydex = rb_define_module("Rubydex");
|
|
16
21
|
rdxi_initialize_graph(mRubydex);
|
|
17
22
|
rdxi_initialize_declaration(mRubydex);
|