rubydex 0.2.0-aarch64-linux → 0.2.2-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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44787b43319481966587e2e358c33a55e58800a092864ef132d9c10d2271f5c0
4
- data.tar.gz: 520ab23713bc163e050622c52b986672e591c116954935e6957c7f8e52dfe343
3
+ metadata.gz: 220a0eb3de71608c1daa45286224aa1f11ebd03b893564e60cfd9e7db66124c2
4
+ data.tar.gz: 747ef3a246e405c236b9efcc6b2d592033025b154cdf5e9afa03006732a10303
5
5
  SHA512:
6
- metadata.gz: 941b4124e0ec93076390a9a777d538189316512a964d4cc2210ad9775ff14408ccd2912c2e757314304ba4eb343bef241a82399b8a99d8f3b5a9b959608126ff
7
- data.tar.gz: 74a4eaeeb123b057140cd64529dc4502232ca4b3821a992f6a91cb85994de0b3173f0042249aa8eeab4c53cb7486dde3bb9e7ee3c790dde6d29ad6bbb00b7750
6
+ metadata.gz: 4afa9fef910c50747666dbb3b464d86ba791e13e1a260041b9c845b32786a049b02da55a76583c98c749a4deabaa412e35fc71c45cb7da476b6058c88199fd08
7
+ data.tar.gz: 851d2924ff4d895866b5663e1f144960823fe57375a20511a08378840d013f9c6bf4f7de4a1303f9a1da2ea28ee4c2376aceb848d702f41175e933ccd98c7f8f
@@ -407,6 +407,38 @@ static VALUE rdxr_variable_declaration_references(VALUE self) {
407
407
  return rb_ary_new();
408
408
  }
409
409
 
410
+ static VALUE rdxi_visibility_to_symbol(CVisibility visibility) {
411
+ switch (visibility) {
412
+ case CVisibility_Public:
413
+ return ID2SYM(rb_intern("public"));
414
+ case CVisibility_Protected:
415
+ return ID2SYM(rb_intern("protected"));
416
+ case CVisibility_Private:
417
+ return ID2SYM(rb_intern("private"));
418
+ default:
419
+ rb_raise(rb_eRuntimeError, "Unknown CVisibility: %d", visibility);
420
+ }
421
+ }
422
+
423
+ // Declaration#visibility -> Symbol
424
+ static VALUE rdxr_declaration_visibility(VALUE self) {
425
+ HandleData *data;
426
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
427
+
428
+ void *graph;
429
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
430
+
431
+ const CVisibility *visibility = rdx_graph_visibility(graph, data->id);
432
+ if (visibility == NULL) {
433
+ rb_raise(rb_eRuntimeError, "declaration has no visibility");
434
+ }
435
+
436
+ VALUE symbol = rdxi_visibility_to_symbol(*visibility);
437
+ free_c_visibility(visibility);
438
+
439
+ return symbol;
440
+ }
441
+
410
442
  // ConstantAlias#target -> Declaration?
411
443
  // Returns the first resolved target declaration for this constant alias, or nil if none of its definitions resolved to
412
444
  // a target
