steep 0.14.0 → 0.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +25 -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 +18 -2
  9. data/lib/steep/annotation_parser.rb +4 -4
  10. data/lib/steep/ast/buffer.rb +11 -7
  11. data/lib/steep/ast/builtin.rb +8 -0
  12. data/lib/steep/ast/types/factory.rb +55 -55
  13. data/lib/steep/cli.rb +16 -1
  14. data/lib/steep/drivers/annotations.rb +1 -1
  15. data/lib/steep/drivers/check.rb +20 -4
  16. data/lib/steep/drivers/langserver.rb +13 -457
  17. data/lib/steep/drivers/utils/driver_helper.rb +1 -1
  18. data/lib/steep/drivers/vendor.rb +2 -2
  19. data/lib/steep/drivers/watch.rb +97 -85
  20. data/lib/steep/drivers/worker.rb +51 -0
  21. data/lib/steep/project.rb +9 -5
  22. data/lib/steep/project/completion_provider.rb +9 -13
  23. data/lib/steep/project/dsl.rb +14 -0
  24. data/lib/steep/project/file.rb +43 -46
  25. data/lib/steep/project/hover_content.rb +17 -8
  26. data/lib/steep/project/options.rb +25 -3
  27. data/lib/steep/project/target.rb +40 -24
  28. data/lib/steep/server/base_worker.rb +56 -0
  29. data/lib/steep/server/code_worker.rb +151 -0
  30. data/lib/steep/server/interaction_worker.rb +281 -0
  31. data/lib/steep/server/master.rb +196 -0
  32. data/lib/steep/server/signature_worker.rb +148 -0
  33. data/lib/steep/server/utils.rb +36 -0
  34. data/lib/steep/server/worker_process.rb +62 -0
  35. data/lib/steep/signature/errors.rb +1 -1
  36. data/lib/steep/signature/validator.rb +13 -13
  37. data/lib/steep/source.rb +1 -1
  38. data/lib/steep/type_construction.rb +996 -726
  39. data/lib/steep/type_inference/constant_env.rb +3 -11
  40. data/lib/steep/type_inference/context.rb +8 -3
  41. data/lib/steep/type_inference/context_array.rb +111 -0
  42. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  43. data/lib/steep/type_inference/logic.rb +130 -0
  44. data/lib/steep/type_inference/type_env.rb +5 -69
  45. data/lib/steep/typing.rb +79 -22
  46. data/lib/steep/version.rb +1 -1
  47. data/smoke/alias/Steepfile +1 -0
  48. data/smoke/and/Steepfile +1 -0
  49. data/smoke/array/Steepfile +1 -0
  50. data/smoke/array/b.rb +0 -2
  51. data/smoke/block/Steepfile +1 -0
  52. data/smoke/case/Steepfile +1 -0
  53. data/smoke/class/Steepfile +1 -0
  54. data/smoke/const/Steepfile +1 -0
  55. data/smoke/dstr/Steepfile +1 -0
  56. data/smoke/ensure/Steepfile +1 -0
  57. data/smoke/enumerator/Steepfile +1 -0
  58. data/smoke/extension/Steepfile +1 -0
  59. data/smoke/extension/c.rb +1 -0
  60. data/smoke/hash/Steepfile +1 -0
  61. data/smoke/hello/Steepfile +1 -0
  62. data/smoke/if/Steepfile +1 -0
  63. data/smoke/if/a.rb +1 -1
  64. data/smoke/implements/Steepfile +1 -0
  65. data/smoke/initialize/Steepfile +1 -0
  66. data/smoke/integer/Steepfile +1 -0
  67. data/smoke/interface/Steepfile +1 -0
  68. data/smoke/kwbegin/Steepfile +1 -0
  69. data/smoke/lambda/Steepfile +1 -0
  70. data/smoke/literal/Steepfile +1 -0
  71. data/smoke/map/Steepfile +1 -0
  72. data/smoke/method/Steepfile +1 -0
  73. data/smoke/module/Steepfile +1 -0
  74. data/smoke/regexp/Steepfile +1 -0
  75. data/smoke/regression/Steepfile +1 -0
  76. data/smoke/rescue/Steepfile +1 -0
  77. data/smoke/rescue/a.rb +1 -1
  78. data/smoke/self/Steepfile +1 -0
  79. data/smoke/skip/Steepfile +1 -0
  80. data/smoke/stdout/Steepfile +1 -0
  81. data/smoke/super/Steepfile +1 -0
  82. data/smoke/type_case/Steepfile +1 -0
  83. data/smoke/yield/Steepfile +1 -0
  84. data/steep.gemspec +7 -8
  85. metadata +26 -141
  86. data/exe/rbs +0 -3
  87. data/exe/ruby-signature +0 -3
  88. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  89. data/vendor/ruby-signature/.gitignore +0 -12
  90. data/vendor/ruby-signature/.rubocop.yml +0 -15
  91. data/vendor/ruby-signature/BSDL +0 -22
  92. data/vendor/ruby-signature/COPYING +0 -56
  93. data/vendor/ruby-signature/Gemfile +0 -6
  94. data/vendor/ruby-signature/README.md +0 -93
  95. data/vendor/ruby-signature/Rakefile +0 -67
  96. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
  97. data/vendor/ruby-signature/bin/console +0 -14
  98. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  99. data/vendor/ruby-signature/bin/setup +0 -10
  100. data/vendor/ruby-signature/bin/sort +0 -88
  101. data/vendor/ruby-signature/bin/test_runner.rb +0 -17
  102. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  103. data/vendor/ruby-signature/docs/sigs.md +0 -148
  104. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  105. data/vendor/ruby-signature/docs/syntax.md +0 -528
  106. data/vendor/ruby-signature/exe/rbs +0 -3
  107. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  108. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
  109. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  110. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  111. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  112. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  113. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  114. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  115. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -555
  116. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  117. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  118. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  119. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  120. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  121. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  122. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  123. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  124. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  125. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  126. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  127. data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1344
  128. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -444
  129. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  130. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  131. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  132. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  133. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  134. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  135. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
  136. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -327
  137. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  138. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  139. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  140. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  141. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  142. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  143. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  144. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
  145. data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
  146. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
  147. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
  148. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  149. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  150. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  151. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
  152. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  153. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  154. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  155. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  156. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  157. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  158. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
  159. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
  160. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  161. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  162. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  163. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  164. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
  165. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  166. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  167. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  168. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
  169. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  170. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  171. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
  172. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  173. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
  174. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  175. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
  176. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
  177. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
  178. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
  179. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
  180. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
  181. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  182. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  183. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  184. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
  185. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
  186. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
  187. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  188. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  189. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
  190. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
  191. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  192. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  193. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1894
  194. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
  195. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  196. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
  197. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
  198. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  199. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
  200. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
  201. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  202. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
  203. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  204. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
  205. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
  206. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
  207. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  208. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  209. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  210. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
  211. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -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/ruby/signature/parser.rb
