steep 0.15.0 → 0.17.0
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 +12 -1
- data/lib/steep/cli.rb +16 -1
- data/lib/steep/drivers/annotations.rb +1 -1
- data/lib/steep/drivers/check.rb +1 -12
- data/lib/steep/drivers/langserver.rb +13 -462
- data/lib/steep/drivers/utils/driver_helper.rb +1 -1
- 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 +4 -2
- data/lib/steep/project/file.rb +2 -1
- data/lib/steep/project/hover_content.rb +6 -3
- data/lib/steep/project/options.rb +15 -0
- data/lib/steep/project/target.rb +30 -20
- 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/validator.rb +5 -5
- data/lib/steep/type_construction.rb +13 -19
- data/lib/steep/type_inference/constant_env.rb +2 -10
- data/lib/steep/type_inference/context.rb +1 -0
- data/lib/steep/version.rb +1 -1
- data/steep.gemspec +7 -8
- metadata +22 -142
- data/exe/rbs +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 -157
- 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 -89
- data/vendor/ruby-signature/bin/test_runner.rb +0 -16
- 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 -7
- data/vendor/ruby-signature/lib/rbs.rb +0 -64
- data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
- data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
- data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
- data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
- data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
- data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
- data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
- data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
- data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
- data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
- data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
- data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
- data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
- data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
- data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
- data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
- data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
- data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
- data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
- data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
- data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
- data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
- data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
- data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
- data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
- data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
- data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
- data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
- data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
- data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
- data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
- data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
- data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
- data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
- data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
- data/vendor/ruby-signature/rbs.gemspec +0 -45
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
- data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
- 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 -44
- 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 -413
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
- 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 -194
- 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 -1076
- 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 -243
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
- 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 -429
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
- 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 -57
- 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 -1901
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
- data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
- data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
- 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 -301
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,138 +0,0 @@
|
|
1
|
-
module RBS
|
2
|
-
class VarianceCalculator
|
3
|
-
class Result
|
4
|
-
attr_reader :result
|
5
|
-
|
6
|
-
def initialize(variables:)
|
7
|
-
@result = {}
|
8
|
-
variables.each do |x|
|
9
|
-
result[x] = :unused
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def covariant(x)
|
14
|
-
case result[x]
|
15
|
-
when :unused
|
16
|
-
result[x] = :covariant
|
17
|
-
when :contravariant
|
18
|
-
result[x] = :invariant
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def contravariant(x)
|
23
|
-
case result[x]
|
24
|
-
when :unused
|
25
|
-
result[x] = :contravariant
|
26
|
-
when :covariant
|
27
|
-
result[x] = :invariant
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def invariant(x)
|
32
|
-
result[x] = :invariant
|
33
|
-
end
|
34
|
-
|
35
|
-
def each(&block)
|
36
|
-
result.each(&block)
|
37
|
-
end
|
38
|
-
|
39
|
-
def include?(name)
|
40
|
-
result.key?(name)
|
41
|
-
end
|
42
|
-
|
43
|
-
def compatible?(var, with_annotation:)
|
44
|
-
variance = result[var]
|
45
|
-
|
46
|
-
case
|
47
|
-
when variance == :unused
|
48
|
-
true
|
49
|
-
when with_annotation == :invariant
|
50
|
-
true
|
51
|
-
when variance == with_annotation
|
52
|
-
true
|
53
|
-
else
|
54
|
-
false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
attr_reader :builder
|
60
|
-
|
61
|
-
def initialize(builder:)
|
62
|
-
@builder = builder
|
63
|
-
end
|
64
|
-
|
65
|
-
def env
|
66
|
-
builder.env
|
67
|
-
end
|
68
|
-
|
69
|
-
def in_method_type(method_type:, variables:)
|
70
|
-
result = Result.new(variables: variables)
|
71
|
-
|
72
|
-
method_type.type.each_param do |param|
|
73
|
-
type(param.type, result: result, context: :contravariant)
|
74
|
-
end
|
75
|
-
|
76
|
-
if method_type.block
|
77
|
-
method_type.block.type.each_param do |param|
|
78
|
-
type(param.type, result: result, context: :covariant)
|
79
|
-
end
|
80
|
-
type(method_type.block.type.return_type, result: result, context: :contravariant)
|
81
|
-
end
|
82
|
-
|
83
|
-
type(method_type.type.return_type, result: result, context: :covariant)
|
84
|
-
|
85
|
-
result
|
86
|
-
end
|
87
|
-
|
88
|
-
def in_inherit(name:, args:, variables:)
|
89
|
-
type = Types::ClassInstance.new(name: name, args: args, location: nil)
|
90
|
-
|
91
|
-
Result.new(variables: variables).tap do |result|
|
92
|
-
type(type, result: result, context: :covariant)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def type(type, result:, context:)
|
97
|
-
case type
|
98
|
-
when Types::Variable
|
99
|
-
if result.include?(type.name)
|
100
|
-
case context
|
101
|
-
when :covariant
|
102
|
-
result.covariant(type.name)
|
103
|
-
when :contravariant
|
104
|
-
result.contravariant(type.name)
|
105
|
-
when :invariant
|
106
|
-
result.invariant(type.name)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
when Types::ClassInstance, Types::Interface
|
110
|
-
decl = env.find_class(type.name)
|
111
|
-
type.args.each.with_index do |ty, i|
|
112
|
-
var = decl.type_params.params[i]
|
113
|
-
case var.variance
|
114
|
-
when :invariant
|
115
|
-
type(ty, result: result, context: :invariant)
|
116
|
-
when :covariant
|
117
|
-
type(ty, result: result, context: context)
|
118
|
-
when :contravariant
|
119
|
-
con = case context
|
120
|
-
when :invariant
|
121
|
-
:invariant
|
122
|
-
when :covariant
|
123
|
-
:contravariant
|
124
|
-
when :contravariant
|
125
|
-
:covariant
|
126
|
-
end
|
127
|
-
type(ty, result: result, context: con)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
when Types::Tuple, Types::Record, Types::Union, Types::Intersection
|
131
|
-
# Covariant types
|
132
|
-
type.each_type do |ty|
|
133
|
-
type(ty, result: result, context: context)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module RBS
|
2
|
-
class Vendorer
|
3
|
-
attr_reader :vendor_dir
|
4
|
-
|
5
|
-
def initialize(vendor_dir:)
|
6
|
-
@vendor_dir = vendor_dir
|
7
|
-
end
|
8
|
-
|
9
|
-
def ensure_dir
|
10
|
-
unless vendor_dir.directory?
|
11
|
-
vendor_dir.mkpath
|
12
|
-
end
|
13
|
-
|
14
|
-
yield
|
15
|
-
end
|
16
|
-
|
17
|
-
def clean!
|
18
|
-
ensure_dir do
|
19
|
-
RBS.logger.info "Cleaning vendor root: #{vendor_dir}..."
|
20
|
-
vendor_dir.rmtree
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def stdlib!()
|
25
|
-
ensure_dir do
|
26
|
-
RBS.logger.info "Vendoring stdlib: #{EnvironmentLoader::STDLIB_ROOT} => #{vendor_dir + "stdlib"}..."
|
27
|
-
FileUtils.copy_entry EnvironmentLoader::STDLIB_ROOT, vendor_dir + "stdlib"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def gem!(name, version)
|
32
|
-
ensure_dir do
|
33
|
-
sig_path = EnvironmentLoader.gem_sig_path(name, version)
|
34
|
-
RBS.logger.debug "Checking gem signature path: name=#{name}, version=#{version}, path=#{sig_path}"
|
35
|
-
|
36
|
-
if sig_path&.directory?
|
37
|
-
gems_dir = vendor_dir + "gems"
|
38
|
-
gems_dir.mkpath unless gems_dir.directory?
|
39
|
-
|
40
|
-
gem_dir = gems_dir + name
|
41
|
-
RBS.logger.info "Vendoring gem(#{name}:#{version}): #{sig_path} => #{gem_dir}..."
|
42
|
-
FileUtils.copy_entry sig_path, gem_dir
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,269 +0,0 @@
|
|
1
|
-
module RBS
|
2
|
-
class Writer
|
3
|
-
attr_reader :out
|
4
|
-
|
5
|
-
def initialize(out:)
|
6
|
-
@out = out
|
7
|
-
end
|
8
|
-
|
9
|
-
def write_annotation(annotations, level:)
|
10
|
-
prefix = " " * level
|
11
|
-
|
12
|
-
annotations.each do |annotation|
|
13
|
-
string = annotation.string
|
14
|
-
case
|
15
|
-
when string !~ /\}/
|
16
|
-
out.puts "#{prefix}%a{#{string}}"
|
17
|
-
when string !~ /\)/
|
18
|
-
out.puts "#{prefix}%a(#{string})"
|
19
|
-
when string !~ /\]/
|
20
|
-
out.puts "#{prefix}%a[#{string}]"
|
21
|
-
when string !~ /\>/
|
22
|
-
out.puts "#{prefix}%a<#{string}>"
|
23
|
-
when string !~ /\|/
|
24
|
-
out.puts "#{prefix}%a|#{string}|"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def write_comment(comment, level:)
|
30
|
-
if comment
|
31
|
-
prefix = " " * level
|
32
|
-
comment.string.lines.each do |line|
|
33
|
-
line = " #{line}" unless line.chomp.empty?
|
34
|
-
out.puts "#{prefix}##{line}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def write(decls)
|
40
|
-
[nil, *decls].each_cons(2) do |prev, decl|
|
41
|
-
preserve_empty_line(prev, decl)
|
42
|
-
write_decl decl
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def write_decl(decl)
|
47
|
-
case decl
|
48
|
-
when AST::Declarations::Class
|
49
|
-
super_class = if decl.super_class
|
50
|
-
" < #{name_and_args(decl.super_class.name, decl.super_class.args)}"
|
51
|
-
end
|
52
|
-
write_comment decl.comment, level: 0
|
53
|
-
write_annotation decl.annotations, level: 0
|
54
|
-
out.puts "class #{name_and_params(decl.name, decl.type_params)}#{super_class}"
|
55
|
-
|
56
|
-
[nil, *decl.members].each_cons(2) do |prev, member|
|
57
|
-
preserve_empty_line prev, member
|
58
|
-
write_member member
|
59
|
-
end
|
60
|
-
|
61
|
-
out.puts "end"
|
62
|
-
|
63
|
-
when AST::Declarations::Module
|
64
|
-
self_type = if decl.self_type
|
65
|
-
" : #{decl.self_type}"
|
66
|
-
end
|
67
|
-
|
68
|
-
write_comment decl.comment, level: 0
|
69
|
-
write_annotation decl.annotations, level: 0
|
70
|
-
out.puts "module #{name_and_params(decl.name, decl.type_params)}#{self_type}"
|
71
|
-
decl.members.each.with_index do |member, index|
|
72
|
-
if index > 0
|
73
|
-
out.puts
|
74
|
-
end
|
75
|
-
write_member member
|
76
|
-
end
|
77
|
-
out.puts "end"
|
78
|
-
when AST::Declarations::Constant
|
79
|
-
write_comment decl.comment, level: 0
|
80
|
-
out.puts "#{decl.name}: #{decl.type}"
|
81
|
-
|
82
|
-
when AST::Declarations::Global
|
83
|
-
write_comment decl.comment, level: 0
|
84
|
-
out.puts "#{decl.name}: #{decl.type}"
|
85
|
-
|
86
|
-
when AST::Declarations::Alias
|
87
|
-
write_comment decl.comment, level: 0
|
88
|
-
write_annotation decl.annotations, level: 0
|
89
|
-
out.puts "type #{decl.name} = #{decl.type}"
|
90
|
-
|
91
|
-
when AST::Declarations::Interface
|
92
|
-
write_comment decl.comment, level: 0
|
93
|
-
write_annotation decl.annotations, level: 0
|
94
|
-
out.puts "interface #{name_and_params(decl.name, decl.type_params)}"
|
95
|
-
decl.members.each.with_index do |member, index|
|
96
|
-
if index > 0
|
97
|
-
out.puts
|
98
|
-
end
|
99
|
-
write_member member
|
100
|
-
end
|
101
|
-
out.puts "end"
|
102
|
-
|
103
|
-
when AST::Declarations::Extension
|
104
|
-
write_comment decl.comment, level: 0
|
105
|
-
write_annotation decl.annotations, level: 0
|
106
|
-
out.puts "extension #{name_and_args(decl.name, decl.type_params)} (#{decl.extension_name})"
|
107
|
-
decl.members.each.with_index do |member, index|
|
108
|
-
if index > 0
|
109
|
-
out.puts
|
110
|
-
end
|
111
|
-
write_member member
|
112
|
-
end
|
113
|
-
out.puts "end"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def name_and_params(name, params)
|
118
|
-
if params.empty?
|
119
|
-
"#{name}"
|
120
|
-
else
|
121
|
-
ps = params.each.map do |param|
|
122
|
-
s = ""
|
123
|
-
if param.skip_validation
|
124
|
-
s << "unchecked "
|
125
|
-
end
|
126
|
-
case param.variance
|
127
|
-
when :invariant
|
128
|
-
# nop
|
129
|
-
when :covariant
|
130
|
-
s << "out "
|
131
|
-
when :contravariant
|
132
|
-
s << "in "
|
133
|
-
end
|
134
|
-
s + param.name.to_s
|
135
|
-
end
|
136
|
-
|
137
|
-
"#{name}[#{ps.join(", ")}]"
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def name_and_args(name, args)
|
142
|
-
if name && args
|
143
|
-
if args.empty?
|
144
|
-
"#{name}"
|
145
|
-
else
|
146
|
-
"#{name}[#{args.join(", ")}]"
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def write_member(member)
|
152
|
-
case member
|
153
|
-
when AST::Members::Include
|
154
|
-
write_comment member.comment, level: 2
|
155
|
-
write_annotation member.annotations, level: 2
|
156
|
-
out.puts " include #{name_and_args(member.name, member.args)}"
|
157
|
-
when AST::Members::Extend
|
158
|
-
write_comment member.comment, level: 2
|
159
|
-
write_annotation member.annotations, level: 2
|
160
|
-
out.puts " extend #{name_and_args(member.name, member.args)}"
|
161
|
-
when AST::Members::Prepend
|
162
|
-
write_comment member.comment, level: 2
|
163
|
-
write_annotation member.annotations, level: 2
|
164
|
-
out.puts " prepend #{name_and_args(member.name, member.args)}"
|
165
|
-
when AST::Members::AttrAccessor
|
166
|
-
write_comment member.comment, level: 2
|
167
|
-
write_annotation member.annotations, level: 2
|
168
|
-
out.puts " #{attribute(:accessor, member)}"
|
169
|
-
when AST::Members::AttrReader
|
170
|
-
write_comment member.comment, level: 2
|
171
|
-
write_annotation member.annotations, level: 2
|
172
|
-
out.puts " #{attribute(:reader, member)}"
|
173
|
-
when AST::Members::AttrWriter
|
174
|
-
write_comment member.comment, level: 2
|
175
|
-
write_annotation member.annotations, level: 2
|
176
|
-
out.puts " #{attribute(:writer, member)}"
|
177
|
-
when AST::Members::Public
|
178
|
-
out.puts " public"
|
179
|
-
when AST::Members::Private
|
180
|
-
out.puts " private"
|
181
|
-
when AST::Members::Alias
|
182
|
-
write_comment member.comment, level: 2
|
183
|
-
write_annotation member.annotations, level: 2
|
184
|
-
new_name = member.singleton? ? "self.#{member.new_name}" : member.new_name
|
185
|
-
old_name = member.singleton? ? "self.#{member.old_name}" : member.old_name
|
186
|
-
out.puts " alias #{new_name} #{old_name}"
|
187
|
-
when AST::Members::InstanceVariable
|
188
|
-
write_comment member.comment, level: 2
|
189
|
-
out.puts " #{member.name}: #{member.type}"
|
190
|
-
when AST::Members::ClassInstanceVariable
|
191
|
-
write_comment member.comment, level: 2
|
192
|
-
out.puts " self.#{member.name}: #{member.type}"
|
193
|
-
when AST::Members::ClassVariable
|
194
|
-
write_comment member.comment, level: 2
|
195
|
-
out.puts " #{member.name}: #{member.type}"
|
196
|
-
when AST::Members::MethodDefinition
|
197
|
-
write_comment member.comment, level: 2
|
198
|
-
write_annotation member.annotations, level: 2
|
199
|
-
write_def member
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
def method_name(name)
|
204
|
-
s = name.to_s
|
205
|
-
|
206
|
-
if /\A#{Parser::KEYWORDS_RE}\z/.match?(s)
|
207
|
-
"`#{s}`"
|
208
|
-
else
|
209
|
-
s
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
def write_def(member)
|
214
|
-
name = case member.kind
|
215
|
-
when :instance
|
216
|
-
"#{method_name(member.name)}"
|
217
|
-
when :singleton_instance
|
218
|
-
"self?.#{method_name(member.name)}"
|
219
|
-
when :singleton
|
220
|
-
"self.#{method_name(member.name)}"
|
221
|
-
end
|
222
|
-
|
223
|
-
attrs = member.attributes.empty? ? "" : member.attributes.join(" ") + " "
|
224
|
-
prefix = " #{attrs}def #{name}:"
|
225
|
-
padding = " " * (prefix.size-1)
|
226
|
-
|
227
|
-
out.print prefix
|
228
|
-
|
229
|
-
member.types.each.with_index do |type, index|
|
230
|
-
if index > 0
|
231
|
-
out.print padding
|
232
|
-
out.print "|"
|
233
|
-
end
|
234
|
-
out.puts " #{type}"
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
def attribute(kind, attr)
|
239
|
-
var = case attr.ivar_name
|
240
|
-
when nil
|
241
|
-
""
|
242
|
-
when false
|
243
|
-
"()"
|
244
|
-
else
|
245
|
-
"(#{attr.ivar_name})"
|
246
|
-
end
|
247
|
-
"attr_#{kind} #{attr.name}#{var}: #{attr.type}"
|
248
|
-
end
|
249
|
-
|
250
|
-
def preserve_empty_line(prev, decl)
|
251
|
-
return unless prev
|
252
|
-
|
253
|
-
decl = decl.comment if decl.respond_to?(:comment) && decl.comment
|
254
|
-
|
255
|
-
# When the signature is not constructed by the parser,
|
256
|
-
# it always inserts an empty line.
|
257
|
-
if !prev.location || !decl.location
|
258
|
-
out.puts
|
259
|
-
return
|
260
|
-
end
|
261
|
-
|
262
|
-
prev_end_line = prev.location.end_line
|
263
|
-
start_line = decl.location.start_line
|
264
|
-
if start_line - prev_end_line > 1
|
265
|
-
out.puts
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|