repl_type_completor 0.1.5 → 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 +24 -24
- data/lib/repl_type_completor/types.rb +2 -2
- data/lib/repl_type_completor/version.rb +1 -1
- data/lib/repl_type_completor.rb +9 -12
- 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,7 +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
|
-
const_path_write receiver, node.target.
|
422
|
+
const_path_write receiver, node.target.name.to_s, value, scope
|
423
423
|
value
|
424
424
|
end
|
425
425
|
|
@@ -466,13 +466,19 @@ module ReplTypeCompletor
|
|
466
466
|
value.is_a?(Array) ? Types.array_of(*value) : value
|
467
467
|
end
|
468
468
|
|
469
|
-
def evaluate_if_node(node, scope)
|
470
|
-
def evaluate_unless_node(node, scope) = evaluate_if_unless(node, scope)
|
471
|
-
def evaluate_if_unless(node, scope)
|
469
|
+
def evaluate_if_node(node, scope)
|
472
470
|
evaluate node.predicate, scope
|
473
471
|
Types::UnionType[*scope.run_branches(
|
474
472
|
-> { node.statements ? evaluate(node.statements, _1) : Types::NIL },
|
475
|
-
-> { 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 }
|
476
482
|
)]
|
477
483
|
end
|
478
484
|
|
@@ -578,19 +584,14 @@ module ReplTypeCompletor
|
|
578
584
|
end
|
579
585
|
error_types << Types::InstanceType.new(StandardError) if error_types.empty?
|
580
586
|
error_type = Types::UnionType[*error_types]
|
581
|
-
|
582
|
-
when Prism::LocalVariableTargetNode, Prism::InstanceVariableTargetNode, Prism::ClassVariableTargetNode, Prism::GlobalVariableTargetNode, Prism::ConstantTargetNode
|
583
|
-
s[node.reference.name.to_s] = error_type
|
584
|
-
when Prism::CallTargetNode, Prism::IndexTargetNode
|
585
|
-
evaluate_multi_write_receiver node.reference, s, nil
|
586
|
-
end
|
587
|
+
evaluate_write node.reference, error_type, s, nil
|
587
588
|
end
|
588
589
|
node.statements ? evaluate(node.statements, s) : Types::NIL
|
589
590
|
end
|
590
|
-
if node.
|
591
|
+
if node.subsequent # begin; rescue A; rescue B; end
|
591
592
|
types = scope.run_branches(
|
592
593
|
run_rescue,
|
593
|
-
-> { evaluate node.
|
594
|
+
-> { evaluate node.subsequent, _1 }
|
594
595
|
)
|
595
596
|
Types::UnionType[*types]
|
596
597
|
else
|
@@ -705,8 +706,8 @@ module ReplTypeCompletor
|
|
705
706
|
branches = node.conditions.map do |condition|
|
706
707
|
->(s) { evaluate_case_when_condition condition, s }
|
707
708
|
end
|
708
|
-
if node.
|
709
|
-
branches << ->(s) { evaluate node.
|
709
|
+
if node.else_clause
|
710
|
+
branches << ->(s) { evaluate node.else_clause, s }
|
710
711
|
else
|
711
712
|
branches << ->(_s) { Types::NIL }
|
712
713
|
end
|
@@ -719,8 +720,8 @@ module ReplTypeCompletor
|
|
719
720
|
branches = node.conditions.map do |condition|
|
720
721
|
->(s) { evaluate_case_in_condition target, condition, s }
|
721
722
|
end
|
722
|
-
if node.
|
723
|
-
branches << ->(s) { evaluate node.
|
723
|
+
if node.else_clause
|
724
|
+
branches << ->(s) { evaluate node.else_clause, s }
|
724
725
|
end
|
725
726
|
Types::UnionType[*scope.run_branches(*branches)]
|
726
727
|
end
|
@@ -869,9 +870,9 @@ module ReplTypeCompletor
|
|
869
870
|
end
|
870
871
|
|
871
872
|
def evaluate_constant_node_info(node, scope)
|
873
|
+
name = node.name.to_s
|
872
874
|
case node
|
873
875
|
when Prism::ConstantPathNode
|
874
|
-
name = node.child.name.to_s
|
875
876
|
if node.parent
|
876
877
|
receiver = evaluate node.parent, scope
|
877
878
|
if receiver.is_a? Types::SingletonType
|
@@ -887,7 +888,6 @@ module ReplTypeCompletor
|
|
887
888
|
type = Types::NIL
|
888
889
|
end
|
889
890
|
when Prism::ConstantReadNode
|
890
|
-
name = node.name.to_s
|
891
891
|
type = scope[name]
|
892
892
|
end
|
893
893
|
@dig_targets.resolve type, scope if @dig_targets.target? node
|
@@ -1042,7 +1042,7 @@ module ReplTypeCompletor
|
|
1042
1042
|
scope[node.name.to_s] = value
|
1043
1043
|
when Prism::ConstantPathTargetNode
|
1044
1044
|
receiver = evaluated_receivers&.[](node.parent) || evaluate(node.parent, scope) if node.parent
|
1045
|
-
const_path_write receiver, node.
|
1045
|
+
const_path_write receiver, node.name.to_s, value, scope
|
1046
1046
|
end
|
1047
1047
|
end
|
1048
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
@@ -101,20 +101,17 @@ module ReplTypeCompletor
|
|
101
101
|
[op == '::' ? :call_or_const : :call, name, receiver_type, self_call]
|
102
102
|
when Prism::LocalVariableReadNode, Prism::LocalVariableTargetNode
|
103
103
|
[:lvar_or_method, target_node.name.to_s, calculate_scope.call]
|
104
|
-
when Prism::
|
104
|
+
when Prism::ConstantPathNode, Prism::ConstantPathTargetNode
|
105
105
|
name = target_node.name.to_s
|
106
|
-
if
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
scope = calculate_scope.call
|
113
|
-
[:const, name, Types::SingletonType.new(Object), scope]
|
114
|
-
end
|
115
|
-
else
|
116
|
-
[:const, name, nil, calculate_scope.call]
|
106
|
+
if target_node.parent # A::B
|
107
|
+
receiver, scope = calculate_type_scope.call(target_node.parent)
|
108
|
+
[:const, name, receiver, scope]
|
109
|
+
else # ::A
|
110
|
+
scope = calculate_scope.call
|
111
|
+
[:const, name, Types::SingletonType.new(Object), scope]
|
117
112
|
end
|
113
|
+
when Prism::ConstantReadNode, Prism::ConstantTargetNode
|
114
|
+
[:const, target_node.name.to_s, nil, calculate_scope.call]
|
118
115
|
when Prism::GlobalVariableReadNode, Prism::GlobalVariableTargetNode
|
119
116
|
[:gvar, target_node.name.to_s, calculate_scope.call]
|
120
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
|