11
- /lib/ruby/signature/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
- # Ruby::Signature
2
-
3
- Ruby::Signature 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/ruby-signature
14
- ```
15
-
16
- ## Usage
17
-
18
- ```
19
- $ ruby-signature list
20
- $ ruby-signature ancestors ::Object
21
- $ ruby-signature methods ::Object
22
- $ ruby-signature method ::Object tap
23
- ```
24
-
25
- ### ruby-signature [--class|--module|interface] list
26
-
27
- ```
28
- $ ruby-signature list
29
- ```
30
-
31
- This command lists all of the classes/modules/interfaces defined in `.rbs` files.
32
-
33
- ### ruby-signature ancestors [--singleton|--instance] CLASS
34
-
35
- ```
36
- $ ruby-signature ancestors Array # ([].class.ancestors)
37
- $ ruby-signature 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
- ### ruby-signature methods [--singleton|--instance] CLASS
45
-
46
- ```
47
- $ ruby-signature methods ::Integer # 1.methods
48
- $ ruby-signature methods --singleton ::Object # Object.methods
49
- ```
50
-
51
- This command prints all methods provided for the class.
52
-
53
- ### ruby-signature method [--singleton|--instance] CLASS METHOD
54
-
55
- ```
56
- $ ruby-signature method ::Integer '+' # 1+2
57
- $ ruby-signature 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
- $ ruby-signature -r set list
70
- ```
71
-
72
- `-I` is for application signatures. You can specify the name of directory.
73
-
74
- ```
75
- $ ruby-signature -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,67 +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/ruby/signature/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
- path.write <<~RUBY
48
- require_relative "test_helper"
49
-
50
- class #{klass}Test < StdlibTest
51
- target #{klass}
52
- # library "pathname", "set", "securerandom" # Declare library signatures to load
53
- using hook.refinement
54
-
55
- # def test_method_name
56
- # # Call the method
57
- # method_name(arg)
58
- # method_name(arg, arg2)
59
- # end
60
- end
61
- RUBY
62
-
63
- puts "Created: #{path}"
64
- end
65
- end
66
-
67
- CLEAN.include("lib/ruby/signature/parser.rb")
@@ -1,156 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "ruby/signature"
4
- require "rdoc"
5
-
6
- def store_for_class(name, stores:)
7
- stores.find do |store|
8
- store.find_class_named(name) || store.find_module_named(name)
9
- end
10
- end
11
-
12
- def format_comment(comment)
13
- out = RDoc::Markup::Document.new
14
- out << comment
15
- formatter = RDoc::Markup::ToMarkdown.new
16
- out.accept(formatter)
17
- end
18
-
19
- def comment_for_constant(decl, stores:)
20
- class_name = decl.name.namespace.to_type_name.to_s
21
- klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
22
- store.find_class_named(class_name) || store.find_module_named(class_name)
23
- }
24
-
25
- if klass
26
- constant = klass.constants.find do |const|
27
- const.name == decl.name.name.to_s
28
- end
29
-
30
- if constant&.documented?
31
- string = format_comment(constant.comment)
32
- Ruby::Signature::AST::Comment.new(location: nil, string: string)
33
- end
34
- end
35
- end
36
-
37
- def comment_for_class(decl, stores:)
38
- name = decl.name.to_s
39
- klass = store_for_class(name, stores: stores)&.yield_self {|store|
40
- store.find_class_named(name) || store.find_module_named(name)
41
- }
42
-
43
- if klass&.documented?
44
- string = format_comment(klass.comment)
45
- Ruby::Signature::AST::Comment.new(location: nil, string: string)
46
- end
47
- end
48
-
49
- def comment_for_method(klass, method, stores:)
50
- method = store_for_class(klass, stores: stores)&.load_method(klass, method)
51
-
52
- if method&.documented?
53
- out = RDoc::Markup::Document.new
54
-
55
- out << method.comment
56
-
57
- if method.arglists
58
- out << RDoc::Markup::Heading.new(1, "arglists 💪👽🚨 << Delete this section")
59
- arglists = method.arglists.chomp.split("\n").map {|line| line + "\n" }
60
- out << RDoc::Markup::Verbatim.new(*arglists)
61
- end
62
-
63
- string = out.accept(RDoc::Markup::ToMarkdown.new)
64
- Ruby::Signature::AST::Comment.new(location: nil, string: string)
65
- end
66
-
67
- rescue RDoc::Store::MissingFileError
68
- puts " 👺 No document found for #{klass}#{method}"
69
- nil
70
- end
71
-
72
- if ARGV.empty?
73
- puts 'annotate-with-rdoc [RBS files...]'
74
- exit
75
- end
76
-
77
- def print_members(stores, klass_name, members)
78
- members.each do |member|
79
- case member
80
- when Ruby::Signature::AST::Members::MethodDefinition
81
- puts " Processing #{member.name}..."
82
-
83
- method_name = case
84
- when member.instance?
85
- "##{member.name}"
86
- when member.singleton?
87
- "::#{member.name}"
88
- end
89
-
90
- comment = comment_for_method(klass_name, method_name, stores: stores)
91
-
92
- unless comment
93
- if member.instance? && member.name == :initialize
94
- comment = comment_for_method(klass_name, '::new', stores: stores)
95
- end
96
- end
97
-
98
- member.instance_variable_set(:@comment, comment)
99
- when Ruby::Signature::AST::Members::AttrReader, Ruby::Signature::AST::Members::AttrAccessor, Ruby::Signature::AST::Members::AttrWriter
100
- puts " 👻 Attributes not supported (#{klass_name})"
101
- when Ruby::Signature::AST::Members::Alias
102
- puts " Processing #{member.new_name}(alias)..."
103
- prefix = case
104
- when member.instance?
105
- "#"
106
- when member.singleton?
107
- "."
108
- end
109
- name = "#{prefix}#{member.new_name}"
110
-
111
- comment = comment_for_method(klass_name, name, stores: stores)
112
- member.instance_variable_set(:@comment, comment)
113
- end
114
- end
115
- end
116
-
117
- stores = []
118
- RDoc::RI::Paths.each true, true, false, false do |path, type|
119
- puts "Loading store from #{path}..."
120
- store = RDoc::RI::Store.new(path, type)
121
- store.load_all
122
- stores << store
123
- end
124
-
125
- ARGV.map {|f| Pathname(f) }.each do |path|
126
- puts "Opening #{path}..."
127
-
128
- buffer = Ruby::Signature::Buffer.new(name: path, content: path.read)
129
- sigs = Ruby::Signature::Parser.parse_signature(buffer)
130
-
131
- sigs.each do |decl|
132
- case decl
133
- when Ruby::Signature::AST::Declarations::Constant
134
- puts " Importing documentation for #{decl.name}..."
135
- comment = comment_for_constant(decl, stores: stores)
136
- decl.instance_variable_set(:@comment, comment)
137
- when Ruby::Signature::AST::Declarations::Class, Ruby::Signature::AST::Declarations::Module
138
- puts " Importing documentation for #{decl.name}..."
139
- comment = comment_for_class(decl, stores: stores)
140
- decl.instance_variable_set(:@comment, comment)
141
-
142
- print_members stores, decl.name.to_s, decl.members
143
- when Ruby::Signature::AST::Declarations::Extension
144
- puts " Importing documentation for #{decl.name} (#{decl.extension_name})"
145
-
146
- print_members stores, decl.name.to_s, decl.members
147
- end
148
- end
149
-
150
- puts "Writing #{path}..."
151
- path.open('w') do |out|
152
- writer = Ruby::Signature::Writer.new(out: out)
153
- writer.write sigs
154
- end
155
- end
156
-
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "ruby/signature"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)