rubydex 0.1.0.beta9 → 0.1.0.beta10
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/ext/rubydex/declaration.c +24 -0
- data/ext/rubydex/graph.c +33 -28
- data/ext/rubydex/utils.c +10 -0
- data/ext/rubydex/utils.h +4 -1
- data/lib/rubydex/librubydex_sys.so +0 -0
- data/lib/rubydex/version.rb +1 -1
- data/rbi/rubydex.rbi +6 -0
- data/rust/rubydex/src/indexing/rbs_indexer.rs +623 -7
- data/rust/rubydex/src/indexing/ruby_indexer.rs +256 -10
- data/rust/rubydex/src/model/declaration.rs +4 -4
- data/rust/rubydex/src/model/definitions.rs +15 -15
- data/rust/rubydex/src/model/id.rs +45 -19
- data/rust/rubydex/src/model/ids.rs +6 -6
- data/rust/rubydex/src/model/keywords.rs +256 -0
- data/rust/rubydex/src/model/name.rs +1 -1
- data/rust/rubydex/src/model/references.rs +1 -1
- data/rust/rubydex/src/model.rs +1 -0
- data/rust/rubydex/src/query.rs +275 -32
- data/rust/rubydex/src/resolution.rs +22 -0
- data/rust/rubydex/src/test_utils/local_graph_test.rs +32 -3
- data/rust/rubydex-mcp/src/server.rs +13 -2
- data/rust/rubydex-mcp/src/tools.rs +5 -1
- data/rust/rubydex-sys/src/declaration_api.rs +28 -0
- data/rust/rubydex-sys/src/graph_api.rs +47 -15
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 13a3cb3d4cbe536ab21b25d16a2ec0903b600dd2ffe90b062657c38cefc3dfbd
|
|
4
|
+
data.tar.gz: 43664af48f34fe8ca7cf006cc5a77548fad873df329b5f45c344aea0f34fff14
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e8f31a47de5aa62df61a57c9545a3b93155617e96fb4064ef95201c38c43949b524688e3ad8204471240dacc62f0f2e34b02fd49e2257fd181b1b9d69b0924a
|
|
7
|
+
data.tar.gz: c7ebeb6983652dfd86591054a954ee1ecb3b5bc55c00a43581014344c337f46e5ccc5b6539fe50e9861bd30ef7e88ba596e7734570575ed3dee3d3437c707519
|
data/ext/rubydex/declaration.c
CHANGED
|
@@ -295,6 +295,29 @@ static VALUE rdxr_declaration_descendants(VALUE self) {
|
|
|
295
295
|
return self;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
// Namespace#members: () -> Enumerator[Declaration]
|
|
299
|
+
static VALUE rdxr_declaration_members(VALUE self) {
|
|
300
|
+
if (!rb_block_given_p()) {
|
|
301
|
+
return rb_enumeratorize(self, rb_str_new2("members"), 0, NULL);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
HandleData *data;
|
|
305
|
+
TypedData_Get_Struct(self, HandleData, &handle_type, data);
|
|
306
|
+
|
|
307
|
+
void *graph;
|
|
308
|
+
TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
|
|
309
|
+
|
|
310
|
+
void *iter = rdx_declaration_members(graph, data->id);
|
|
311
|
+
if (iter == NULL) {
|
|
312
|
+
rb_raise(rb_eRuntimeError, "failed to create iterator");
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
|
|
316
|
+
rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
|
|
317
|
+
|
|
318
|
+
return self;
|
|
319
|
+
}
|
|
320
|
+
|
|
298
321
|
// Size function for the Declaration#references enumerator
|
|
299
322
|
static VALUE declaration_references_size(VALUE self, VALUE _args, VALUE _eobj) {
|
|
300
323
|
HandleData *data;
|
|
@@ -359,6 +382,7 @@ void rdxi_initialize_declaration(VALUE mRubydex) {
|
|
|
359
382
|
rb_define_method(cNamespace, "singleton_class", rdxr_declaration_singleton_class, 0);
|
|
360
383
|
rb_define_method(cNamespace, "ancestors", rdxr_declaration_ancestors, 0);
|
|
361
384
|
rb_define_method(cNamespace, "descendants", rdxr_declaration_descendants, 0);
|
|
385
|
+
rb_define_method(cNamespace, "members", rdxr_declaration_members, 0);
|
|
362
386
|
|
|
363
387
|
rb_funcall(rb_singleton_class(cDeclaration), rb_intern("private"), 1, ID2SYM(rb_intern("new")));
|
|
364
388
|
}
|
data/ext/rubydex/graph.c
CHANGED
|
@@ -43,11 +43,7 @@ static VALUE rdxr_graph_index_all(VALUE self, VALUE file_paths) {
|
|
|
43
43
|
size_t error_count = 0;
|
|
44
44
|
const char *const *errors = rdx_index_all(graph, (const char **)converted_file_paths, length, &error_count);
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
for (size_t i = 0; i < length; i++) {
|
|
48
|
-
free(converted_file_paths[i]);
|
|
49
|
-
}
|
|
50
|
-
free(converted_file_paths);
|
|
46
|
+
rdxi_free_str_array(converted_file_paths, length);
|
|
51
47
|
|
|
52
48
|
if (errors == NULL) {
|
|
53
49
|
return rb_ary_new();
|
|
@@ -128,9 +124,24 @@ static VALUE rdxr_graph_declarations(VALUE self) {
|
|
|
128
124
|
return self;
|
|
129
125
|
}
|
|
130
126
|
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
static VALUE rdxr_graph_yield_search_results(VALUE self, void *iter) {
|
|
128
|
+
if (iter == NULL) {
|
|
129
|
+
// The only case where the iterator will be NULL instead of a list is if the query cannot be converted to a Rust
|
|
130
|
+
// string
|
|
131
|
+
rb_raise(rb_eRuntimeError, "Converting query to Rust string failed");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
VALUE args = rb_ary_new_from_args(2, self, ULL2NUM((uintptr_t)iter));
|
|
135
|
+
rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
|
|
136
|
+
|
|
137
|
+
return self;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Graph#search: (String query) -> Enumerator[Declaration]
|
|
141
|
+
// Returns an enumerator that yields declarations matching the query exactly (substring match)
|
|
133
142
|
static VALUE rdxr_graph_search(VALUE self, VALUE query) {
|
|
143
|
+
Check_Type(query, T_STRING);
|
|
144
|
+
|
|
134
145
|
if (!rb_block_given_p()) {
|
|
135
146
|
return rb_enumeratorize(self, rb_str_new2("search"), 1, &query);
|
|
136
147
|
}
|
|
@@ -138,20 +149,22 @@ static VALUE rdxr_graph_search(VALUE self, VALUE query) {
|
|
|
138
149
|
void *graph;
|
|
139
150
|
TypedData_Get_Struct(self, void *, &graph_type, graph);
|
|
140
151
|
|
|
141
|
-
|
|
152
|
+
return rdxr_graph_yield_search_results(self, rdx_graph_declarations_search(graph, StringValueCStr(query)));
|
|
153
|
+
}
|
|
142
154
|
|
|
143
|
-
|
|
155
|
+
// Graph#fuzzy_search: (String query) -> Enumerator[Declaration]
|
|
156
|
+
// Returns an enumerator that yields declarations matching the query fuzzily
|
|
157
|
+
static VALUE rdxr_graph_fuzzy_search(VALUE self, VALUE query) {
|
|
158
|
+
Check_Type(query, T_STRING);
|
|
144
159
|
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
// string
|
|
148
|
-
rb_raise(rb_eRuntimeError, "Converting query to Rust string failed");
|
|
160
|
+
if (!rb_block_given_p()) {
|
|
161
|
+
return rb_enumeratorize(self, rb_str_new2("fuzzy_search"), 1, &query);
|
|
149
162
|
}
|
|
150
163
|
|
|
151
|
-
|
|
152
|
-
|
|
164
|
+
void *graph;
|
|
165
|
+
TypedData_Get_Struct(self, void *, &graph_type, graph);
|
|
153
166
|
|
|
154
|
-
return self;
|
|
167
|
+
return rdxr_graph_yield_search_results(self, rdx_graph_declarations_fuzzy_search(graph, StringValueCStr(query)));
|
|
155
168
|
}
|
|
156
169
|
|
|
157
170
|
// Body function for rb_ensure in Graph#documents
|
|
@@ -348,10 +361,7 @@ static VALUE rdxr_graph_resolve_constant(VALUE self, VALUE const_name, VALUE nes
|
|
|
348
361
|
const CDeclaration *decl =
|
|
349
362
|
rdx_graph_resolve_constant(graph, StringValueCStr(const_name), (const char **)converted_file_paths, length);
|
|
350
363
|
|
|
351
|
-
|
|
352
|
-
free(converted_file_paths[i]);
|
|
353
|
-
}
|
|
354
|
-
free(converted_file_paths);
|
|
364
|
+
rdxi_free_str_array(converted_file_paths, length);
|
|
355
365
|
|
|
356
366
|
if (decl == NULL) {
|
|
357
367
|
return Qnil;
|
|
@@ -379,10 +389,7 @@ static VALUE rdxr_graph_resolve_require_path(VALUE self, VALUE require_path, VAL
|
|
|
379
389
|
|
|
380
390
|
const uint64_t *uri_id = rdx_resolve_require_path(graph, path_str, (const char **)converted_paths, paths_len);
|
|
381
391
|
|
|
382
|
-
|
|
383
|
-
free(converted_paths[i]);
|
|
384
|
-
}
|
|
385
|
-
free(converted_paths);
|
|
392
|
+
rdxi_free_str_array(converted_paths, paths_len);
|
|
386
393
|
|
|
387
394
|
if (uri_id == NULL) {
|
|
388
395
|
return Qnil;
|
|
@@ -407,10 +414,7 @@ static VALUE rdxr_graph_require_paths(VALUE self, VALUE load_path) {
|
|
|
407
414
|
size_t out_count = 0;
|
|
408
415
|
const char *const *results = rdx_require_paths(graph, (const char **)converted_paths, paths_len, &out_count);
|
|
409
416
|
|
|
410
|
-
|
|
411
|
-
free(converted_paths[i]);
|
|
412
|
-
}
|
|
413
|
-
free(converted_paths);
|
|
417
|
+
rdxi_free_str_array(converted_paths, paths_len);
|
|
414
418
|
|
|
415
419
|
if (results == NULL) {
|
|
416
420
|
return rb_ary_new();
|
|
@@ -501,6 +505,7 @@ void rdxi_initialize_graph(VALUE moduleRubydex) {
|
|
|
501
505
|
rb_define_method(cGraph, "check_integrity", rdxr_graph_check_integrity, 0);
|
|
502
506
|
rb_define_method(cGraph, "[]", rdxr_graph_aref, 1);
|
|
503
507
|
rb_define_method(cGraph, "search", rdxr_graph_search, 1);
|
|
508
|
+
rb_define_method(cGraph, "fuzzy_search", rdxr_graph_fuzzy_search, 1);
|
|
504
509
|
rb_define_method(cGraph, "encoding=", rdxr_graph_set_encoding, 1);
|
|
505
510
|
rb_define_method(cGraph, "resolve_require_path", rdxr_graph_resolve_require_path, 2);
|
|
506
511
|
rb_define_method(cGraph, "require_paths", rdxr_graph_require_paths, 1);
|
data/ext/rubydex/utils.c
CHANGED
|
@@ -19,6 +19,16 @@ char **rdxi_str_array_to_char(VALUE array, size_t length) {
|
|
|
19
19
|
return converted_array;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// Free a char** array allocated by rdxi_str_array_to_char
|
|
23
|
+
void rdxi_free_str_array(char **array, size_t length) {
|
|
24
|
+
if (array != NULL) {
|
|
25
|
+
for (size_t i = 0; i < length; i++) {
|
|
26
|
+
free(array[i]);
|
|
27
|
+
}
|
|
28
|
+
free(array);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
22
32
|
// Verify that the Ruby object is an array of strings or raise `TypeError`
|
|
23
33
|
void rdxi_check_array_of_strings(VALUE array) {
|
|
24
34
|
Check_Type(array, T_ARRAY);
|
data/ext/rubydex/utils.h
CHANGED
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
#include "ruby.h"
|
|
5
5
|
|
|
6
6
|
// Convert a Ruby array of strings into a double char pointer so that we can pass that to Rust.
|
|
7
|
-
// This copies the data so it must be freed
|
|
7
|
+
// This copies the data so it must be freed with rdxi_free_str_array
|
|
8
8
|
char **rdxi_str_array_to_char(VALUE array, size_t length);
|
|
9
9
|
|
|
10
|
+
// Free a char** array allocated by rdxi_str_array_to_char
|
|
11
|
+
void rdxi_free_str_array(char **array, size_t length);
|
|
12
|
+
|
|
10
13
|
// Verify that the Ruby object is an array of strings or raise `TypeError`
|
|
11
14
|
void rdxi_check_array_of_strings(VALUE array);
|
|
12
15
|
|
|
Binary file
|
data/lib/rubydex/version.rb
CHANGED
data/rbi/rubydex.rbi
CHANGED
|
@@ -59,6 +59,9 @@ class Rubydex::Namespace < Rubydex::Declaration
|
|
|
59
59
|
sig { returns(T::Enumerable[Rubydex::Namespace]) }
|
|
60
60
|
def descendants; end
|
|
61
61
|
|
|
62
|
+
sig { returns(T::Enumerable[Rubydex::Declaration]) }
|
|
63
|
+
def members; end
|
|
64
|
+
|
|
62
65
|
sig { params(name: String).returns(T.nilable(Rubydex::Declaration)) }
|
|
63
66
|
def member(name); end
|
|
64
67
|
|
|
@@ -203,6 +206,9 @@ class Rubydex::Graph
|
|
|
203
206
|
sig { params(query: String).returns(T::Enumerable[Rubydex::Declaration]) }
|
|
204
207
|
def search(query); end
|
|
205
208
|
|
|
209
|
+
sig { params(query: String).returns(T::Enumerable[Rubydex::Declaration]) }
|
|
210
|
+
def fuzzy_search(query); end
|
|
211
|
+
|
|
206
212
|
sig { params(encoding: String).void }
|
|
207
213
|
def encoding=(encoding); end
|
|
208
214
|
|