repl_type_completor 0.1.5 → 0.1.7

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: f9fd32939443428590da667d339d7bb234b7831f259d4d5fc6f9aa4c89e30265
4
- data.tar.gz: 60893ba2d927272dce119ee977d6c8d3c472af808c80b482f3ee8e420532749a
3
+ metadata.gz: 2e852d359a7203c7d7b6b001dc043cb749427339d7024bc13666baff16908076
4
+ data.tar.gz: c9f790626f9cf102b7571c7eb9612da3924b1e8f9d360bc9cd3881f48dc602a5
5
5
  SHA512:
6
- metadata.gz: 1012c8e5c03bf2f76d267454c17f95e816d986a82bfc91a8f1ea37a2a562bc28d5c9df69e2ab143ada813a8231ec309520d86a168680a31f13be0caf96cf452b
7
- data.tar.gz: b008d3bf44a71071d3cacd4ee163abb31ccadced36020733dbf562fa603e914855ef215a1820b3d07afbb1ac89fdd107f2aadc20c5a474722cfa3b439dc9038a
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.operator, [right], nil, nil, scope, name_match: false
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.operator, [right], nil, nil, scope, name_match: false
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.operator, [right], nil, nil, scope, name_match: false
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.operator, [right], nil, nil, scope, name_match: false
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.child.name.to_s, value, scope
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) = evaluate_if_unless(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.consequent ? evaluate(node.consequent, _1) : Types::NIL }
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
- case node.reference
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.consequent # begin; rescue A; rescue B; end
591
+ if node.subsequent # begin; rescue A; rescue B; end
591
592
  types = scope.run_branches(
592
593
  run_rescue,
593
- -> { evaluate node.consequent, _1 }
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.consequent
709
- branches << ->(s) { evaluate node.consequent, s }
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.consequent
723
- branches << ->(s) { evaluate node.consequent, s }
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.child.name.to_s, value, scope
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReplTypeCompletor
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.7"
5
5
  end
@@ -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::ConstantReadNode, Prism::ConstantTargetNode
104
+ when Prism::ConstantPathNode, Prism::ConstantPathTargetNode
105
105
  name = target_node.name.to_s
106
- if parents.last.is_a? Prism::ConstantPathNode
107
- path_node = parents.last
108
- if path_node.parent # A::B
109
- receiver, scope = calculate_type_scope.call(path_node.parent)
110
- [:const, name, receiver, scope]
111
- else # ::A
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.5
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-04-29 00:00:00.000000000 Z
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: 0.19.0
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: 0.19.0
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rbs
29
29
  requirement: !ruby/object:Gem::Requirement