rubydex 0.2.0-x86_64-linux → 0.2.1-x86_64-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 +4 -4
- data/ext/rubydex/declaration.c +38 -0
- data/ext/rubydex/graph.c +70 -17
- data/lib/rubydex/3.2/rubydex.so +0 -0
- data/lib/rubydex/3.3/rubydex.so +0 -0
- data/lib/rubydex/3.4/rubydex.so +0 -0
- data/lib/rubydex/4.0/rubydex.so +0 -0
- data/lib/rubydex/declaration.rb +31 -0
- data/lib/rubydex/librubydex_sys.so +0 -0
- data/lib/rubydex/version.rb +1 -1
- data/rbi/rubydex.rbi +41 -11
- data/rust/rubydex/src/diagnostic.rs +1 -0
- data/rust/rubydex/src/indexing/ruby_indexer.rs +2 -5
- data/rust/rubydex/src/indexing/ruby_indexer_tests.rs +14 -7
- data/rust/rubydex/src/model/declaration.rs +48 -0
- data/rust/rubydex/src/model/definitions.rs +18 -9
- data/rust/rubydex/src/model/graph.rs +237 -35
- data/rust/rubydex/src/query.rs +1475 -159
- data/rust/rubydex/src/resolution.rs +173 -61
- data/rust/rubydex/src/resolution_tests.rs +178 -0
- data/rust/rubydex-sys/src/declaration_api.rs +19 -0
- data/rust/rubydex-sys/src/graph_api.rs +89 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af48ce975a55310aaf8f2026be413cad45663642baf60ddda21ddfaf678a0e96
|
|
4
|
+
data.tar.gz: 298d02687b6b96bddf246a83b9d808705d5ebe33ce0fd5a87f230d2d6fa2f6b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e6840ad668950cf5cf8f823f86eeb561de8cd3b60b1bc4d01b7afa390fd473b7268df85d6bba802d270b27a61c5224f7b7c7f8359f56274c829004ee9491843
|
|
7
|
+
data.tar.gz: a64f5c6f3f2f4c1dbed7774ab03216be98545a40892a3dffba8c6bb98376db901065e18fc96d1b7028a1c46fa9c9adde054a19e5a651eff694f044fcf218c18c
|
data/ext/rubydex/declaration.c
CHANGED
|
@@ -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);
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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,
|
|
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);
|
data/lib/rubydex/3.2/rubydex.so
CHANGED
|
Binary file
|
data/lib/rubydex/3.3/rubydex.so
CHANGED
|
Binary file
|
data/lib/rubydex/3.4/rubydex.so
CHANGED
|
Binary file
|
data/lib/rubydex/4.0/rubydex.so
CHANGED
|
Binary file
|
data/lib/rubydex/declaration.rb
CHANGED
|
@@ -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
|
data/lib/rubydex/version.rb
CHANGED
data/rbi/rubydex.rbi
CHANGED
|
@@ -152,6 +152,7 @@ class Rubydex::GlobalVariableDefinition < Rubydex::Definition; end
|
|
|
152
152
|
class Rubydex::InstanceVariableDefinition < Rubydex::Definition; end
|
|
153
153
|
class Rubydex::MethodAliasDefinition < Rubydex::Definition; end
|
|
154
154
|
class Rubydex::MethodDefinition < Rubydex::Definition; end
|
|
155
|
+
|
|
155
156
|
class Rubydex::ModuleDefinition < Rubydex::Definition
|
|
156
157
|
sig { returns(T::Array[Rubydex::Mixin]) }
|
|
157
158
|
def mixins; end
|
|
@@ -317,27 +318,56 @@ class Rubydex::Graph
|
|
|
317
318
|
# Returns completion candidates for an expression context. This includes all keywords, constants, methods, instance
|
|
318
319
|
# variables, class variables and global variables reachable from the current lexical scope and self type.
|
|
319
320
|
#
|
|
320
|
-
# The nesting array represents the lexical scope stack
|
|
321
|
-
#
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
# The nesting array represents the lexical scope stack. The optional `self_receiver` keyword argument overrides the
|
|
322
|
+
# self type independently of the lexical scope (e.g., `"Foo::<Foo>"` for `def Foo.bar`). This distinction is important
|
|
323
|
+
# because constants and class variables are always attached to the lexical scope. Meanwhile, methods and instance
|
|
324
|
+
# variables are attached to the type of `self` and those don't always match.
|
|
325
|
+
sig do
|
|
326
|
+
params(
|
|
327
|
+
nesting: T::Array[String],
|
|
328
|
+
self_receiver: T.nilable(String),
|
|
329
|
+
).returns(T::Array[T.any(Rubydex::Declaration, Rubydex::Keyword)])
|
|
330
|
+
end
|
|
331
|
+
def complete_expression(nesting, self_receiver: nil); end
|
|
324
332
|
|
|
325
333
|
# Returns completion candidates after a namespace access operator (e.g., `Foo::`). This includes all constants and
|
|
326
334
|
# singleton methods for the namespace and its ancestors.
|
|
327
|
-
|
|
328
|
-
|
|
335
|
+
#
|
|
336
|
+
# The optional `self_receiver` kwarg is the caller's runtime self type. It's used to filter visibility-restricted
|
|
337
|
+
# singleton methods (e.g., `private_class_method`). Pass `nil` (the default) for top-level/script scope.
|
|
338
|
+
sig do
|
|
339
|
+
params(
|
|
340
|
+
name: String,
|
|
341
|
+
self_receiver: T.nilable(String),
|
|
342
|
+
).returns(T::Array[Rubydex::Declaration])
|
|
343
|
+
end
|
|
344
|
+
def complete_namespace_access(name, self_receiver: nil); end
|
|
329
345
|
|
|
330
346
|
# Returns completion candidates after a method call operator (e.g., `foo.`). This includes all methods that exist on
|
|
331
347
|
# the type of the receiver and its ancestors.
|
|
332
|
-
|
|
333
|
-
|
|
348
|
+
#
|
|
349
|
+
# The optional `self_receiver` kwarg is the caller's runtime self type. It's used for visibility checks for `private`
|
|
350
|
+
# and `protected` methods. Pass `nil` (the default) for top-level/script scope.
|
|
351
|
+
sig do
|
|
352
|
+
params(
|
|
353
|
+
name: String,
|
|
354
|
+
self_receiver: T.nilable(String),
|
|
355
|
+
).returns(T::Array[Rubydex::Method])
|
|
356
|
+
end
|
|
357
|
+
def complete_method_call(name, self_receiver: nil); end
|
|
334
358
|
|
|
335
359
|
# Returns completion candidates inside a method call's argument list (e.g., `foo.bar(|)`). This includes everything
|
|
336
360
|
# that expression completion provides plus keyword argument names of the method being called.
|
|
337
361
|
#
|
|
338
|
-
#
|
|
339
|
-
sig
|
|
340
|
-
|
|
362
|
+
# See `complete_expression` for the semantics of `nesting` and `self_receiver`.
|
|
363
|
+
sig do
|
|
364
|
+
params(
|
|
365
|
+
name: String,
|
|
366
|
+
nesting: T::Array[String],
|
|
367
|
+
self_receiver: T.nilable(String),
|
|
368
|
+
).returns(T::Array[T.any(Rubydex::Declaration, Rubydex::Keyword, Rubydex::KeywordParameter)])
|
|
369
|
+
end
|
|
370
|
+
def complete_method_argument(name, nesting, self_receiver: nil); end
|
|
341
371
|
|
|
342
372
|
private
|
|
343
373
|
|
|
@@ -1260,11 +1260,8 @@ impl<'a> RubyIndexer<'a> {
|
|
|
1260
1260
|
let str_id = self.local_graph.intern_string(name);
|
|
1261
1261
|
let offset = Offset::from_prism_location(&location);
|
|
1262
1262
|
let definition = Definition::ConstantVisibility(Box::new(ConstantVisibilityDefinition::new(
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
receiver_name_id.map_or(ParentScope::None, ParentScope::Some),
|
|
1266
|
-
self.current_lexical_scope_name_id(),
|
|
1267
|
-
)),
|
|
1263
|
+
receiver_name_id,
|
|
1264
|
+
str_id,
|
|
1268
1265
|
visibility,
|
|
1269
1266
|
self.uri_id,
|
|
1270
1267
|
offset,
|
|
@@ -3271,31 +3271,38 @@ mod visibility_tests {
|
|
|
3271
3271
|
assert_no_local_diagnostics!(&context);
|
|
3272
3272
|
|
|
3273
3273
|
assert_definition_at!(&context, "6:21-6:24", ConstantVisibility, |def| {
|
|
3274
|
-
|
|
3274
|
+
assert_string_eq!(&context, def.target(), "BAR");
|
|
3275
|
+
assert!(def.receiver().is_none());
|
|
3275
3276
|
assert_eq!(def.visibility(), &Visibility::Private);
|
|
3276
3277
|
});
|
|
3277
3278
|
assert_definition_at!(&context, "6:27-6:30", ConstantVisibility, |def| {
|
|
3278
|
-
|
|
3279
|
+
assert_string_eq!(&context, def.target(), "BAZ");
|
|
3280
|
+
assert!(def.receiver().is_none());
|
|
3279
3281
|
assert_eq!(def.visibility(), &Visibility::Private);
|
|
3280
3282
|
});
|
|
3281
3283
|
assert_definition_at!(&context, "7:20-7:25", ConstantVisibility, |def| {
|
|
3282
|
-
|
|
3284
|
+
assert_string_eq!(&context, def.target(), "FOO");
|
|
3285
|
+
assert!(def.receiver().is_none());
|
|
3283
3286
|
assert_eq!(def.visibility(), &Visibility::Private);
|
|
3284
3287
|
});
|
|
3285
3288
|
assert_definition_at!(&context, "13:26-13:29", ConstantVisibility, |def| {
|
|
3286
|
-
|
|
3289
|
+
assert_string_eq!(&context, def.target(), "BAR");
|
|
3290
|
+
assert_name_path_eq!(&context, "Foo", def.receiver().unwrap());
|
|
3287
3291
|
assert_eq!(def.visibility(), &Visibility::Public);
|
|
3288
3292
|
});
|
|
3289
3293
|
assert_definition_at!(&context, "14:25-14:30", ConstantVisibility, |def| {
|
|
3290
|
-
|
|
3294
|
+
assert_string_eq!(&context, def.target(), "BAZ");
|
|
3295
|
+
assert_name_path_eq!(&context, "Foo", def.receiver().unwrap());
|
|
3291
3296
|
assert_eq!(def.visibility(), &Visibility::Public);
|
|
3292
3297
|
});
|
|
3293
3298
|
assert_definition_at!(&context, "17:26-17:29", ConstantVisibility, |def| {
|
|
3294
|
-
|
|
3299
|
+
assert_string_eq!(&context, def.target(), "Qux");
|
|
3300
|
+
assert!(def.receiver().is_none());
|
|
3295
3301
|
assert_eq!(def.visibility(), &Visibility::Private);
|
|
3296
3302
|
});
|
|
3297
3303
|
assert_definition_at!(&context, "20:22-20:25", ConstantVisibility, |def| {
|
|
3298
|
-
|
|
3304
|
+
assert_string_eq!(&context, def.target(), "BAR");
|
|
3305
|
+
assert_name_path_eq!(&context, "Foo", def.receiver().unwrap());
|
|
3299
3306
|
assert_eq!(def.visibility(), &Visibility::Public);
|
|
3300
3307
|
});
|
|
3301
3308
|
}
|
|
@@ -339,6 +339,54 @@ impl Declaration {
|
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
+
#[must_use]
|
|
343
|
+
pub fn as_constant(&self) -> Option<&ConstantDeclaration> {
|
|
344
|
+
match self {
|
|
345
|
+
Declaration::Constant(constant) => Some(constant),
|
|
346
|
+
_ => None,
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
#[must_use]
|
|
351
|
+
pub fn as_constant_alias(&self) -> Option<&ConstantAliasDeclaration> {
|
|
352
|
+
match self {
|
|
353
|
+
Declaration::ConstantAlias(alias) => Some(alias),
|
|
354
|
+
_ => None,
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
#[must_use]
|
|
359
|
+
pub fn as_method(&self) -> Option<&MethodDeclaration> {
|
|
360
|
+
match self {
|
|
361
|
+
Declaration::Method(method) => Some(method),
|
|
362
|
+
_ => None,
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
#[must_use]
|
|
367
|
+
pub fn as_global_variable(&self) -> Option<&GlobalVariableDeclaration> {
|
|
368
|
+
match self {
|
|
369
|
+
Declaration::GlobalVariable(global) => Some(global),
|
|
370
|
+
_ => None,
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
#[must_use]
|
|
375
|
+
pub fn as_class_variable(&self) -> Option<&ClassVariableDeclaration> {
|
|
376
|
+
match self {
|
|
377
|
+
Declaration::ClassVariable(cvar) => Some(cvar),
|
|
378
|
+
_ => None,
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
#[must_use]
|
|
383
|
+
pub fn as_instance_variable(&self) -> Option<&InstanceVariableDeclaration> {
|
|
384
|
+
match self {
|
|
385
|
+
Declaration::InstanceVariable(ivar) => Some(ivar),
|
|
386
|
+
_ => None,
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
342
390
|
#[must_use]
|
|
343
391
|
pub fn definitions(&self) -> &[DefinitionId] {
|
|
344
392
|
all_declarations!(self, it => &it.definition_ids)
|
|
@@ -155,8 +155,8 @@ impl Definition {
|
|
|
155
155
|
Definition::Module(d) => Some(d.name_id()),
|
|
156
156
|
Definition::Constant(d) => Some(d.name_id()),
|
|
157
157
|
Definition::ConstantAlias(d) => Some(d.name_id()),
|
|
158
|
-
Definition::ConstantVisibility(
|
|
159
|
-
Definition::MethodVisibility(_)
|
|
158
|
+
Definition::ConstantVisibility(_)
|
|
159
|
+
| Definition::MethodVisibility(_)
|
|
160
160
|
| Definition::GlobalVariable(_)
|
|
161
161
|
| Definition::InstanceVariable(_)
|
|
162
162
|
| Definition::ClassVariable(_)
|
|
@@ -711,7 +711,8 @@ impl ConstantAliasDefinition {
|
|
|
711
711
|
|
|
712
712
|
#[derive(Debug)]
|
|
713
713
|
pub struct ConstantVisibilityDefinition {
|
|
714
|
-
|
|
714
|
+
receiver: Option<NameId>,
|
|
715
|
+
target: StringId,
|
|
715
716
|
visibility: Visibility,
|
|
716
717
|
uri_id: UriId,
|
|
717
718
|
offset: Offset,
|
|
@@ -722,8 +723,10 @@ pub struct ConstantVisibilityDefinition {
|
|
|
722
723
|
|
|
723
724
|
impl ConstantVisibilityDefinition {
|
|
724
725
|
#[must_use]
|
|
726
|
+
#[allow(clippy::too_many_arguments)]
|
|
725
727
|
pub const fn new(
|
|
726
|
-
|
|
728
|
+
receiver: Option<NameId>,
|
|
729
|
+
target: StringId,
|
|
727
730
|
visibility: Visibility,
|
|
728
731
|
uri_id: UriId,
|
|
729
732
|
offset: Offset,
|
|
@@ -732,7 +735,8 @@ impl ConstantVisibilityDefinition {
|
|
|
732
735
|
lexical_nesting_id: Option<DefinitionId>,
|
|
733
736
|
) -> Self {
|
|
734
737
|
Self {
|
|
735
|
-
|
|
738
|
+
receiver,
|
|
739
|
+
target,
|
|
736
740
|
visibility,
|
|
737
741
|
uri_id,
|
|
738
742
|
offset,
|
|
@@ -744,12 +748,17 @@ impl ConstantVisibilityDefinition {
|
|
|
744
748
|
|
|
745
749
|
#[must_use]
|
|
746
750
|
pub fn id(&self) -> DefinitionId {
|
|
747
|
-
DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.
|
|
751
|
+
DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.target))
|
|
748
752
|
}
|
|
749
753
|
|
|
750
754
|
#[must_use]
|
|
751
|
-
pub fn
|
|
752
|
-
&self.
|
|
755
|
+
pub fn receiver(&self) -> &Option<NameId> {
|
|
756
|
+
&self.receiver
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
#[must_use]
|
|
760
|
+
pub fn target(&self) -> &StringId {
|
|
761
|
+
&self.target
|
|
753
762
|
}
|
|
754
763
|
|
|
755
764
|
#[must_use]
|
|
@@ -782,7 +791,7 @@ impl ConstantVisibilityDefinition {
|
|
|
782
791
|
&self.flags
|
|
783
792
|
}
|
|
784
793
|
}
|
|
785
|
-
assert_mem_size!(ConstantVisibilityDefinition,
|
|
794
|
+
assert_mem_size!(ConstantVisibilityDefinition, 64);
|
|
786
795
|
|
|
787
796
|
#[derive(Debug)]
|
|
788
797
|
pub struct MethodVisibilityDefinition {
|