steep 0.14.0 → 0.16.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/CHANGELOG.md +25 -0
- data/Rakefile +0 -13
- data/bin/setup +0 -2
- data/bin/smoke_runner.rb +0 -1
- data/exe/steep +0 -1
- data/lib/steep.rb +18 -2
- data/lib/steep/annotation_parser.rb +4 -4
- data/lib/steep/ast/buffer.rb +11 -7
- data/lib/steep/ast/builtin.rb +8 -0
- data/lib/steep/ast/types/factory.rb +55 -55
- data/lib/steep/cli.rb +16 -1
- data/lib/steep/drivers/annotations.rb +1 -1
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/langserver.rb +13 -457
- data/lib/steep/drivers/utils/driver_helper.rb +1 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/drivers/watch.rb +97 -85
- data/lib/steep/drivers/worker.rb +51 -0
- data/lib/steep/project.rb +9 -5
- data/lib/steep/project/completion_provider.rb +9 -13
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +43 -46
- data/lib/steep/project/hover_content.rb +17 -8
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +40 -24
- data/lib/steep/server/base_worker.rb +56 -0
- data/lib/steep/server/code_worker.rb +151 -0
- data/lib/steep/server/interaction_worker.rb +281 -0
- data/lib/steep/server/master.rb +196 -0
- data/lib/steep/server/signature_worker.rb +148 -0
- data/lib/steep/server/utils.rb +36 -0
- data/lib/steep/server/worker_process.rb +62 -0
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +13 -13
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +996 -726
- data/lib/steep/type_inference/constant_env.rb +3 -11
- data/lib/steep/type_inference/context.rb +8 -3
- data/lib/steep/type_inference/context_array.rb +111 -0
- data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
- data/lib/steep/type_inference/logic.rb +130 -0
- data/lib/steep/type_inference/type_env.rb +5 -69
- data/lib/steep/typing.rb +79 -22
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/Steepfile +1 -0
- data/smoke/and/Steepfile +1 -0
- data/smoke/array/Steepfile +1 -0
- data/smoke/array/b.rb +0 -2
- data/smoke/block/Steepfile +1 -0
- data/smoke/case/Steepfile +1 -0
- data/smoke/class/Steepfile +1 -0
- data/smoke/const/Steepfile +1 -0
- data/smoke/dstr/Steepfile +1 -0
- data/smoke/ensure/Steepfile +1 -0
- data/smoke/enumerator/Steepfile +1 -0
- data/smoke/extension/Steepfile +1 -0
- data/smoke/extension/c.rb +1 -0
- data/smoke/hash/Steepfile +1 -0
- data/smoke/hello/Steepfile +1 -0
- data/smoke/if/Steepfile +1 -0
- data/smoke/if/a.rb +1 -1
- data/smoke/implements/Steepfile +1 -0
- data/smoke/initialize/Steepfile +1 -0
- data/smoke/integer/Steepfile +1 -0
- data/smoke/interface/Steepfile +1 -0
- data/smoke/kwbegin/Steepfile +1 -0
- data/smoke/lambda/Steepfile +1 -0
- data/smoke/literal/Steepfile +1 -0
- data/smoke/map/Steepfile +1 -0
- data/smoke/method/Steepfile +1 -0
- data/smoke/module/Steepfile +1 -0
- data/smoke/regexp/Steepfile +1 -0
- data/smoke/regression/Steepfile +1 -0
- data/smoke/rescue/Steepfile +1 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +1 -0
- data/smoke/skip/Steepfile +1 -0
- data/smoke/stdout/Steepfile +1 -0
- data/smoke/super/Steepfile +1 -0
- data/smoke/type_case/Steepfile +1 -0
- data/smoke/yield/Steepfile +1 -0
- data/steep.gemspec +7 -8
- metadata +26 -141
- data/exe/rbs +0 -3
- data/exe/ruby-signature +0 -3
- data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
- data/vendor/ruby-signature/.gitignore +0 -12
- data/vendor/ruby-signature/.rubocop.yml +0 -15
- data/vendor/ruby-signature/BSDL +0 -22
- data/vendor/ruby-signature/COPYING +0 -56
- data/vendor/ruby-signature/Gemfile +0 -6
- data/vendor/ruby-signature/README.md +0 -93
- data/vendor/ruby-signature/Rakefile +0 -67
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
- data/vendor/ruby-signature/bin/console +0 -14
- data/vendor/ruby-signature/bin/query-rdoc +0 -103
- data/vendor/ruby-signature/bin/setup +0 -10
- data/vendor/ruby-signature/bin/sort +0 -88
- data/vendor/ruby-signature/bin/test_runner.rb +0 -17
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
- data/vendor/ruby-signature/docs/sigs.md +0 -148
- data/vendor/ruby-signature/docs/stdlib.md +0 -152
- data/vendor/ruby-signature/docs/syntax.md +0 -528
- data/vendor/ruby-signature/exe/rbs +0 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -555
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1344
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -444
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -327
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
- data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1894
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
- data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,383 +0,0 @@
|
|
1
|
-
module Ruby
|
2
|
-
module Signature
|
3
|
-
module Prototype
|
4
|
-
class Runtime
|
5
|
-
attr_reader :patterns
|
6
|
-
attr_reader :env
|
7
|
-
attr_reader :merge
|
8
|
-
attr_reader :owners_included
|
9
|
-
|
10
|
-
def initialize(patterns:, env:, merge:, owners_included: [])
|
11
|
-
@patterns = patterns
|
12
|
-
@decls = nil
|
13
|
-
@env = env
|
14
|
-
@merge = merge
|
15
|
-
@owners_included = owners_included.map do |name|
|
16
|
-
Object.const_get(name)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def target?(const)
|
21
|
-
patterns.any? do |pattern|
|
22
|
-
if pattern.end_with?("*")
|
23
|
-
(const.name || "").start_with?(pattern.chop)
|
24
|
-
else
|
25
|
-
const.name == pattern
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def builder
|
31
|
-
@builder ||= DefinitionBuilder.new(env: env)
|
32
|
-
end
|
33
|
-
|
34
|
-
def parse(file)
|
35
|
-
require file
|
36
|
-
end
|
37
|
-
|
38
|
-
def decls
|
39
|
-
unless @decls
|
40
|
-
@decls = []
|
41
|
-
ObjectSpace.each_object(Module).select {|mod| target?(mod) }.sort_by(&:name).each do |mod|
|
42
|
-
case mod
|
43
|
-
when Class
|
44
|
-
generate_class mod
|
45
|
-
when Module
|
46
|
-
generate_module mod
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
@decls
|
51
|
-
end
|
52
|
-
|
53
|
-
def to_type_name(name)
|
54
|
-
*prefix, last = name.split(/::/)
|
55
|
-
|
56
|
-
if prefix.empty?
|
57
|
-
TypeName.new(name: last.to_sym, namespace: Namespace.empty)
|
58
|
-
else
|
59
|
-
TypeName.new(name: last.to_sym, namespace: Namespace.parse(prefix.join("::")))
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def each_mixin(mixins, *super_mixes)
|
64
|
-
supers = Set.new(super_mixes)
|
65
|
-
mixins.each do |mix|
|
66
|
-
unless supers.include?(mix)
|
67
|
-
yield mix
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def method_type(method)
|
73
|
-
untyped = Types::Bases::Any.new(location: nil)
|
74
|
-
|
75
|
-
required_positionals = []
|
76
|
-
optional_positionals = []
|
77
|
-
rest = nil
|
78
|
-
trailing_positionals = []
|
79
|
-
required_keywords = {}
|
80
|
-
optional_keywords = {}
|
81
|
-
rest_keywords = nil
|
82
|
-
|
83
|
-
requireds = required_positionals
|
84
|
-
|
85
|
-
block = nil
|
86
|
-
|
87
|
-
method.parameters.each do |kind, name|
|
88
|
-
case kind
|
89
|
-
when :req
|
90
|
-
requireds << Types::Function::Param.new(name: name, type: untyped)
|
91
|
-
when :opt
|
92
|
-
requireds = trailing_positionals
|
93
|
-
optional_positionals << Types::Function::Param.new(name: name, type: untyped)
|
94
|
-
when :rest
|
95
|
-
requireds = trailing_positionals
|
96
|
-
rest = Types::Function::Param.new(name: name, type: untyped)
|
97
|
-
when :keyreq
|
98
|
-
required_keywords[name] = Types::Function::Param.new(name: nil, type: untyped)
|
99
|
-
when :key
|
100
|
-
optional_keywords[name] = Types::Function::Param.new(name: nil, type: untyped)
|
101
|
-
when :keyrest
|
102
|
-
rest_keywords = Types::Function::Param.new(name: nil, type: untyped)
|
103
|
-
when :block
|
104
|
-
block = MethodType::Block.new(
|
105
|
-
type: Types::Function.empty(untyped).update(rest_positionals: Types::Function::Param.new(name: nil, type: untyped)),
|
106
|
-
required: true
|
107
|
-
)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
method_type = Types::Function.new(
|
112
|
-
required_positionals: required_positionals,
|
113
|
-
optional_positionals: optional_positionals,
|
114
|
-
rest_positionals: rest,
|
115
|
-
trailing_positionals: trailing_positionals,
|
116
|
-
required_keywords: required_keywords,
|
117
|
-
optional_keywords: optional_keywords,
|
118
|
-
rest_keywords: rest_keywords,
|
119
|
-
return_type: untyped
|
120
|
-
)
|
121
|
-
|
122
|
-
MethodType.new(
|
123
|
-
location: nil,
|
124
|
-
type_params: [],
|
125
|
-
type: method_type,
|
126
|
-
block: block
|
127
|
-
)
|
128
|
-
end
|
129
|
-
|
130
|
-
def merge_rbs(module_name, members, instance: nil, singleton: nil)
|
131
|
-
if merge
|
132
|
-
if env.class?(module_name.absolute!)
|
133
|
-
case
|
134
|
-
when instance
|
135
|
-
method = builder.build_instance(module_name.absolute!).methods[instance]
|
136
|
-
method_name = instance
|
137
|
-
kind = :instance
|
138
|
-
when singleton
|
139
|
-
method = builder.build_singleton(module_name.absolute!).methods[singleton]
|
140
|
-
method_name = singleton
|
141
|
-
kind = :singleton
|
142
|
-
end
|
143
|
-
|
144
|
-
if method
|
145
|
-
members << AST::Members::MethodDefinition.new(
|
146
|
-
name: method_name,
|
147
|
-
types: method.method_types.map {|type|
|
148
|
-
type.update.tap do |ty|
|
149
|
-
def ty.to_s
|
150
|
-
location.source
|
151
|
-
end
|
152
|
-
end
|
153
|
-
},
|
154
|
-
kind: kind,
|
155
|
-
location: nil,
|
156
|
-
comment: method.comment,
|
157
|
-
annotations: method.annotations,
|
158
|
-
attributes: method.attributes
|
159
|
-
)
|
160
|
-
return
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
yield
|
165
|
-
else
|
166
|
-
yield
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def target_method?(mod, instance: nil, singleton: nil)
|
171
|
-
case
|
172
|
-
when instance
|
173
|
-
method = mod.instance_method(instance)
|
174
|
-
method.owner == mod || owners_included.any? {|m| method.owner == m }
|
175
|
-
when singleton
|
176
|
-
method = mod.singleton_class.instance_method(singleton)
|
177
|
-
method.owner == mod.singleton_class || owners_included.any? {|m| method.owner == m.singleton_class }
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def generate_methods(mod, module_name, members)
|
182
|
-
mod.singleton_methods.select {|name| target_method?(mod, singleton: name) }.sort.each do |name|
|
183
|
-
method = mod.singleton_class.instance_method(name)
|
184
|
-
|
185
|
-
if method.name == method.original_name
|
186
|
-
merge_rbs(module_name, members, singleton: name) do
|
187
|
-
Signature.logger.info "missing #{module_name}.#{name} #{method.source_location}"
|
188
|
-
|
189
|
-
members << AST::Members::MethodDefinition.new(
|
190
|
-
name: method.name,
|
191
|
-
types: [method_type(method)],
|
192
|
-
kind: :singleton,
|
193
|
-
location: nil,
|
194
|
-
comment: nil,
|
195
|
-
annotations: [],
|
196
|
-
attributes: []
|
197
|
-
)
|
198
|
-
end
|
199
|
-
else
|
200
|
-
members << AST::Members::Alias.new(
|
201
|
-
new_name: method.name,
|
202
|
-
old_name: method.original_name,
|
203
|
-
kind: :singleton,
|
204
|
-
location: nil,
|
205
|
-
comment: nil,
|
206
|
-
annotations: [],
|
207
|
-
)
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
public_instance_methods = mod.public_instance_methods.select {|name| target_method?(mod, instance: name) }
|
212
|
-
unless public_instance_methods.empty?
|
213
|
-
members << AST::Members::Public.new(location: nil)
|
214
|
-
|
215
|
-
public_instance_methods.sort.each do |name|
|
216
|
-
method = mod.instance_method(name)
|
217
|
-
|
218
|
-
if method.name == method.original_name
|
219
|
-
merge_rbs(module_name, members, instance: name) do
|
220
|
-
Signature.logger.info "missing #{module_name}##{name} #{method.source_location}"
|
221
|
-
|
222
|
-
members << AST::Members::MethodDefinition.new(
|
223
|
-
name: method.name,
|
224
|
-
types: [method_type(method)],
|
225
|
-
kind: :instance,
|
226
|
-
location: nil,
|
227
|
-
comment: nil,
|
228
|
-
annotations: [],
|
229
|
-
attributes: []
|
230
|
-
)
|
231
|
-
end
|
232
|
-
else
|
233
|
-
members << AST::Members::Alias.new(
|
234
|
-
new_name: method.name,
|
235
|
-
old_name: method.original_name,
|
236
|
-
kind: :instance,
|
237
|
-
location: nil,
|
238
|
-
comment: nil,
|
239
|
-
annotations: [],
|
240
|
-
)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
private_instance_methods = mod.private_instance_methods.select {|name| target_method?(mod, instance: name) }
|
246
|
-
unless private_instance_methods.empty?
|
247
|
-
members << AST::Members::Private.new(location: nil)
|
248
|
-
|
249
|
-
private_instance_methods.sort.each do |name|
|
250
|
-
method = mod.instance_method(name)
|
251
|
-
|
252
|
-
if method.name == method.original_name
|
253
|
-
merge_rbs(module_name, members, instance: name) do
|
254
|
-
Signature.logger.info "missing #{module_name}##{name} #{method.source_location}"
|
255
|
-
|
256
|
-
members << AST::Members::MethodDefinition.new(
|
257
|
-
name: method.name,
|
258
|
-
types: [method_type(method)],
|
259
|
-
kind: :instance,
|
260
|
-
location: nil,
|
261
|
-
comment: nil,
|
262
|
-
annotations: [],
|
263
|
-
attributes: []
|
264
|
-
)
|
265
|
-
end
|
266
|
-
else
|
267
|
-
members << AST::Members::Alias.new(
|
268
|
-
new_name: method.name,
|
269
|
-
old_name: method.original_name,
|
270
|
-
kind: :instance,
|
271
|
-
location: nil,
|
272
|
-
comment: nil,
|
273
|
-
annotations: [],
|
274
|
-
)
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
def generate_constants(mod)
|
281
|
-
mod.constants(false).sort.each do |name|
|
282
|
-
value = mod.const_get(name)
|
283
|
-
|
284
|
-
next if value.is_a?(Class) || value.is_a?(Module)
|
285
|
-
type = case value
|
286
|
-
when true, false
|
287
|
-
Types::Bases::Bool.new(location: nil)
|
288
|
-
when nil
|
289
|
-
Types::Optional.new(
|
290
|
-
type: Types::Bases::Any.new(location: nil),
|
291
|
-
location: nil
|
292
|
-
)
|
293
|
-
else
|
294
|
-
Types::ClassInstance.new(name: to_type_name(value.class.to_s), args: [], location: nil)
|
295
|
-
end
|
296
|
-
|
297
|
-
@decls << AST::Declarations::Constant.new(
|
298
|
-
name: "#{mod.to_s}::#{name}",
|
299
|
-
type: type,
|
300
|
-
location: nil,
|
301
|
-
comment: nil
|
302
|
-
)
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
def generate_class(mod)
|
307
|
-
type_name = to_type_name(mod.name)
|
308
|
-
super_class = if mod.superclass == ::Object
|
309
|
-
nil
|
310
|
-
else
|
311
|
-
AST::Declarations::Class::Super.new(name: to_type_name(mod.superclass.name), args: [])
|
312
|
-
end
|
313
|
-
|
314
|
-
decl = AST::Declarations::Class.new(
|
315
|
-
name: type_name,
|
316
|
-
type_params: AST::Declarations::ModuleTypeParams.empty,
|
317
|
-
super_class: super_class,
|
318
|
-
members: [],
|
319
|
-
annotations: [],
|
320
|
-
location: nil,
|
321
|
-
comment: nil
|
322
|
-
)
|
323
|
-
|
324
|
-
each_mixin(mod.included_modules, *mod.superclass.included_modules, *mod.included_modules.flat_map(&:included_modules)) do |included_module|
|
325
|
-
module_name = to_type_name(included_module.name)
|
326
|
-
if module_name.namespace == type_name.namespace
|
327
|
-
module_name = TypeName.new(name: module_name.name, namespace: Namespace.empty)
|
328
|
-
end
|
329
|
-
|
330
|
-
decl.members << AST::Members::Include.new(
|
331
|
-
name: module_name,
|
332
|
-
args: [],
|
333
|
-
location: nil,
|
334
|
-
comment: nil,
|
335
|
-
annotations: []
|
336
|
-
)
|
337
|
-
end
|
338
|
-
|
339
|
-
generate_methods(mod, type_name, decl.members)
|
340
|
-
|
341
|
-
@decls << decl
|
342
|
-
|
343
|
-
generate_constants mod
|
344
|
-
end
|
345
|
-
|
346
|
-
def generate_module(mod)
|
347
|
-
type_name = to_type_name(mod.name)
|
348
|
-
|
349
|
-
decl = AST::Declarations::Module.new(
|
350
|
-
name: type_name,
|
351
|
-
type_params: AST::Declarations::ModuleTypeParams.empty,
|
352
|
-
self_type: nil,
|
353
|
-
members: [],
|
354
|
-
annotations: [],
|
355
|
-
location: nil,
|
356
|
-
comment: nil
|
357
|
-
)
|
358
|
-
|
359
|
-
each_mixin(mod.included_modules, *mod.included_modules.flat_map(&:included_modules), namespace: type_name.namespace) do |included_module|
|
360
|
-
module_name = to_type_name(included_module.name)
|
361
|
-
if module_name.namespace == type_name.namespace
|
362
|
-
module_name = TypeName.new(name: module_name.name, namespace: Namespace.empty)
|
363
|
-
end
|
364
|
-
|
365
|
-
decl.members << AST::Members::Include.new(
|
366
|
-
name: module_name,
|
367
|
-
args: [],
|
368
|
-
location: nil,
|
369
|
-
comment: nil,
|
370
|
-
annotations: []
|
371
|
-
)
|
372
|
-
end
|
373
|
-
|
374
|
-
generate_methods(mod, type_name, decl.members)
|
375
|
-
|
376
|
-
@decls << decl
|
377
|
-
|
378
|
-
generate_constants mod
|
379
|
-
end
|
380
|
-
end
|
381
|
-
end
|
382
|
-
end
|
383
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module Ruby
|
2
|
-
module Signature
|
3
|
-
class Substitution
|
4
|
-
attr_reader :mapping
|
5
|
-
|
6
|
-
def initialize()
|
7
|
-
@mapping = {}
|
8
|
-
end
|
9
|
-
|
10
|
-
def add(from:, to:)
|
11
|
-
mapping[from] = to
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.build(variables, types, &block)
|
15
|
-
unless variables.size == types.size
|
16
|
-
raise "Broken substitution: variables=#{variables}, types=#{types}"
|
17
|
-
end
|
18
|
-
|
19
|
-
mapping = variables.zip(types).to_h
|
20
|
-
|
21
|
-
self.new.tap do |subst|
|
22
|
-
mapping.each do |v, t|
|
23
|
-
type = block_given? ? yield(t) : t
|
24
|
-
subst.add(from: v, to: type)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def apply(ty)
|
30
|
-
case ty
|
31
|
-
when Types::Variable
|
32
|
-
mapping[ty.name] || ty
|
33
|
-
else
|
34
|
-
ty
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def without(*vars)
|
39
|
-
self.class.new.tap do |subst|
|
40
|
-
subst.mapping.merge!(mapping)
|
41
|
-
vars.each do |var|
|
42
|
-
subst.mapping.delete(var)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "ruby/signature/test/spy"
|
2
|
-
require "ruby/signature/test/errors"
|
3
|
-
require "ruby/signature/test/type_check"
|
4
|
-
require "ruby/signature/test/hook"
|
5
|
-
|
6
|
-
module Ruby
|
7
|
-
module Signature
|
8
|
-
module Test
|
9
|
-
IS_AP = Kernel.instance_method(:is_a?)
|
10
|
-
DEFINE_METHOD = Module.instance_method(:define_method)
|
11
|
-
INSTANCE_EVAL = BasicObject.instance_method(:instance_eval)
|
12
|
-
INSTANCE_EXEC = BasicObject.instance_method(:instance_exec)
|
13
|
-
METHOD = Kernel.instance_method(:method)
|
14
|
-
CLASS = Kernel.instance_method(:class)
|
15
|
-
SINGLETON_CLASS = Kernel.instance_method(:singleton_class)
|
16
|
-
PP = Kernel.instance_method(:pp)
|
17
|
-
INSPECT = Kernel.instance_method(:inspect)
|
18
|
-
METHODS = Kernel.instance_method(:methods)
|
19
|
-
|
20
|
-
ArgumentsReturn = Struct.new(:arguments, :return_value, :exception, keyword_init: true)
|
21
|
-
CallTrace = Struct.new(:method_name, :method_call, :block_calls, :block_given, keyword_init: true)
|
22
|
-
|
23
|
-
def self.call(receiver, method, *args, **kwargs, &block)
|
24
|
-
method.bind_call(receiver, *args, **kwargs, &block)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|