steep 0.16.0 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +24 -0
  4. data/Rakefile +0 -13
  5. data/bin/setup +0 -2
  6. data/bin/smoke_runner.rb +0 -1
  7. data/exe/steep +0 -1
  8. data/lib/steep.rb +1 -1
  9. data/lib/steep/drivers/check.rb +1 -12
  10. data/lib/steep/drivers/watch.rb +2 -2
  11. data/lib/steep/project/file.rb +1 -1
  12. data/lib/steep/project/hover_content.rb +1 -1
  13. data/lib/steep/project/options.rb +15 -0
  14. data/lib/steep/server/code_worker.rb +4 -4
  15. data/lib/steep/server/signature_worker.rb +4 -4
  16. data/lib/steep/type_construction.rb +13 -19
  17. data/lib/steep/type_inference/constant_env.rb +2 -10
  18. data/lib/steep/type_inference/context.rb +1 -0
  19. data/lib/steep/version.rb +1 -1
  20. data/steep.gemspec +6 -7
  21. metadata +23 -146
  22. data/exe/rbs +0 -3
  23. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  24. data/vendor/ruby-signature/.gitignore +0 -12
  25. data/vendor/ruby-signature/.rubocop.yml +0 -15
  26. data/vendor/ruby-signature/BSDL +0 -22
  27. data/vendor/ruby-signature/COPYING +0 -56
  28. data/vendor/ruby-signature/Gemfile +0 -6
  29. data/vendor/ruby-signature/README.md +0 -93
  30. data/vendor/ruby-signature/Rakefile +0 -142
  31. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -157
  32. data/vendor/ruby-signature/bin/console +0 -14
  33. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  34. data/vendor/ruby-signature/bin/setup +0 -10
  35. data/vendor/ruby-signature/bin/sort +0 -89
  36. data/vendor/ruby-signature/bin/test_runner.rb +0 -16
  37. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  38. data/vendor/ruby-signature/docs/sigs.md +0 -148
  39. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  40. data/vendor/ruby-signature/docs/syntax.md +0 -528
  41. data/vendor/ruby-signature/exe/rbs +0 -7
  42. data/vendor/ruby-signature/lib/rbs.rb +0 -64
  43. data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
  44. data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
  45. data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
  46. data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
  47. data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
  48. data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
  49. data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
  50. data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
  51. data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
  52. data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
  53. data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
  54. data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
  55. data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
  56. data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
  57. data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
  58. data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
  59. data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
  60. data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
  61. data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
  62. data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
  63. data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
  64. data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
  65. data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
  66. data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
  67. data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
  68. data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
  69. data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
  70. data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
  71. data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
  72. data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
  73. data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
  74. data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
  75. data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
  76. data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
  77. data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
  78. data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
  79. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
  80. data/vendor/ruby-signature/rbs.gemspec +0 -46
  81. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
  82. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
  83. data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
  84. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  85. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  86. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  87. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -45
  88. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  89. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  90. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  91. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  92. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  93. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  94. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -413
  95. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
  96. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  97. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  98. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  99. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  100. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -194
  101. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  102. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  103. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  104. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -1076
  105. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  106. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  107. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -243
  108. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  109. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
  110. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  111. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
  112. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
  113. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
  114. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
  115. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
  116. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
  117. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  118. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  119. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  120. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -429
  121. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
  122. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
  123. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  124. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  125. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -57
  126. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
  127. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  128. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  129. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1901
  130. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
  131. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  132. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
  133. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
  134. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  135. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
  136. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
  137. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  138. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
  139. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  140. data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
  141. data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
  142. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
  143. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
  144. data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
  145. data/vendor/ruby-signature/stdlib/json/json.rbs +0 -335
  146. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
  147. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  148. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  149. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  150. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -301
  151. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
