repl_type_completor 0.1.8 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96985b2dccd9d5437190f365bb6b367a4dd830cbf35c9542825b340f4d833f70
4
- data.tar.gz: 53d2a4f5ef5d01b2f1626d978a385bc74d44472ff69f04fc9975b2669226a775
3
+ metadata.gz: 22c32aa7e27069f8002c1fe8080bb31c8470760c6c780ba8b566252389dc326d
4
+ data.tar.gz: 296c548b10082570baadd90d3c94323f91373a6f0edbde307d01228aac7d83e0
5
5
  SHA512:
6
- metadata.gz: 61535de8984acd5d7bc82b0c93e41dac60b5e43dcf4606666f0c7df491e685c39a983cf5dfac80e368ce20e77e2211242db9e172596dfa1111f67fb9a17bdb47
7
- data.tar.gz: 54c7e6900a693254db6e2d462a9b14f0cef5e514581227c2c39b1d13841fea88591f4504037b02edfe6aa1971d3ebdb9e678d735a277d98cebb6df7d372f00fb
6
+ metadata.gz: 3494ca3dfd41ac33f784e35384299a502703e503fc94732a7572cf2c4418d7754b53dfb2be49588aca33eab595dc3ed181686b4cfc32da0a36c6523aa82183c9
7
+ data.tar.gz: 4beada48ab3e6d67c7543cf9a3e7797792fef8548cf4a8637024d72b865dcbb50ace5fe460ff8e504dae73e308116aefa523fdcbf4f161ed534060fa9c700e59
@@ -139,29 +139,37 @@ module ReplTypeCompletor
139
139
  type = type.types.find { _1.all_methods.include? name.to_sym }
140
140
  case type
141
141
  when Types::SingletonType
142
- "#{Types.class_name_of(type.module_or_class)}.#{name}"
142
+ "#{doc_class_module_name(type.module_or_class)}.#{name}"
143
143
  when Types::InstanceType
144
- "#{Types.class_name_of(type.klass)}##{name}"
144
+ "#{doc_class_module_name(type.klass)}##{name}"
145
145
  end
146
146
  end
147
147
 
148
148
  def call_or_const_doc(type, name)
149
149
  if name =~ /\A[A-Z]/
150
150
  type = type.types.grep(Types::SingletonType).find { _1.module_or_class.const_defined?(name) }
151
- type.module_or_class == Object ? name : "#{Types.class_name_of(type.module_or_class)}::#{name}" if type
151
+ type.module_or_class == Object ? name : "#{doc_class_module_name(type.module_or_class)}::#{name}" if type
152
152
  else
153
153
  method_doc(type, name)
154
154
  end
155
155
  end
156
156
 
157
+ def doc_class_module_name(module_or_class)
158
+ if Class === module_or_class
159
+ Types.class_name_of(module_or_class)
160
+ else
161
+ Methods::MODULE_NAME_METHOD.bind_call(module_or_class) || 'Module'
162
+ end
163
+ end
164
+
157
165
  def value_doc(type)
158
166
  return unless type
159
167
  type.types.each do |t|
160
168
  case t
161
169
  when Types::SingletonType
162
- return Types.class_name_of(t.module_or_class)
170
+ return doc_class_module_name(t.module_or_class)
163
171
  when Types::InstanceType
164
- return Types.class_name_of(t.klass)
172
+ return doc_class_module_name(t.klass)
165
173
  end
166
174
  end
167
175
  nil
@@ -9,13 +9,13 @@ module ReplTypeCompletor
9
9
  class TypeAnalyzer
10
10
  class DigTarget
11
11
  def initialize(parents, receiver, &block)
12
- @dig_ids = parents.to_h { [_1.__id__, true] }
13
- @target_id = receiver.__id__
12
+ @dig_nodes = parents.to_h { [_1, true] }.compare_by_identity
13
+ @target = receiver
14
14
  @block = block
15
15
  end
16
16
 
17
- def dig?(node) = @dig_ids[node.__id__]
18
- def target?(node) = @target_id == node.__id__
17
+ def dig?(node) = @dig_nodes[node]
18
+ def target?(node) = @target.equal?(node)
19
19
  def resolve(type, scope)
20
20
  @block.call type, scope
21
21
  end
@@ -259,6 +259,9 @@ module ReplTypeCompletor
259
259
  call_block_proc = ->(block_args, block_self_type) do
260
260
  scope.conditional do |s|
261
261
  params_table = node.block.locals.to_h { [_1.to_s, Types::NIL] }
262
+ if node.block.parameters.is_a?(Prism::ItParametersNode)
263
+ params_table['_1'] = block_args.first || Types::NIL
264
+ end
262
265
  table = { **params_table, Scope::BREAK_RESULT => nil, Scope::NEXT_RESULT => nil }
263
266
  block_scope = Scope.new s, table, self_type: block_self_type, trace_ivar: !block_self_type
264
267
  # TODO kwargs
@@ -266,9 +269,9 @@ module ReplTypeCompletor
266
269
  when Prism::NumberedParametersNode
267
270
  assign_numbered_parameters node.block.parameters.maximum, block_scope, block_args, {}
268
271
  when Prism::BlockParametersNode
