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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9838707935ff868fb005a0d85254747ea6e3a5b5871c0626f5ec6641e0878e2
4
- data.tar.gz: 87f4157545d244bfb3bb7e869914dc355d1d2b3dd0e181e439ce81ce1073cdc5
3
+ metadata.gz: 13a3cb3d4cbe536ab21b25d16a2ec0903b600dd2ffe90b062657c38cefc3dfbd
4
+ data.tar.gz: 43664af48f34fe8ca7cf006cc5a77548fad873df329b5f45c344aea0f34fff14
5
5
  SHA512:
6
- metadata.gz: 7a69359f6261bb54eb0f576fbb9c31b85eb209c45fdb60d81d5f965abed05ac535409191b8a87376bcabe8278149ef1f87c8097162204d583f1ed2670bea7d5e
7
- data.tar.gz: 862070c2cd67d83aae2da083987235017610d9637d6b90b49b8270a6ab8d3c4a1914333e30152f025f3e24e317fd3b3d0a74f3f20e64ffcf25752503c40baa7f
6
+ metadata.gz: 3e8f31a47de5aa62df61a57c9545a3b93155617e96fb4064ef95201c38c43949b524688e3ad8204471240dacc62f0f2e34b02fd49e2257fd181b1b9d69b0924a
7
+ data.tar.gz: c7ebeb6983652dfd86591054a954ee1ecb3b5bc55c00a43581014344c337f46e5ccc5b6539fe50e9861bd30ef7e88ba596e7734570575ed3dee3d3437c707519
@@ -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
- // Free the converted file paths and allow the GC to collect them
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
- // Graph#search: () -> Enumerator[Declaration]
132
- // Returns an enumerator that yields all declarations lazily
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
- const char *c_query = StringValueCStr(query);
152
+ return rdxr_graph_yield_search_results(self, rdx_graph_declarations_search(graph, StringValueCStr(query)));
153
+ }
142
154
 
143
- void *iter = rdx_graph_declarations_search(graph, c_query);
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 (iter == NULL) {
146
- // The only case where the iterator will be NULL instead of a list is if the query cannot be converted to a Rust
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
- VALUE args = rb_ary_new_from_args(2, self, ULL2NUM((uintptr_t)iter));
152
- rb_ensure(rdxi_declarations_yield, args, rdxi_declarations_ensure, args);
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
- for (size_t i = 0; i < length; i++) {
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
- for (size_t i = 0; i < paths_len; i++) {
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
- for (size_t i = 0; i < paths_len; i++) {
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubydex
4
- VERSION = "0.1.0.beta9"
4
+ VERSION = "0.1.0.beta10"
5
5
  end
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