data/exe/rbs DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- load File.join(__dir__, "../vendor/ruby-signature/exe/rbs")
@@ -1,27 +0,0 @@
1
- name: Ruby
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
- pull_request: {}
8
-
9
- jobs:
10
- test:
11
- runs-on: "ubuntu-latest"
12
- strategy:
13
- matrix:
14
- container_tag:
15
- - master-nightly-bionic
16
- - 2.6.5-bionic
17
- - 2.7.0-bionic
18
- container:
19
- image: rubylang/ruby:${{ matrix.container_tag }}
20
- steps:
21
- - uses: actions/checkout@v1
22
- - name: Run test
23
- run: |
24
- ruby -v
25
- gem install bundler
26
- bundle install --jobs 4 --retry 3
27
- bundle exec rake
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /pkg/
6
- /spec/reports/
7
- /tmp/
8
- /Gemfile.lock
9
- /.ruby-version
10
- /lib/rbs/parser.rb
11
- /lib/rbs/parser.output
12
- /vendor/sigs
@@ -1,15 +0,0 @@
1
- require: rubocop-rubycw
2
- AllCops:
3
- TargetRubyVersion: 2.7
4
- DisabledByDefault: true
5
- Exclude:
6
- - 'vendor/bundle/**/*'
7
- Rubycw/Rubycw:
8
- Enabled: true
9
- Exclude:
10
- - 'test/**/*_test.rb'
11
-
12
- Lint/DuplicateMethods:
13
- Enabled: true
14
- Include:
15
- - 'test/**/*_test.rb'
@@ -1,22 +0,0 @@
1
- Copyright (C) 2019 Soutaro Matsumoto. All rights reserved.
2
-
3
- Redistribution and use in source and binary forms, with or without
4
- modification, are permitted provided that the following conditions
5
- are met:
6
- 1. Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
8
- 2. Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
- SUCH DAMAGE.
@@ -1,56 +0,0 @@
1
- ruby-signature is copyrighted free software by Soutaro Matsumoto <matsumoto@soutaro.com>.
2
- You can redistribute it and/or modify it under either the terms of the
3
- 2-clause BSDL (see the file BSDL), or the conditions below:
4
-
5
- 1. You may make and give away verbatim copies of the source form of the
6
- software without restriction, provided that you duplicate all of the
7
- original copyright notices and associated disclaimers.
8
-
9
- 2. You may modify your copy of the software in any way, provided that
10
- you do at least ONE of the following:
11
-
12
- a. place your modifications in the Public Domain or otherwise
13
- make them Freely Available, such as by posting said
14
- modifications to Usenet or an equivalent medium, or by allowing
15
- the author to include your modifications in the software.
16
-
17
- b. use the modified software only within your corporation or
18
- organization.
19
-
20
- c. give non-standard binaries non-standard names, with
21
- instructions on where to get the original software distribution.
22
-
23
- d. make other distribution arrangements with the author.
24
-
25
- 3. You may distribute the software in object code or binary form,
26
- provided that you do at least ONE of the following:
27
-
28
- a. distribute the binaries and library files of the software,
29
- together with instructions (in the manual page or equivalent)
30
- on where to get the original distribution.
31
-
32
- b. accompany the distribution with the machine-readable source of
33
- the software.
34
-
35
- c. give non-standard binaries non-standard names, with
36
- instructions on where to get the original software distribution.
37
-
38
- d. make other distribution arrangements with the author.
39
-
40
- 4. You may modify and include the part of the software into any other
41
- software (possibly commercial). But some files in the distribution
42
- are not written by the author, so that they are not under these terms.
43
-
44
- For the list of those files and their copying conditions, see the
45
- file LEGAL.
46
-
47
- 5. The scripts and library files supplied as input to or produced as
48
- output from the software do not automatically fall under the
49
- copyright of the software, but belong to whomever generated them,
50
- and may be sold commercially, and may be aggregated with this
51
- software.
52
-
53
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
- PURPOSE.
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in ruby-signature.gemspec
4
- gemspec
5
-
6
- gem "ruby-signature-amber", path: "test/assets/test-gem"
@@ -1,93 +0,0 @@
1
- # RBS
2
-
3
- RBS provides syntax and semantics definition for the `Ruby Signature` language, `.rbs` files.
4
- It consists of a parser, the syntax, and class definition interpreter, the semantics.
5
-
6
- ## Build
7
-
8
- We haven't published a gem yet.
9
- You need to install the dependencies, and build its parser with `bin/setup`.
10
-
11
- ```
12
- $ bin/setup
13
- $ bundle exec exe/rbs
14
- ```
15
-
16
- ## Usage
17
-
18
- ```
19
- $ rbs list
20
- $ rbs ancestors ::Object
21
- $ rbs methods ::Object
22
- $ rbs method ::Object tap
23
- ```
24
-
25
- ### rbs [--class|--module|interface] list
26
-
27
- ```
28
- $ rbs list
29
- ```
30
-
31
- This command lists all of the classes/modules/interfaces defined in `.rbs` files.
32
-
33
- ### rbs ancestors [--singleton|--instance] CLASS
34
-
35
- ```
36
- $ rbs ancestors Array # ([].class.ancestors)
37
- $ rbs ancestors --singleton Array # (Array.class.ancestors)
38
- ```
39
-
40
- This command prints the _ancestors_ of the class.
41
- The name of the command is borrowed from `Class#ancestors`, but the semantics is a bit different.
42
- The `ancestors` command is more precise (I believe).
43
-
44
- ### rbs methods [--singleton|--instance] CLASS
45
-
46
- ```
47
- $ rbs methods ::Integer # 1.methods
48
- $ rbs methods --singleton ::Object # Object.methods
49
- ```
50
-
51
- This command prints all methods provided for the class.
52
-
53
- ### rbs method [--singleton|--instance] CLASS METHOD
54
-
55
- ```
56
- $ rbs method ::Integer '+' # 1+2
57
- $ rbs method --singleton ::Object tap # Object.tap { ... }
58
- ```
59
-
60
- This command prints type and properties of the method.
61
-
62
- ### Options
63
-
64
- It accepts two global options, `-r` and `-I`.
65
-
66
- `-r` is for libraries. You can specify the names of libraries.
67
-
68
- ```
69
- $ rbs -r set list
70
- ```
71
-
72
- `-I` is for application signatures. You can specify the name of directory.
73
-
74
- ```
75
- $ rbs -I sig list
76
- ```
77
-
78
- ## Guides
79
-
80
- - [Standard library signature contribution guide](docs/CONTRIBUTING.md)
81
- - [Writing signatures guide](docs/sigs.md)
82
- - [Stdlib signatures guide](docs/stdlib.md)
83
- - [Syntax](docs/syntax.md)
84
-
85
- ## Development
86
-
87
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
88
-
89
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
90
-
91
- ## Contributing
92
-
93
- Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/ruby-signature.
@@ -1,142 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"].reject do |path|
8
- path =~ %r{test/stdlib/}
9
- end
10
- end
11
-
12
- multitask :default => [:test, :stdlib_test, :rubocop, :validate]
13
-
14
- task :validate => :parser do
15
- sh "rbs validate"
16
- end
17
-
18
- FileList["test/stdlib/**/*_test.rb"].each do |test|
19
- multitask test => :parser do
20
- sh "ruby bin/test_runner.rb #{test}"
21
- end
22
- multitask stdlib_test: test
23
- end
24
-
25
- task :rubocop do
26
- sh "rubocop --parallel"
27
- end
28
-
29
- rule ".rb" => ".y" do |t|
30
- sh "racc -v -o #{t.name} #{t.source}"
31
- end
32
-
33
- task :parser => "lib/rbs/parser.rb"
34
- task :test => :parser
35
- task :stdlib_test => :parser
36
- task :build => :parser
37
-
38
- namespace :generate do
39
- task :stdlib_test, [:class] do |_task, args|
40
- klass = args.fetch(:class) do
41
- raise "Class name is necessary. e.g. rake 'generate:stdlib_test[String]'"
42
- end
43
-
44
- path = Pathname("test/stdlib/#{klass}_test.rb")
45
- raise "#{path} already exists!" if path.exist?
46
-
47
- require "erb"
48
- require "ruby/signature"
49
-
50
- class TestTemplateBuilder
51
- attr_reader :klass, :env
52
-
53
- def initialize(klass)
54
- @klass = klass
55
-
56
- @env = Ruby::Signature::Environment.new
57
- Ruby::Signature::EnvironmentLoader.new.load(env: @env)
58
- end
59
-
60
- def call
61
- ERB.new(<<~ERB, trim_mode: "-").result(binding)
62
- require_relative "test_helper"
63
-
64
- class <%= klass %>Test < StdlibTest
65
- target <%= klass %>
66
- # library "pathname", "set", "securerandom" # Declare library signatures to load
67
- using hook.refinement
68
- <%- class_methods.each do |method_name, definition| %>
69
- def test_class_method_<%= test_name_for(method_name) %>
70
- <%- definition.method_types.each do |method_type| -%>
71
- # <%= method_type %>
72
- <%= klass %>.<%= method_name %>
73
- <%- end -%>
74
- end
75
- <%- end -%>
76
- <%- instance_methods.each do |method_name, definition| %>
77
- def test_<%= test_name_for(method_name) %>
78
- <%- definition.method_types.each do |method_type| -%>
79
- # <%= method_type %>
80
- <%= klass %>.new.<%= method_name %>
81
- <%- end -%>
82
- end
83
- <%- end -%>
84
- end
85
- ERB
86
- end
87
-
88
- private
89
-
90
- def test_name_for(method_name)
91
- {
92
- :== => 'double_equal',
93
- :!= => 'not_equal',
94
- :=== => 'triple_equal',
95
- :[] => 'square_bracket',
96
- :[]= => 'square_bracket_assign',
97
- :> => 'greater_than',
98
- :< => 'less_than',
99
- :>= => 'greater_than_equal_to',
100
- :<= => 'less_than_equal_to',
101
- :<=> => 'spaceship',
102
- :+ => 'plus',
103
- :- => 'minus',
104
- :* => 'multiply',
105
- :/ => 'divide',
106
- :** => 'power',
107
- :% => 'modulus',
108
- :& => 'and',
109
- :| => 'or',
110
- :^ => 'xor',
111
- :>> => 'right_shift',
112
- :<< => 'left_shift',
113
- :=~ => 'pattern_match',
114
- :!~ => 'does_not_match',
115
- :~ => 'tilde'
116
- }.fetch(method_name, method_name)
117
- end
118
-
119
- def type_name
120
- @type_name ||= Ruby::Signature::TypeName.new(name: klass.to_sym, namespace: Ruby::Signature::Namespace.new(path: [], absolute: true))
121
- end
122
-
123
- def class_methods
124
- @class_methods ||= Ruby::Signature::DefinitionBuilder.new(env: env).build_singleton(type_name).methods.select {|_, definition|
125
- definition.implemented_in.name.absolute! == type_name
126
- }
127
- end
128
-
129
- def instance_methods
130
- @instance_methods ||= Ruby::Signature::DefinitionBuilder.new(env: env).build_instance(type_name).methods.select {|_, definition|
131
- definition.implemented_in.name.absolute! == type_name
132
- }
133
- end
134
- end
135
-
136
- path.write TestTemplateBuilder.new(klass).call
137
-
138
- puts "Created: #{path}"
139
- end
140
- end
141
-
142
- CLEAN.include("lib/rbs/parser.rb")
@@ -1,157 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rbs"
5
- require "rdoc"
6
-
7
- def store_for_class(name, stores:)
8
- stores.find do |store|
9
- store.find_class_named(name) || store.find_module_named(name)
10
- end
11
- end
12
-
13
- def format_comment(comment)
14
- out = RDoc::Markup::Document.new
15
- out << comment
16
- formatter = RDoc::Markup::ToMarkdown.new
17
- out.accept(formatter)
18
- end
19
-
20
- def comment_for_constant(decl, stores:)
21
- class_name = decl.name.namespace.to_type_name.to_s
22
- klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
23
- store.find_class_named(class_name) || store.find_module_named(class_name)
24
- }
25
-
26
- if klass
27
- constant = klass.constants.find do |const|
28
- const.name == decl.name.name.to_s
29
- end
30
-
31
- if constant&.documented?
32
- string = format_comment(constant.comment)
33
- RBS::AST::Comment.new(location: nil, string: string)
34
- end
35
- end
36
- end
37
-
38
- def comment_for_class(decl, stores:)
39
- name = decl.name.to_s
40
- klass = store_for_class(name, stores: stores)&.yield_self {|store|
41
- store.find_class_named(name) || store.find_module_named(name)
42
- }
43
-
44
- if klass&.documented?
45
- string = format_comment(klass.comment)
46
- RBS::AST::Comment.new(location: nil, string: string)
47
- end
48
- end
49
-
50
- def comment_for_method(klass, method, stores:)
51
- method = store_for_class(klass, stores: stores)&.load_method(klass, method)
52
-
53
- if method&.documented?
54
- out = RDoc::Markup::Document.new
55
-
56
- out << method.comment
57
-
58
- if method.arglists
59
- out << RDoc::Markup::Heading.new(1, "arglists 💪👽🚨 << Delete this section")
60
- arglists = method.arglists.chomp.split("\n").map {|line| line + "\n" }
61
- out << RDoc::Markup::Verbatim.new(*arglists)
62
- end
63
-
64
- string = out.accept(RDoc::Markup::ToMarkdown.new)
65
- RBS::AST::Comment.new(location: nil, string: string)
66
- end
67
-
68
- rescue RDoc::Store::MissingFileError
69
- puts " 👺 No document found for #{klass}#{method}"
70
- nil
71
- end
72
-
73
- if ARGV.empty?
74
- puts 'annotate-with-rdoc [RBS files...]'
75
- exit
76
- end
77
-
78
- def print_members(stores, klass_name, members)
79
- members.each do |member|
80
- case member
81
- when RBS::AST::Members::MethodDefinition
82
- puts " Processing #{member.name}..."
83
-
84
- method_name = case
85
- when member.instance?
86
- "##{member.name}"
87
- when member.singleton?
88
- "::#{member.name}"
89
- end
90
-
91
- comment = comment_for_method(klass_name, method_name, stores: stores)
92
-
93
- unless comment
94
- if member.instance? && member.name == :initialize
95
- comment = comment_for_method(klass_name, '::new', stores: stores)
96
- end
97
- end
98
-
99
- member.instance_variable_set(:@comment, comment)
100
- when RBS::AST::Members::AttrReader, RBS::AST::Members::AttrAccessor, RBS::AST::Members::AttrWriter
101
- puts " 👻 Attributes not supported (#{klass_name})"
102
- when RBS::AST::Members::Alias
103
- puts " Processing #{member.new_name}(alias)..."
104
- prefix = case
105
- when member.instance?
106
- "#"
107
- when member.singleton?
108
- "."
109
- end
110
- name = "#{prefix}#{member.new_name}"
111
-
112
- comment = comment_for_method(klass_name, name, stores: stores)
113
- member.instance_variable_set(:@comment, comment)
114
- end
115
- end
116
- end
117
-
118
- stores = []
119
- RDoc::RI::Paths.each true, true, false, false do |path, type|
120
- puts "Loading store from #{path}..."
121
- store = RDoc::RI::Store.new(path, type)
122
- store.load_all
123
- stores << store
124
- end
125
-
126
- ARGV.map {|f| Pathname(f) }.each do |path|
127
- puts "Opening #{path}..."
128
-
129
- buffer = RBS::Buffer.new(name: path, content: path.read)
130
- sigs = RBS::Parser.parse_signature(buffer)
131
-
132
- sigs.each do |decl|
133
- case decl
134
- when RBS::AST::Declarations::Constant
135
- puts " Importing documentation for #{decl.name}..."
136
- comment = comment_for_constant(decl, stores: stores)
137
- decl.instance_variable_set(:@comment, comment)
138
- when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module
139
- puts " Importing documentation for #{decl.name}..."
140
- comment = comment_for_class(decl, stores: stores)
141
- decl.instance_variable_set(:@comment, comment)
142
-
143
- print_members stores, decl.name.to_s, decl.members
144
- when RBS::AST::Declarations::Extension
145
- puts " Importing documentation for #{decl.name} (#{decl.extension_name})"
146
-
147
- print_members stores, decl.name.to_s, decl.members
148
- end
149
- end
150
-
151
- puts "Writing #{path}..."
152
- path.open('w') do |out|
153
- writer = RBS::Writer.new(out: out)
154
- writer.write sigs
155
- end
156
- end
157
-