repl_type_completor 0.1.11 → 0.1.12

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: 45c80e0c90081af7992d51765854f270adbaec795050775ae778560737db52b2
4
- data.tar.gz: 9b4745ab99625ebfd3b6c1ecb526ff6e5186ef9320873b55cc4f6d88103f25ec
3
+ metadata.gz: e17428782dfde53e8b592d0fb16957c02ec537bee5122a624e3a99bbfc663e5a
4
+ data.tar.gz: ebebeec739da4ae0e46ac690f3e238cff6759a3cedebccdf9e180e28ee6c51a8
5
5
  SHA512:
6
- metadata.gz: c1a11765f19a07a3cf1a387448e2a57f8d0a087991a9cdae946eebdb6000552e4b7ed7a172a1d7dc65ba273def75e345b76e7adc290cb99af153017cc84df8e8
7
- data.tar.gz: 682c8671b614077226d873dba34543dfae6598fb555cefa69bdce155e09de2bb4cc5cfb107d7a5b4887e50d6381eb923b2fda1d4babb5d458b506484b118b2d5
6
+ metadata.gz: d2d803e3ae97d53a1b3287b564615f9f4f9790d58065ad224d9376ec4fd2407d6df66d10c20a54175ad10c57e2b9efafe10955e01306b21c0d92213b6cc5b9e9
7
+ data.tar.gz: 4ffb182ae4720b9e67d4abb575c09b1e07f7c00a33c1c2601bf66f763eaa4997f8a813980b9367f47ba9731f6ce318a13b277d8c80396c9e7cfe43178896198c
@@ -5,6 +5,7 @@ module ReplTypeCompletor
5
5
  OBJECT_SINGLETON_METHODS_METHOD = Object.instance_method(:singleton_methods)
6
6
  OBJECT_PRIVATE_METHODS_METHOD = Object.instance_method(:private_methods)
7
7
  OBJECT_INSTANCE_VARIABLES_METHOD = Object.instance_method(:instance_variables)
8
+ OBJECT_INSTANCE_VARIABLE_DEFINED_METHOD = Object.instance_method(:instance_variable_defined?)
8
9
  OBJECT_INSTANCE_VARIABLE_GET_METHOD = Object.instance_method(:instance_variable_get)
9
10
  OBJECT_CLASS_METHOD = Object.instance_method(:class)
10
11
  MODULE_NAME_METHOD = Module.instance_method(:name)
@@ -72,7 +72,11 @@ module ReplTypeCompletor
72
72
  else
73
73
  []
74
74
  end
75
- candidates.select { _1.start_with?(name) }.map { _1[name.size..] }
75
+
76
+ candidates.filter_map do
77
+ _1[name.size..] if _1.start_with?(name)
78
+ rescue EncodingError
79
+ end
76
80
  rescue Exception => e
77
81
  ReplTypeCompletor.handle_exception(e)
78
82
  []
@@ -1179,6 +1179,12 @@ module ReplTypeCompletor
1179
1179
  end
1180
1180
  end
1181
1181
  end
1182
+
1183
+ if types.empty? && args.empty? && !kwargs && !block
1184
+ t = Types.accessor_method_return_type(receiver, method_name)
1185
+ types << t if t
1186
+ end
1187
+
1182
1188
  scope&.terminate if terminates && breaks.empty?
1183
1189
  Types::UnionType[*types, *breaks]
1184
1190
  end
@@ -105,6 +105,28 @@ module ReplTypeCompletor
105
105
  UnionType[*types]
106
106
  end
107
107
 
108
+ def self.accessor_method_return_type(type, method_name)
109
+ return unless method_name.match?(/\A[a-z_][a-z_0-9]*\z/)
110
+
111
+ ivar_name = :"@#{method_name}"
112
+ instances = type.types.filter_map do |t|
113
+ case t
114
+ in SingletonType
115
+ t.module_or_class
116
+ in InstanceType
117
+ t.instances
118
+ end
119
+ end.flatten
120
+ instances = instances.sample(OBJECT_TO_TYPE_SAMPLE_SIZE) if instances.size > OBJECT_TO_TYPE_SAMPLE_SIZE
121
+ objects = []
122
+ instances.each do |instance|
123
+ if Methods::OBJECT_INSTANCE_VARIABLE_DEFINED_METHOD.bind_call(instance, ivar_name)
124
+ objects << Methods::OBJECT_INSTANCE_VARIABLE_GET_METHOD.bind_call(instance, ivar_name)
125
+ end
126
+ end
127
+ union_type_from_objects(objects) unless objects.empty?
128
+ end
129
+
108
130
  def self.rbs_methods(type, method_name, args_types, kwargs_type, has_block)
109
131
  return [] unless rbs_builder
110
132
 
@@ -188,9 +210,10 @@ module ReplTypeCompletor
188
210
  end
189
211
 
190
212
  def self.union_type_from_objects(objects)
191
- instanes = objects.size <= OBJECT_TO_TYPE_SAMPLE_SIZE ? objects : objects.sample(OBJECT_TO_TYPE_SAMPLE_SIZE)
192
- class_instanes = instanes.group_by { Methods::OBJECT_CLASS_METHOD.bind_call(_1) }
193
- UnionType[*class_instanes.map { InstanceType.new _1, nil, _2 }]
213
+ instances = objects.size <= OBJECT_TO_TYPE_SAMPLE_SIZE ? objects : objects.sample(OBJECT_TO_TYPE_SAMPLE_SIZE)
214
+ modules, instances = instances.partition { Module === _1 }
215
+ class_instances = instances.group_by { Methods::OBJECT_CLASS_METHOD.bind_call(_1) }
216
+ UnionType[*class_instances.map { InstanceType.new _1, nil, _2 }, *modules.uniq.map { SingletonType.new _1 }]
194
217
  end
195
218
 
196
219
  class SingletonType
@@ -273,7 +296,9 @@ module ReplTypeCompletor
273
296
  end
274
297
 
275
298
  def inspect
276
- if params.empty?
299
+ if !@params && (@klass == Array || @klass == Hash) && @instances
300
+ "#{inspect_without_params}[unresolved]"
301
+ elsif params.empty?
277
302
  inspect_without_params
278
303
  else
279
304
  params_string = "[#{params.map { "#{_1}: #{_2.inspect}" }.join(', ')}]"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReplTypeCompletor
4
- VERSION = "0.1.11"
4
+ VERSION = "0.1.12"
5
5
  end
metadata CHANGED
@@ -1,13 +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.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - tompng
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: prism
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubygems_version: 3.6.3
87
+ rubygems_version: 3.6.7
88
88
  specification_version: 4
89
89
  summary: Type based completion for REPL.
90
90
  test_files: []