katakata_irb 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/README.md +3 -1
- data/lib/katakata_irb/completor.rb +4 -5
- data/lib/katakata_irb/scope.rb +9 -1
- data/lib/katakata_irb/type_simulator.rb +1 -2
- data/lib/katakata_irb/types.rb +31 -36
- data/lib/katakata_irb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e03e0f334a22895540f29f3bb27551bff9bfcbede5aac767559006edbc77118f
|
4
|
+
data.tar.gz: 4db442409ca2ac1d853b4e7675ff3ac10aed0d6ced431d1abdbe2eea7a1fa298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb7d8eae8b68d497c6e0c5c0d9bc8d8455d5af5638fb680b3048166188a1035a2e36229a7555203de4f8d18bc3089b92f441f496d6e2a074ad61587805b6de82
|
7
|
+
data.tar.gz: 75ef2f2f26505c98e3550342493474f47f11623fd1342f0529249e6e902e95f5ebf03f5053974c6813beee3697c0d13cb5a0adec073c65ece35dce9a3e3f01ed
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
katakata_irb (0.1.
|
4
|
+
katakata_irb (0.1.8)
|
5
5
|
irb (>= 1.4.0)
|
6
6
|
rbs
|
7
7
|
|
@@ -9,12 +9,12 @@ GEM
|
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
io-console (0.6.0)
|
12
|
-
irb (1.6.
|
12
|
+
irb (1.6.4)
|
13
13
|
reline (>= 0.3.0)
|
14
|
-
minitest (5.
|
14
|
+
minitest (5.18.0)
|
15
15
|
rake (13.0.6)
|
16
|
-
rbs (
|
17
|
-
reline (0.3.
|
16
|
+
rbs (3.1.0)
|
17
|
+
reline (0.3.3)
|
18
18
|
io-console (~> 0.5)
|
19
19
|
|
20
20
|
PLATFORMS
|
data/README.md
CHANGED
@@ -120,10 +120,9 @@ module KatakataIrb::Completor
|
|
120
120
|
contents = types.filter_map do |type|
|
121
121
|
case type
|
122
122
|
when KatakataIrb::Types::InstanceType
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
"#{module_name}.itself" if module_name
|
123
|
+
type.inspect_without_params
|
124
|
+
else
|
125
|
+
type.inspect
|
127
126
|
end
|
128
127
|
end.uniq
|
129
128
|
return if contents.empty?
|
@@ -247,7 +246,7 @@ module KatakataIrb::Completor
|
|
247
246
|
# `require 'target'`
|
248
247
|
return [require_method.to_sym, name.rstrip]
|
249
248
|
end
|
250
|
-
if (target in [:@ident,]) && (expression in [:symbol,]) && (parents[-2] in [:args_add_block, Array =>
|
249
|
+
if (target in [:@ident,]) && (expression in [:symbol,]) && (parents[-2] in [:args_add_block, Array => _args, [:symbol_literal, ^expression]])
|
251
250
|
# `method(&:target)`
|
252
251
|
receiver_ref = [:var_ref, [:@ident, '_1', [0, 0]]]
|
253
252
|
block_statements = [receiver_ref]
|
data/lib/katakata_irb/scope.rb
CHANGED
@@ -14,6 +14,7 @@ module KatakataIrb
|
|
14
14
|
@binding, @self_object = binding, self_object
|
15
15
|
@cache = { SELF => KatakataIrb::Types.type_from_object(self_object) }
|
16
16
|
@local_variables = binding.local_variables.map(&:to_s).to_set
|
17
|
+
@global_variables = global_variables.map(&:to_s).to_set
|
17
18
|
end
|
18
19
|
|
19
20
|
def level() = 0
|
@@ -36,6 +37,8 @@ module KatakataIrb
|
|
36
37
|
BaseScope.type_of(fallback: fallback) { @binding.local_variable_get(name) }
|
37
38
|
when :const
|
38
39
|
BaseScope.type_of(fallback: fallback) { @binding.eval name }
|
40
|
+
when :gvar
|
41
|
+
BaseScope.type_of(fallback: fallback) { @binding.eval name if @global_variables.include? name }
|
39
42
|
end
|
40
43
|
)
|
41
44
|
end
|
@@ -77,7 +80,12 @@ module KatakataIrb
|
|
77
80
|
when :lvar
|
78
81
|
@local_variables.include? name
|
79
82
|
when :const
|
80
|
-
|
83
|
+
begin
|
84
|
+
@binding.eval(name)
|
85
|
+
true
|
86
|
+
rescue
|
87
|
+
false
|
88
|
+
end
|
81
89
|
when :gvar, :cvar, :ivar
|
82
90
|
true
|
83
91
|
when :internal
|
@@ -707,13 +707,12 @@ class KatakataIrb::TypeSimulator
|
|
707
707
|
|
708
708
|
def evaluate_massign(sexp, values, scope)
|
709
709
|
values = sized_splat values, :to_ary, sexp.size unless values.is_a? Array
|
710
|
-
|
711
710
|
rest_index = sexp.find_index { _1 in [:rest_param, ]}
|
712
711
|
if rest_index
|
713
712
|
pre = rest_index ? sexp[0...rest_index] : sexp
|
714
713
|
post = rest_index ? sexp[rest_index + 1..] : []
|
715
714
|
sexp[rest_index] in [:rest_param, rest_field]
|
716
|
-
rest_values = values[pre.size
|
715
|
+
rest_values = values[pre.size...values.size - post.size] || []
|
717
716
|
rest_type = KatakataIrb::Types::InstanceType.new Array, Elem: KatakataIrb::Types::UnionType[*rest_values]
|
718
717
|
pairs = pre.zip(values.first(pre.size)) + [[rest_field, rest_type]] + post.zip(values.last(post.size))
|
719
718
|
else
|
data/lib/katakata_irb/types.rb
CHANGED
@@ -12,7 +12,7 @@ module KatakataIrb::Types
|
|
12
12
|
loader.add path: Pathname('sig')
|
13
13
|
RBS::DefinitionBuilder.new env: RBS::Environment.from_loader(loader).resolve_type_names
|
14
14
|
rescue => e
|
15
|
-
puts "\nKatakataIRB failed to initialize RBS::
|
15
|
+
puts "\r\nKatakataIRB failed to initialize RBS::DefinitionBuilder\r\n#{e}\r\n"
|
16
16
|
Object.new
|
17
17
|
end
|
18
18
|
|
@@ -95,15 +95,11 @@ module KatakataIrb::Types
|
|
95
95
|
given << UnionType[*centers.drop(opts.size)]
|
96
96
|
expected << rest.type
|
97
97
|
end
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
0.5
|
104
|
-
else
|
105
|
-
0
|
106
|
-
end
|
98
|
+
if given.any?
|
99
|
+
score += given.zip(expected).count do |t, e|
|
100
|
+
e = from_rbs_type e, receiver_type
|
101
|
+
intersect?(t, e) || (intersect?(STRING, e) && t.methods.include?(:to_str)) || (intersect?(INTEGER, e) && t.methods.include?(:to_int)) || (intersect?(ARRAY, e) && t.methods.include?(:to_ary))
|
102
|
+
end.fdiv(given.size)
|
107
103
|
end
|
108
104
|
end
|
109
105
|
[[method_type, given || [], expected || []], score]
|
@@ -114,15 +110,16 @@ module KatakataIrb::Types
|
|
114
110
|
end
|
115
111
|
|
116
112
|
def self.intersect?(a, b)
|
117
|
-
atypes =
|
118
|
-
btypes =
|
119
|
-
intersect = ->(type, &block) do
|
120
|
-
aa, bb = [atypes, btypes].map {|types| (types[type] || []).map(&block) }
|
121
|
-
(aa & bb).any?
|
122
|
-
end
|
113
|
+
atypes = a.types.group_by(&:class)
|
114
|
+
btypes = b.types.group_by(&:class)
|
123
115
|
return true if atypes[ProcType] && btypes[ProcType]
|
124
|
-
|
125
|
-
|
116
|
+
if atypes[SingletonType] && btypes[SingletonType]
|
117
|
+
aa, bb = [atypes, btypes].map {|types| types[SingletonType].map(&:module_or_class) }
|
118
|
+
return true if (aa & bb).any?
|
119
|
+
end
|
120
|
+
|
121
|
+
aa, bb = [atypes, btypes].map {|types| (types[InstanceType] || []).map(&:klass) }
|
122
|
+
(aa.flat_map(&:ancestors) & bb).any?
|
126
123
|
end
|
127
124
|
|
128
125
|
def self.type_from_object(object)
|
@@ -196,16 +193,22 @@ module KatakataIrb::Types
|
|
196
193
|
def nillable?() = (@klass == NilClass)
|
197
194
|
def nonnillable() = self
|
198
195
|
def inspect
|
199
|
-
|
200
|
-
|
196
|
+
if params.empty?
|
197
|
+
inspect_without_params
|
198
|
+
else
|
199
|
+
params_string = "[#{params.map { "#{_1}: #{_2.inspect}" }.join(', ')}]"
|
200
|
+
"#{inspect_without_params}#{params_string}"
|
201
|
+
end
|
202
|
+
end
|
203
|
+
def inspect_without_params
|
204
|
+
if klass == NilClass
|
201
205
|
'nil'
|
202
|
-
|
206
|
+
elsif klass == TrueClass
|
203
207
|
'true'
|
204
|
-
|
208
|
+
elsif klass == FalseClass
|
205
209
|
'false'
|
206
210
|
else
|
207
|
-
|
208
|
-
"#{klass.name}#{params_string}"
|
211
|
+
klass.singleton_class? ? klass.superclass.to_s : klass.to_s
|
209
212
|
end
|
210
213
|
end
|
211
214
|
end
|
@@ -327,18 +330,10 @@ module KatakataIrb::Types
|
|
327
330
|
BOOLEAN
|
328
331
|
when RBS::Types::Bases::Instance
|
329
332
|
self_type.transform do |type|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
case type.klass
|
335
|
-
in Class
|
336
|
-
InstanceType.new Class
|
337
|
-
in Module
|
338
|
-
InstanceType.new Module
|
339
|
-
else
|
340
|
-
OBJECT
|
341
|
-
end
|
333
|
+
if type.is_a?(SingletonType) && type.module_or_class.is_a?(Class)
|
334
|
+
InstanceType.new type.module_or_class
|
335
|
+
else
|
336
|
+
OBJECT
|
342
337
|
end
|
343
338
|
end
|
344
339
|
when RBS::Types::Union
|
data/lib/katakata_irb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katakata_irb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tompng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: irb
|