269
- assign_parameters node.block.parameters.parameters, block_scope, block_args, {}
270
- when Prism::ItParametersNode
271
- scope['_1'] = block_args.first || Types::NIL
272
+ if node.block.parameters.parameters
273
+ assign_parameters node.block.parameters.parameters, block_scope, block_args, {}
274
+ end
272
275
  end
273
276
  result = node.block.body ? evaluate(node.block.body, block_scope) : Types::NIL
274
277
  block_scope.merge_jumps
@@ -447,6 +450,10 @@ module ReplTypeCompletor
447
450
  Types::PROC
448
451
  end
449
452
 
453
+ def evaluate_shareable_constant_node(node, scope)
454
+ evaluate(node.write, scope)
455
+ end
456
+
450
457
  def evaluate_reference_write(node, scope)
451
458
  scope[node.name.to_s] = evaluate node.value, scope
452
459
  end
@@ -817,7 +824,7 @@ module ReplTypeCompletor
817
824
  def evaluate_call_node_arguments(call_node, scope)
818
825
  # call_node.arguments is Prism::ArgumentsNode
819
826
  arguments = call_node.arguments&.arguments&.dup || []
820
- block_arg = call_node.block.expression if call_node.block.is_a?(Prism::BlockArgumentNode)
827
+ block_arg = call_node.block.expression if call_node.respond_to?(:block) && call_node.block.is_a?(Prism::BlockArgumentNode)
821
828
  kwargs = arguments.pop.elements if arguments.last.is_a?(Prism::KeywordHashNode)
822
829
  args_types = arguments.map do |arg|
823
830
  case arg
@@ -1093,7 +1100,6 @@ module ReplTypeCompletor
1093
1100
  end
1094
1101
  end
1095
1102
  end
1096
- evaluate node.block.expression, scope if node.block&.expression
1097
1103
  receiver
1098
1104
  when Prism::SplatNode
1099
1105
  evaluate_multi_write_receiver node.expression, scope, evaluated_receivers if node.expression
@@ -53,15 +53,32 @@ module ReplTypeCompletor
53
53
  end
54
54
 
55
55
  def self.class_name_of(klass)
56
- klass = klass.superclass if klass.singleton_class?
57
- Methods::MODULE_NAME_METHOD.bind_call klass
56
+ while true
57
+ name = Methods::MODULE_NAME_METHOD.bind_call klass
58
+ return name if name
59
+
60
+ klass = klass.superclass
61
+ end
62
+ end
63
+
64
+ if RBS::TypeName.respond_to?(:parse) # RBS >= 3.8.0
65
+ def self.rbs_absolute_type_name(name)
66
+ RBS::TypeName.parse(name).absolute!
67
+ end
68
+ else
69
+ def self.rbs_absolute_type_name(name)
70
+ # Deprecated in RBS 3.8.0
71
+ RBS::TypeName(name).absolute!
72
+ end
58
73
  end
59
74
 
60
75
  def self.rbs_search_method(klass, method_name, singleton)
76
+ return unless rbs_builder
77
+
61
78
  klass.ancestors.each do |ancestor|
62
- name = class_name_of ancestor
63
- next unless name && rbs_builder
64
- type_name = RBS::TypeName(name).absolute!
79
+ next unless (name = Methods::MODULE_NAME_METHOD.bind_call(ancestor))
80
+
81
+ type_name = rbs_absolute_type_name(name)
65
82
  definition = (singleton ? rbs_builder.build_singleton(type_name) : rbs_builder.build_instance(type_name)) rescue nil
66
83
  method = definition.methods[method_name] if definition
67
84
  return method if method
@@ -208,10 +225,10 @@ module ReplTypeCompletor
208
225
  def nillable?() = (@klass == NilClass)
209
226
  def nonnillable() = self
210
227
  def rbs_methods
211
- name = Types.class_name_of(@klass)
212
- return {} unless name && Types.rbs_builder
228
+ return {} unless Types.rbs_builder
213
229
 
214
- type_name = RBS::TypeName(name).absolute!
230
+ name = Types.class_name_of(@klass)
231
+ type_name = Types.rbs_absolute_type_name(name)
215
232
  Types.rbs_builder.build_instance(type_name).methods rescue {}
216
233
  end
217
234
  def inspect
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReplTypeCompletor
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.10"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repl_type_completor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - tompng
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-12-12 00:00:00.000000000 Z
10
+ date: 2025-01-21 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: prism
@@ -71,7 +70,6 @@ metadata:
71
70
  homepage_uri: https://github.com/ruby/repl_type_completor
72
71
  source_code_uri: https://github.com/ruby/repl_type_completor
73
72
  documentation_uri: https://github.com/ruby/repl_type_completor
74
- post_install_message:
75
73
  rdoc_options: []
76
74
  require_paths:
77
75
  - lib
@@ -86,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
84
  - !ruby/object:Gem::Version
87
85
  version: '0'
88
86
  requirements: []
89
- rubygems_version: 3.5.9
90
- signing_key:
87
+ rubygems_version: 3.6.2
91
88
  specification_version: 4
92
89
  summary: Type based completion for REPL.
93
90
  test_files: []