@@ -459,13 +491,19 @@ void rdxi_initialize_declaration(VALUE mRubydex) {
459
491
  rb_define_method(cNamespace, "descendants", rdxr_declaration_descendants, 0);
460
492
  rb_define_method(cNamespace, "members", rdxr_declaration_members, 0);
461
493
 
494
+ rb_define_method(cClass, "visibility", rdxr_declaration_visibility, 0);
495
+ rb_define_method(cModule, "visibility", rdxr_declaration_visibility, 0);
496
+
462
497
  // Constant and ConstantAlias have constant references
463
498
  rb_define_method(cConstant, "references", rdxr_constant_declaration_references, 0);
499
+ rb_define_method(cConstant, "visibility", rdxr_declaration_visibility, 0);
464
500
  rb_define_method(cConstantAlias, "references", rdxr_constant_declaration_references, 0);
465
501
  rb_define_method(cConstantAlias, "target", rdxr_constant_alias_target, 0);
502
+ rb_define_method(cConstantAlias, "visibility", rdxr_declaration_visibility, 0);
466
503
 
467
504
  // Method has method references
468
505
  rb_define_method(cMethod, "references", rdxr_method_declaration_references, 0);
506
+ rb_define_method(cMethod, "visibility", rdxr_declaration_visibility, 0);
469
507
 
470
508
  // Variable declarations don't yet support references
471
509
  rb_define_method(cGlobalVariable, "references", rdxr_variable_declaration_references, 0);
@@ -3,6 +3,7 @@
3
3
  #include "handle.h"
4
4
  #include "location.h"
5
5
  #include "reference.h"
6
+ #include "signature.h"
6
7
  #include "ruby/internal/scan_args.h"
7
8
  #include "rustbindings.h"
8
9
 
@@ -239,6 +240,30 @@ static VALUE rdxr_definition_mixins(VALUE self) {
239
240
  return ary;
240
241
  }
241
242
 
243
+ // MethodDefinition#signatures -> [Rubydex::Signature]
244
+ static VALUE rdxr_method_definition_signatures(VALUE self) {
245
+ HandleData *data;
246
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
247
+
248
+ void *graph;
249
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
250
+
251
+ SignatureArray *arr = rdx_definition_signatures(graph, data->id);
252
+ return rdxi_signatures_to_ruby(arr);
253
+ }
254
+
255
+ // MethodAliasDefinition#signatures -> [Rubydex::Signature]
256
+ static VALUE rdxr_method_alias_definition_signatures(VALUE self) {
257
+ HandleData *data;
258
+ TypedData_Get_Struct(self, HandleData, &handle_type, data);
259
+
260
+ void *graph;
261
+ TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
262
+
263
+ SignatureArray *arr = rdx_method_alias_definition_signatures(graph, data->id);
264
+ return rdxi_signatures_to_ruby(arr);
265
+ }
266
+
242
267
  void rdxi_initialize_definition(VALUE mod) {
243
268
  mRubydex = mod;
244
269
 
@@ -273,6 +298,7 @@ void rdxi_initialize_definition(VALUE mod) {
273
298
  cConstantVisibilityDefinition = rb_define_class_under(mRubydex, "ConstantVisibilityDefinition", cDefinition);
274
299
  cMethodVisibilityDefinition = rb_define_class_under(mRubydex, "MethodVisibilityDefinition", cDefinition);
275
300
  cMethodDefinition = rb_define_class_under(mRubydex, "MethodDefinition", cDefinition);
301
+ rb_define_method(cMethodDefinition, "signatures", rdxr_method_definition_signatures, 0);
276
302
  cAttrAccessorDefinition = rb_define_class_under(mRubydex, "AttrAccessorDefinition", cDefinition);
277
303
  cAttrReaderDefinition = rb_define_class_under(mRubydex, "AttrReaderDefinition", cDefinition);
278
304
  cAttrWriterDefinition = rb_define_class_under(mRubydex, "AttrWriterDefinition", cDefinition);
@@ -280,5 +306,6 @@ void rdxi_initialize_definition(VALUE mod) {
280
306
  cInstanceVariableDefinition = rb_define_class_under(mRubydex, "InstanceVariableDefinition", cDefinition);
281
307
  cClassVariableDefinition = rb_define_class_under(mRubydex, "ClassVariableDefinition", cDefinition);
282
308
  cMethodAliasDefinition = rb_define_class_under(mRubydex, "MethodAliasDefinition", cDefinition);
309
+ rb_define_method(cMethodAliasDefinition, "signatures", rdxr_method_alias_definition_signatures, 0);
283
310
  cGlobalVariableAliasDefinition = rb_define_class_under(mRubydex, "GlobalVariableAliasDefinition", cDefinition);
284
311
  }
data/ext/rubydex/graph.c CHANGED
@@ -13,6 +13,31 @@ static VALUE mRubydex;
13
13
  static VALUE cKeyword;
14
14
  static VALUE cKeywordParameter;
15
15
 
16
+ // Interned once in `rdxi_initialize_graph` to avoid repeated symbol-table lookups on hot completion paths.
17
+ static ID id_self_receiver;
18
+
19
+ // Extracts the optional `self_receiver:` kwarg from `opts`. Returns NULL when the kwarg is
20
+ // absent or nil; raises ArgumentError when the value is the wrong type or empty.
21
+ static const char *extract_self_receiver(VALUE opts) {
22
+ if (NIL_P(opts)) {
23
+ return NULL;
24
+ }
25
+
26
+ VALUE kwarg_val;
27
+ rb_get_kwargs(opts, &id_self_receiver, 0, 1, &kwarg_val);
28
+
29
+ if (kwarg_val == Qundef || NIL_P(kwarg_val)) {
30
+ return NULL;
31
+ }
32
+
33
+ Check_Type(kwarg_val, T_STRING);
34
+ if (RSTRING_LEN(kwarg_val) == 0) {
35
+ rb_raise(rb_eArgError, "self_receiver cannot be empty");
36
+ }
37
+
38
+ return StringValueCStr(kwarg_val);
39
+ }
40
+
16
41
  // Free function for the custom Graph allocator. We always have to call into Rust to free data allocated by it
17
42
  static void graph_free(void *ptr) {
18
43
  if (ptr) {
@@ -564,12 +589,18 @@ static VALUE completion_result_to_ruby_array(struct CompletionResult result, VAL
564
589
  return ruby_array;
565
590
  }
566
591
 
567
- // Graph#complete_expression: (Array[String] nesting) -> Array[Declaration | Keyword]
592
+ // Graph#complete_expression: (Array[String] nesting, self_receiver: nil) -> Array[Declaration | Keyword]
568
593
  // Returns completion candidates for an expression context.
569
- // The nesting array represents the lexical scope stack
570
- static VALUE rdxr_graph_complete_expression(VALUE self, VALUE nesting) {
594
+ // The nesting array represents the lexical scope stack. The optional self_receiver keyword argument
595
+ // overrides the self-type (e.g., "Foo::<Foo>" for `def Foo.bar`); when nil, self is derived from
596
+ // the innermost nesting element.
597
+ static VALUE rdxr_graph_complete_expression(int argc, VALUE *argv, VALUE self) {
598
+ VALUE nesting, opts;
599
+ rb_scan_args(argc, argv, "1:", &nesting, &opts);
571
600
  rdxi_check_array_of_strings(nesting);
572
601
 
602
+ const char *self_receiver = extract_self_receiver(opts);
603
+
573
604
  void *graph;
574
605
  TypedData_Get_Struct(self, void *, &graph_type, graph);
575
606
 
@@ -577,42 +608,62 @@ static VALUE rdxr_graph_complete_expression(VALUE self, VALUE nesting) {
577
608
  char **converted_nesting = rdxi_str_array_to_char(nesting, nesting_count);
578
609
 
579
610
  struct CompletionResult result =
580
- rdx_graph_complete_expression(graph, (const char *const *)converted_nesting, nesting_count);
611
+ rdx_graph_complete_expression(graph, (const char *const *)converted_nesting, nesting_count, self_receiver);
581
612
 
582
613
  rdxi_free_str_array(converted_nesting, nesting_count);
583
614
  return completion_result_to_ruby_array(result, self);
584
615
  }
585
616
 
586
- // Graph#complete_namespace_access: (String name) -> Array[Declaration]
617
+ // Graph#complete_namespace_access: (String name, self_receiver: nil) -> Array[Declaration]
587
618
  // Returns completion candidates after a namespace access operator (e.g., `Foo::`).
588
- static VALUE rdxr_graph_complete_namespace_access(VALUE self, VALUE name) {
619
+ // The optional self_receiver kwarg is the caller's runtime self type, used to filter
620
+ // visibility-restricted singleton methods (e.g., `private_class_method`).
621
+ static VALUE rdxr_graph_complete_namespace_access(int argc, VALUE *argv, VALUE self) {
622
+ VALUE name, opts;
623
+ rb_scan_args(argc, argv, "1:", &name, &opts);
589
624
  Check_Type(name, T_STRING);
590
625
 
626
+ const char *self_receiver = extract_self_receiver(opts);
627
+
591
628
  void *graph;
592
629
  TypedData_Get_Struct(self, void *, &graph_type, graph);
593
630
 
594
- struct CompletionResult result = rdx_graph_complete_namespace_access(graph, StringValueCStr(name));
631
+ struct CompletionResult result =
632
+ rdx_graph_complete_namespace_access(graph, StringValueCStr(name), self_receiver);
595
633
  return completion_result_to_ruby_array(result, self);
596
634
  }
597
635
 
598
- // Graph#complete_method_call: (String name) -> Array[Declaration]
636
+ // Graph#complete_method_call: (String name, self_receiver: nil) -> Array[Declaration]
599
637
  // Returns completion candidates after a method call operator (e.g., `foo.`).
600
- static VALUE rdxr_graph_complete_method_call(VALUE self, VALUE name) {
638
+ // The optional self_receiver kwarg is the caller's runtime self type, used for MRI-style
639
+ // visibility checks (private/protected).
640
+ static VALUE rdxr_graph_complete_method_call(int argc, VALUE *argv, VALUE self) {
641
+ VALUE name, opts;
642
+ rb_scan_args(argc, argv, "1:", &name, &opts);
601
643
  Check_Type(name, T_STRING);
602
644
 
645
+ const char *self_receiver = extract_self_receiver(opts);
646
+
603
647
  void *graph;
604
648
  TypedData_Get_Struct(self, void *, &graph_type, graph);
605
649
 
606
- struct CompletionResult result = rdx_graph_complete_method_call(graph, StringValueCStr(name));
650
+ struct CompletionResult result =
651
+ rdx_graph_complete_method_call(graph, StringValueCStr(name), self_receiver);
607
652
  return completion_result_to_ruby_array(result, self);
608
653
  }
609
654
 
610
- // Graph#complete_method_argument: (String name, Array[String] nesting) -> Array[Declaration | Keyword | KeywordParameter]
655
+ // Graph#complete_method_argument: (String name, Array[String] nesting, self_receiver: nil) -> Array[Declaration | Keyword | KeywordParameter]
611
656
  // Returns completion candidates inside a method call's argument list (e.g., `foo.bar(|)`).
612
- static VALUE rdxr_graph_complete_method_argument(VALUE self, VALUE name, VALUE nesting) {
657
+ // See complete_expression for semantics of self_receiver.
658
+ static VALUE rdxr_graph_complete_method_argument(int argc, VALUE *argv, VALUE self) {
659
+ VALUE name, nesting, opts;
660
+ rb_scan_args(argc, argv, "2:", &name, &nesting, &opts);
661
+
613
662
  Check_Type(name, T_STRING);
614
663
  rdxi_check_array_of_strings(nesting);
615
664
 
665
+ const char *self_receiver = extract_self_receiver(opts);
666
+
616
667
  void *graph;
617
668
  TypedData_Get_Struct(self, void *, &graph_type, graph);
618
669
 
@@ -620,7 +671,7 @@ static VALUE rdxr_graph_complete_method_argument(VALUE self, VALUE name, VALUE n
620
671
  char **converted_nesting = rdxi_str_array_to_char(nesting, nesting_count);
621
672
 
622
673
  struct CompletionResult result = rdx_graph_complete_method_argument(
623
- graph, StringValueCStr(name), (const char *const *)converted_nesting, nesting_count);
674
+ graph, StringValueCStr(name), (const char *const *)converted_nesting, nesting_count, self_receiver);
624
675
 
625
676
  rdxi_free_str_array(converted_nesting, nesting_count);
626
677
  return completion_result_to_ruby_array(result, self);
@@ -691,6 +742,8 @@ void rdxi_initialize_graph(VALUE moduleRubydex) {
691
742
  cKeyword = rb_define_class_under(mRubydex, "Keyword", rb_cObject);
692
743
  cKeywordParameter = rb_define_class_under(mRubydex, "KeywordParameter", rb_cObject);
693
744
 
745
+ id_self_receiver = rb_intern("self_receiver");
746
+
694
747
  rb_define_alloc_func(cGraph, rdxr_graph_alloc);
695
748
  rb_define_method(cGraph, "index_all", rdxr_graph_index_all, 1);
696
749
  rb_define_method(cGraph, "index_source", rdxr_graph_index_source, 3);
@@ -710,10 +763,10 @@ void rdxi_initialize_graph(VALUE moduleRubydex) {
710
763
  rb_define_method(cGraph, "encoding=", rdxr_graph_set_encoding, 1);
711
764
  rb_define_method(cGraph, "resolve_require_path", rdxr_graph_resolve_require_path, 2);
712
765
  rb_define_method(cGraph, "require_paths", rdxr_graph_require_paths, 1);
713
- rb_define_method(cGraph, "complete_expression", rdxr_graph_complete_expression, 1);
714
- rb_define_method(cGraph, "complete_namespace_access", rdxr_graph_complete_namespace_access, 1);
715
- rb_define_method(cGraph, "complete_method_call", rdxr_graph_complete_method_call, 1);
716
- rb_define_method(cGraph, "complete_method_argument", rdxr_graph_complete_method_argument, 2);
766
+ rb_define_method(cGraph, "complete_expression", rdxr_graph_complete_expression, -1);
767
+ rb_define_method(cGraph, "complete_namespace_access", rdxr_graph_complete_namespace_access, -1);
768
+ rb_define_method(cGraph, "complete_method_call", rdxr_graph_complete_method_call, -1);
769
+ rb_define_method(cGraph, "complete_method_argument", rdxr_graph_complete_method_argument, -1);
717
770
  rb_define_method(cGraph, "exclude_paths", rdxr_graph_exclude_paths, 1);
718
771
  rb_define_method(cGraph, "excluded_paths", rdxr_graph_excluded_paths, 0);
719
772
  rb_define_method(cGraph, "keyword", rdxr_graph_keyword, 1);
@@ -5,6 +5,7 @@
5
5
  #include "graph.h"
6
6
  #include "location.h"
7
7
  #include "reference.h"
8
+ #include "signature.h"
8
9
 
9
10
  VALUE mRubydex;
10
11
 
@@ -19,4 +20,5 @@ void Init_rubydex(void) {
19
20
  rdxi_initialize_location(mRubydex);
20
21
  rdxi_initialize_diagnostic(mRubydex);
21
22
  rdxi_initialize_reference(mRubydex);
23
+ rdxi_initialize_signature(mRubydex);
22
24
  }
@@ -0,0 +1,83 @@
1
+ #include "signature.h"
2
+ #include "location.h"
3
+
4
+ static VALUE empty_params = Qundef;
5
+
6
+ VALUE cSignature;
7
+ VALUE cParameter;
8
+ VALUE cPositionalParameter;
9
+ VALUE cOptionalPositionalParameter;
10
+ VALUE cRestPositionalParameter;
11
+ VALUE cPostParameter;
12
+ VALUE cKeywordParameter;
13
+ VALUE cOptionalKeywordParameter;
14
+ VALUE cRestKeywordParameter;
15
+ VALUE cForwardParameter;
16
+ VALUE cBlockParameter;
17
+
18
+ static VALUE parameter_class_for_kind(ParameterKind kind) {
19
+ switch (kind) {
20
+ case ParameterKind_RequiredPositional: return cPositionalParameter;
21
+ case ParameterKind_OptionalPositional: return cOptionalPositionalParameter;
22
+ case ParameterKind_RestPositional: return cRestPositionalParameter;
23
+ case ParameterKind_Post: return cPostParameter;
24
+ case ParameterKind_RequiredKeyword: return cKeywordParameter;
25
+ case ParameterKind_OptionalKeyword: return cOptionalKeywordParameter;
26
+ case ParameterKind_RestKeyword: return cRestKeywordParameter;
27
+ case ParameterKind_Forward: return cForwardParameter;
28
+ case ParameterKind_Block: return cBlockParameter;
29
+ default: rb_raise(rb_eRuntimeError, "Unknown ParameterKind: %d", kind);
30
+ }
31
+ }
32
+
33
+ VALUE rdxi_signatures_to_ruby(SignatureArray *arr) {
34
+ VALUE signatures = rb_ary_new_capa((long)arr->len);
35
+
36
+ for (size_t i = 0; i < arr->len; i++) {
37
+ SignatureEntry sig_entry = arr->items[i];
38
+
39
+ VALUE signature;
40
+ if (sig_entry.parameters_len == 0) {
41
+ signature = rb_class_new_instance(1, &empty_params, cSignature);
42
+ } else {
43
+ VALUE parameters = rb_ary_new_capa((long)sig_entry.parameters_len);
44
+ for (size_t j = 0; j < sig_entry.parameters_len; j++) {
45
+ ParameterEntry param_entry = sig_entry.parameters[j];
46
+
47
+ VALUE param_class = parameter_class_for_kind(param_entry.kind);
48
+ VALUE name_sym = rb_str_intern(rb_utf8_str_new_cstr(param_entry.name));
49
+ VALUE location = rdxi_build_location_value(param_entry.location);
50
+ VALUE param_argv[] = {name_sym, location};
51
+ VALUE param = rb_class_new_instance(2, param_argv, param_class);
52
+
53
+ rb_ary_push(parameters, param);
54
+ }
55
+
56
+ signature = rb_class_new_instance(1, &parameters, cSignature);
57
+ }
58
+
59
+ rb_ary_push(signatures, signature);
60
+ }
61
+
62
+ rdx_definition_signatures_free(arr);
63
+ return signatures;
64
+ }
65
+
66
+ void rdxi_initialize_signature(VALUE mRubydex) {
67
+ cSignature = rb_define_class_under(mRubydex, "Signature", rb_cObject);
68
+
69
+ cParameter = rb_define_class_under(cSignature, "Parameter", rb_cObject);
70
+ cPositionalParameter = rb_define_class_under(cSignature, "PositionalParameter", cParameter);
71
+ cOptionalPositionalParameter = rb_define_class_under(cSignature, "OptionalPositionalParameter", cParameter);
72
+ cRestPositionalParameter = rb_define_class_under(cSignature, "RestPositionalParameter", cParameter);
73
+ cPostParameter = rb_define_class_under(cSignature, "PostParameter", cParameter);
74
+ cKeywordParameter = rb_define_class_under(cSignature, "KeywordParameter", cParameter);
75
+ cOptionalKeywordParameter = rb_define_class_under(cSignature, "OptionalKeywordParameter", cParameter);
76
+ cRestKeywordParameter = rb_define_class_under(cSignature, "RestKeywordParameter", cParameter);
77
+ cForwardParameter = rb_define_class_under(cSignature, "ForwardParameter", cParameter);
78
+ cBlockParameter = rb_define_class_under(cSignature, "BlockParameter", cParameter);
79
+
80
+ empty_params = rb_ary_new();
81
+ OBJ_FREEZE(empty_params);
82
+ rb_gc_register_mark_object(empty_params);
83
+ }
@@ -0,0 +1,23 @@
1
+ #ifndef RUBYDEX_SIGNATURE_H
2
+ #define RUBYDEX_SIGNATURE_H
3
+
4
+ #include "ruby.h"
5
+ #include "rustbindings.h"
6
+
7
+ extern VALUE cSignature;
8
+ extern VALUE cParameter;
9
+ extern VALUE cPositionalParameter;
10
+ extern VALUE cOptionalPositionalParameter;
11
+ extern VALUE cRestPositionalParameter;
12
+ extern VALUE cPostParameter;
13
+ extern VALUE cKeywordParameter;
14
+ extern VALUE cOptionalKeywordParameter;
15
+ extern VALUE cRestKeywordParameter;
16
+ extern VALUE cForwardParameter;
17
+ extern VALUE cBlockParameter;
18
+
19
+ void rdxi_initialize_signature(VALUE mRubydex);
20
+
21
+ VALUE rdxi_signatures_to_ruby(SignatureArray *arr);
22
+
23
+ #endif // RUBYDEX_SIGNATURE_H
Binary file
Binary file
Binary file
Binary file
@@ -1,6 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubydex
4
+ module Visibility
5
+ #: () -> bool
6
+ def public? = visibility == :public
7
+
8
+ #: () -> bool
9
+ def private? = visibility == :private
10
+
11
+ #: () -> bool
12
+ def protected? = visibility == :protected
13
+ end
14
+
4
15
  class Declaration
5
16
  # @abstract
6
17
  #: () -> Enumerable[Reference]
@@ -8,4 +19,24 @@ module Rubydex
8
19
  raise NotImplementedError, "Subclasses must implement #references"
9
20
  end
10
21
  end
22
+
23
+ class Class < Namespace
24
+ include Visibility
25
+ end
26
+
27
+ class Module < Namespace
28
+ include Visibility
29
+ end
30
+
31
+ class Constant < Declaration
32
+ include Visibility
33
+ end
34
+
35
+ class ConstantAlias < Declaration
36
+ include Visibility
37
+ end
38
+
39
+ class Method < Declaration
40
+ include Visibility
41
+ end
11
42
  end
Binary file
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubydex
4
+ class Signature
5
+ class Parameter
6
+ #: Symbol
7
+ attr_reader :name
8
+
9
+ #: Location
10
+ attr_reader :location
11
+
12
+ #: (Symbol, Location) -> void
13
+ def initialize(name, location)
14
+ @name = name
15
+ @location = location
16
+ end
17
+ end
18
+
19
+ class PositionalParameter < Parameter; end
20
+ class OptionalPositionalParameter < Parameter; end
21
+ class RestPositionalParameter < Parameter; end
22
+ class PostParameter < Parameter; end
23
+ class KeywordParameter < Parameter; end
24
+ class OptionalKeywordParameter < Parameter; end
25
+ class RestKeywordParameter < Parameter; end
26
+ class ForwardParameter < Parameter; end
27
+ class BlockParameter < Parameter; end
28
+
29
+ #: Array[Parameter]
30
+ attr_reader :parameters
31
+
32
+ #: (Array[Parameter]) -> void
33
+ def initialize(parameters)
34
+ @parameters = parameters
35
+ end
36
+
37
+ #: () -> [Array[PositionalParameter], Array[OptionalPositionalParameter], RestPositionalParameter?, Array[PostParameter], Array[KeywordParameter], Array[OptionalKeywordParameter], RestKeywordParameter?, ForwardParameter?, BlockParameter?]
38
+ def deconstruct
39
+ positionals = [] #: Array[PositionalParameter]
40
+ optional_positionals = [] #: Array[OptionalPositionalParameter]
41
+ rest_positional = nil #: RestPositionalParameter?
42
+ posts = [] #: Array[PostParameter]
43
+ keywords = [] #: Array[KeywordParameter]
44
+ optional_keywords = [] #: Array[OptionalKeywordParameter]
45
+ rest_keyword = nil #: RestKeywordParameter?
46
+ forward = nil #: ForwardParameter?
47
+ block = nil #: BlockParameter?
48
+
49
+ parameters.each do |param|
50
+ case param
51
+ when PositionalParameter then positionals << param
52
+ when OptionalPositionalParameter then optional_positionals << param
53
+ when RestPositionalParameter then rest_positional = param
54
+ when PostParameter then posts << param
55
+ when KeywordParameter then keywords << param
56
+ when OptionalKeywordParameter then optional_keywords << param
57
+ when RestKeywordParameter then rest_keyword = param
58
+ when ForwardParameter then forward = param
59
+ when BlockParameter then block = param
60
+ end
61
+ end
62
+
63
+ [positionals, optional_positionals, rest_positional, posts, keywords, optional_keywords, rest_keyword, forward, block]
64
+ end
65
+
66
+ DECONSTRUCT_KEYS = [
67
+ :positional_parameters,
68
+ :optional_positional_parameters,
69
+ :rest_positional_parameter,
70
+ :post_parameters,
71
+ :keyword_parameters,
72
+ :optional_keyword_parameters,
73
+ :rest_keyword_parameter,
74
+ :forward_parameter,
75
+ :block_parameter,
76
+ ].freeze #: Array[Symbol]
77
+ private_constant :DECONSTRUCT_KEYS
78
+
79
+ #: (Array[Symbol]?) -> Hash[Symbol, untyped]
80
+ def deconstruct_keys(keys)
81
+ keys = DECONSTRUCT_KEYS if keys.nil?
82
+
83
+ positionals, optional_positionals, rest_positional, posts,
84
+ keywords, optional_keywords, rest_keyword, forward, block = deconstruct
85
+
86
+ result = {} #: Hash[Symbol, untyped]
87
+ keys.each do |key|
88
+ case key
89
+ when :positional_parameters then result[key] = positionals
90
+ when :optional_positional_parameters then result[key] = optional_positionals
91
+ when :rest_positional_parameter then result[key] = rest_positional
92
+ when :post_parameters then result[key] = posts
93
+ when :keyword_parameters then result[key] = keywords
94
+ when :optional_keyword_parameters then result[key] = optional_keywords
95
+ when :rest_keyword_parameter then result[key] = rest_keyword
96
+ when :forward_parameter then result[key] = forward
97
+ when :block_parameter then result[key] = block
98
+ end
99
+ end
100
+ result
101
+ end
102
+
103
+ #: () -> Array[PositionalParameter]
104
+ def positional_parameters = deconstruct[0]
105
+
106
+ #: () -> Array[OptionalPositionalParameter]
107
+ def optional_positional_parameters = deconstruct[1]
108
+
109
+ #: () -> RestPositionalParameter?
110
+ def rest_positional_parameter = deconstruct[2]
111
+
112
+ #: () -> Array[PostParameter]
113
+ def post_parameters = deconstruct[3]
114
+
115
+ #: () -> Array[KeywordParameter]
116
+ def keyword_parameters = deconstruct[4]
117
+
118
+ #: () -> Array[OptionalKeywordParameter]
119
+ def optional_keyword_parameters = deconstruct[5]
120
+
121
+ #: () -> RestKeywordParameter?
122
+ def rest_keyword_parameter = deconstruct[6]
123
+
124
+ #: () -> ForwardParameter?
125
+ def forward_parameter = deconstruct[7]
126
+
127
+ #: () -> BlockParameter?
128
+ def block_parameter = deconstruct[8]
129
+ end
130
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubydex
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.2"
5
5
  end
data/lib/rubydex.rb CHANGED
@@ -22,3 +22,4 @@ require "rubydex/keyword"
22
22
  require "rubydex/keyword_parameter"
23
23
  require "rubydex/graph"
24
24
  require "rubydex/declaration"
25
+ require "rubydex/signature"