repl_type_completor 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/repl_type_completor/type_analyzer.rb +23 -30
- data/lib/repl_type_completor/types.rb +2 -2
- data/lib/repl_type_completor/version.rb +1 -1
- data/lib/repl_type_completor.rb +1 -13
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e852d359a7203c7d7b6b001dc043cb749427339d7024bc13666baff16908076
|
4
|
+
data.tar.gz: c9f790626f9cf102b7571c7eb9612da3924b1e8f9d360bc9cd3881f48dc602a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a60c14cde97df73039ea4be3572d7e53fbff6848229ec2f127ab1537d46ec2fecdcaf360bcb63460bb3e44237f08f4d962c0677b30f9aafdb575126b33efd84
|
7
|
+
data.tar.gz: 64a1113147f6d0a3a90958a2f9a106cd9d04a8678ee10103d54000b7c7b754584feb63382fbaf77534955ade2a8400ad19d76f696ad7d7faa9bb18cd0789e89c
|
@@ -342,14 +342,14 @@ module ReplTypeCompletor
|
|
342
342
|
Types::UnionType[left, right]
|
343
343
|
else
|
344
344
|
right = evaluate node.value, scope
|
345
|
-
method_call left, node.
|
345
|
+
method_call left, node.binary_operator, [right], nil, nil, scope, name_match: false
|
346
346
|
end
|
347
347
|
end
|
348
348
|
|
349
349
|
def evaluate_variable_operator_write(node, scope)
|
350
350
|
left = scope[node.name.to_s] || Types::OBJECT
|
351
351
|
right = evaluate node.value, scope
|
352
|
-
scope[node.name.to_s] = method_call left, node.
|
352
|
+
scope[node.name.to_s] = method_call left, node.binary_operator, [right], nil, nil, scope, name_match: false
|
353
353
|
end
|
354
354
|
alias evaluate_global_variable_operator_write_node evaluate_variable_operator_write
|
355
355
|
alias evaluate_local_variable_operator_write_node evaluate_variable_operator_write
|
@@ -378,7 +378,7 @@ module ReplTypeCompletor
|
|
378
378
|
def evaluate_constant_operator_write_node(node, scope)
|
379
379
|
left = scope[node.name.to_s] || Types::OBJECT
|
380
380
|
right = evaluate node.value, scope
|
381
|
-
scope[node.name.to_s] = method_call left, node.
|
381
|
+
scope[node.name.to_s] = method_call left, node.binary_operator, [right], nil, nil, scope, name_match: false
|
382
382
|
end
|
383
383
|
|
384
384
|
def evaluate_constant_and_write_node(node, scope)
|
@@ -395,7 +395,7 @@ module ReplTypeCompletor
|
|
395
395
|
def evaluate_constant_path_operator_write_node(node, scope)
|
396
396
|
left, receiver, _parent_module, name = evaluate_constant_node_info node.target, scope
|
397
397
|
right = evaluate node.value, scope
|
398
|
-
value = method_call left, node.
|
398
|
+
value = method_call left, node.binary_operator, [right], nil, nil, scope, name_match: false
|
399
399
|
const_path_write receiver, name, value, scope
|
400
400
|
value
|
401
401
|
end
|
@@ -419,8 +419,7 @@ module ReplTypeCompletor
|
|
419
419
|
def evaluate_constant_path_write_node(node, scope)
|
420
420
|
receiver = evaluate node.target.parent, scope if node.target.parent
|
421
421
|
value = evaluate node.value, scope
|
422
|
-
|
423
|
-
const_path_write receiver, name, value, scope
|
422
|
+
const_path_write receiver, node.target.name.to_s, value, scope
|
424
423
|
value
|
425
424
|
end
|
426
425
|
|
@@ -467,13 +466,19 @@ module ReplTypeCompletor
|
|
467
466
|
value.is_a?(Array) ? Types.array_of(*value) : value
|
468
467
|
end
|
469
468
|
|
470
|
-
def evaluate_if_node(node, scope)
|
471
|
-
def evaluate_unless_node(node, scope) = evaluate_if_unless(node, scope)
|
472
|
-
def evaluate_if_unless(node, scope)
|
469
|
+
def evaluate_if_node(node, scope)
|
473
470
|
evaluate node.predicate, scope
|
474
471
|
Types::UnionType[*scope.run_branches(
|
475
472
|
-> { node.statements ? evaluate(node.statements, _1) : Types::NIL },
|
476
|
-
-> { node.
|
473
|
+
-> { node.subsequent ? evaluate(node.subsequent, _1) : Types::NIL }
|
474
|
+
)]
|
475
|
+
end
|
476
|
+
|
477
|
+
def evaluate_unless_node(node, scope)
|
478
|
+
evaluate node.predicate, scope
|
479
|
+
Types::UnionType[*scope.run_branches(
|
480
|
+
-> { node.statements ? evaluate(node.statements, _1) : Types::NIL },
|
481
|
+
-> { node.else_clause ? evaluate(node.else_clause, _1) : Types::NIL }
|
477
482
|
)]
|
478
483
|
end
|
479
484
|
|
@@ -583,10 +588,10 @@ module ReplTypeCompletor
|
|
583
588
|
end
|
584
589
|
node.statements ? evaluate(node.statements, s) : Types::NIL
|
585
590
|
end
|
586
|
-
if node.
|
591
|
+
if node.subsequent # begin; rescue A; rescue B; end
|
587
592
|
types = scope.run_branches(
|
588
593
|
run_rescue,
|
589
|
-
-> { evaluate node.
|
594
|
+
-> { evaluate node.subsequent, _1 }
|
590
595
|
)
|
591
596
|
Types::UnionType[*types]
|
592
597
|
else
|
@@ -701,8 +706,8 @@ module ReplTypeCompletor
|
|
701
706
|
branches = node.conditions.map do |condition|
|
702
707
|
->(s) { evaluate_case_when_condition condition, s }
|
703
708
|
end
|
704
|
-
if node.
|
705
|
-
branches << ->(s) { evaluate node.
|
709
|
+
if node.else_clause
|
710
|
+
branches << ->(s) { evaluate node.else_clause, s }
|
706
711
|
else
|
707
712
|
branches << ->(_s) { Types::NIL }
|
708
713
|
end
|
@@ -715,8 +720,8 @@ module ReplTypeCompletor
|
|
715
720
|
branches = node.conditions.map do |condition|
|
716
721
|
->(s) { evaluate_case_in_condition target, condition, s }
|
717
722
|
end
|
718
|
-
if node.
|
719
|
-
branches << ->(s) { evaluate node.
|
723
|
+
if node.else_clause
|
724
|
+
branches << ->(s) { evaluate node.else_clause, s }
|
720
725
|
end
|
721
726
|
Types::UnionType[*scope.run_branches(*branches)]
|
722
727
|
end
|
@@ -839,16 +844,6 @@ module ReplTypeCompletor
|
|
839
844
|
[args_types, kwargs_types, block_sym_node, !!block_arg]
|
840
845
|
end
|
841
846
|
|
842
|
-
def const_path_name(node)
|
843
|
-
if node.respond_to?(:name)
|
844
|
-
# ConstantPathNode#name ConstantPathTargetNode#name is added in Prism 0.28.0
|
845
|
-
node.name.to_s
|
846
|
-
else
|
847
|
-
# ConstantPathNode#child ConstantPathTargetNode#child is deprecated in Prism 0.28.0
|
848
|
-
node.child.name.to_s
|
849
|
-
end
|
850
|
-
end
|
851
|
-
|
852
847
|
def const_path_write(receiver, name, value, scope)
|
853
848
|
if receiver # receiver::A = value
|
854
849
|
singleton_type = receiver.types.find { _1.is_a? Types::SingletonType }
|
@@ -875,9 +870,9 @@ module ReplTypeCompletor
|
|
875
870
|
end
|
876
871
|
|
877
872
|
def evaluate_constant_node_info(node, scope)
|
873
|
+
name = node.name.to_s
|
878
874
|
case node
|
879
875
|
when Prism::ConstantPathNode
|
880
|
-
name = const_path_name(node)
|
881
876
|
if node.parent
|
882
877
|
receiver = evaluate node.parent, scope
|
883
878
|
if receiver.is_a? Types::SingletonType
|
@@ -893,7 +888,6 @@ module ReplTypeCompletor
|
|
893
888
|
type = Types::NIL
|
894
889
|
end
|
895
890
|
when Prism::ConstantReadNode
|
896
|
-
name = node.name.to_s
|
897
891
|
type = scope[name]
|
898
892
|
end
|
899
893
|
@dig_targets.resolve type, scope if @dig_targets.target? node
|
@@ -1048,8 +1042,7 @@ module ReplTypeCompletor
|
|
1048
1042
|
scope[node.name.to_s] = value
|
1049
1043
|
when Prism::ConstantPathTargetNode
|
1050
1044
|
receiver = evaluated_receivers&.[](node.parent) || evaluate(node.parent, scope) if node.parent
|
1051
|
-
name
|
1052
|
-
const_path_write receiver, name, value, scope
|
1045
|
+
const_path_write receiver, node.name.to_s, value, scope
|
1053
1046
|
end
|
1054
1047
|
end
|
1055
1048
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rbs'
|
4
|
+
require 'rbs/cli'
|
3
5
|
require_relative 'methods'
|
4
6
|
|
5
7
|
module ReplTypeCompletor
|
@@ -22,8 +24,6 @@ module ReplTypeCompletor
|
|
22
24
|
|
23
25
|
def self.load_rbs_builder
|
24
26
|
@load_started = true
|
25
|
-
require 'rbs'
|
26
|
-
require 'rbs/cli'
|
27
27
|
loader = RBS::CLI::LibraryOptions.new.loader
|
28
28
|
loader.add path: Pathname('sig')
|
29
29
|
@rbs_builder = RBS::DefinitionBuilder.new env: RBS::Environment.from_loader(loader).resolve_type_names
|
data/lib/repl_type_completor.rb
CHANGED
@@ -111,19 +111,7 @@ module ReplTypeCompletor
|
|
111
111
|
[:const, name, Types::SingletonType.new(Object), scope]
|
112
112
|
end
|
113
113
|
when Prism::ConstantReadNode, Prism::ConstantTargetNode
|
114
|
-
|
115
|
-
if parents.last.is_a? Prism::ConstantPathNode
|
116
|
-
path_node = parents.last
|
117
|
-
if path_node.parent # A::B
|
118
|
-
receiver, scope = calculate_type_scope.call(path_node.parent)
|
119
|
-
[:const, name, receiver, scope]
|
120
|
-
else # ::A
|
121
|
-
scope = calculate_scope.call
|
122
|
-
[:const, name, Types::SingletonType.new(Object), scope]
|
123
|
-
end
|
124
|
-
else
|
125
|
-
[:const, name, nil, calculate_scope.call]
|
126
|
-
end
|
114
|
+
[:const, target_node.name.to_s, nil, calculate_scope.call]
|
127
115
|
when Prism::GlobalVariableReadNode, Prism::GlobalVariableTargetNode
|
128
116
|
[:gvar, target_node.name.to_s, calculate_scope.call]
|
129
117
|
when Prism::InstanceVariableReadNode, Prism::InstanceVariableTargetNode
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repl_type_completor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tompng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prism
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rbs
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|