steep 0.13.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +28 -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 +33 -1
  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 +124 -89
  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/init.rb +5 -5
  17. data/lib/steep/drivers/langserver.rb +13 -287
  18. data/lib/steep/drivers/utils/driver_helper.rb +1 -1
  19. data/lib/steep/drivers/vendor.rb +2 -2
  20. data/lib/steep/drivers/watch.rb +97 -85
  21. data/lib/steep/drivers/worker.rb +51 -0
  22. data/lib/steep/project.rb +9 -5
  23. data/lib/steep/project/completion_provider.rb +298 -0
  24. data/lib/steep/project/dsl.rb +14 -0
  25. data/lib/steep/project/file.rb +54 -47
  26. data/lib/steep/project/hover_content.rb +17 -8
  27. data/lib/steep/project/options.rb +25 -3
  28. data/lib/steep/project/target.rb +40 -24
  29. data/lib/steep/server/base_worker.rb +56 -0
  30. data/lib/steep/server/code_worker.rb +151 -0
  31. data/lib/steep/server/interaction_worker.rb +281 -0
  32. data/lib/steep/server/master.rb +196 -0
  33. data/lib/steep/server/signature_worker.rb +148 -0
  34. data/lib/steep/server/utils.rb +36 -0
  35. data/lib/steep/server/worker_process.rb +62 -0
  36. data/lib/steep/signature/errors.rb +1 -1
  37. data/lib/steep/signature/validator.rb +13 -13
  38. data/lib/steep/source.rb +1 -1
  39. data/lib/steep/type_construction.rb +1004 -727
  40. data/lib/steep/type_inference/constant_env.rb +3 -11
  41. data/lib/steep/type_inference/context.rb +8 -3
  42. data/lib/steep/type_inference/context_array.rb +111 -0
  43. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  44. data/lib/steep/type_inference/logic.rb +130 -0
  45. data/lib/steep/type_inference/type_env.rb +5 -69
  46. data/lib/steep/typing.rb +91 -23
  47. data/lib/steep/version.rb +1 -1
  48. data/smoke/alias/Steepfile +1 -0
  49. data/smoke/alias/a.rb +1 -1
  50. data/smoke/and/Steepfile +1 -0
  51. data/smoke/array/Steepfile +1 -0
  52. data/smoke/array/b.rb +0 -2
  53. data/smoke/block/Steepfile +1 -0
  54. data/smoke/case/Steepfile +1 -0
  55. data/smoke/class/Steepfile +1 -0
  56. data/smoke/const/Steepfile +1 -0
  57. data/smoke/dstr/Steepfile +1 -0
  58. data/smoke/ensure/Steepfile +1 -0
  59. data/smoke/enumerator/Steepfile +1 -0
  60. data/smoke/extension/Steepfile +1 -0
  61. data/smoke/extension/c.rb +1 -0
  62. data/smoke/hash/Steepfile +1 -0
  63. data/smoke/hello/Steepfile +1 -0
  64. data/smoke/if/Steepfile +1 -0
  65. data/smoke/if/a.rb +1 -1
  66. data/smoke/implements/Steepfile +1 -0
  67. data/smoke/initialize/Steepfile +1 -0
  68. data/smoke/integer/Steepfile +1 -0
  69. data/smoke/interface/Steepfile +1 -0
  70. data/smoke/kwbegin/Steepfile +1 -0
  71. data/smoke/lambda/Steepfile +1 -0
  72. data/smoke/literal/Steepfile +1 -0
  73. data/smoke/map/Steepfile +1 -0
  74. data/smoke/method/Steepfile +1 -0
  75. data/smoke/module/Steepfile +1 -0
  76. data/smoke/regexp/Steepfile +1 -0
  77. data/smoke/regexp/b.rb +4 -4
  78. data/smoke/regression/Steepfile +1 -0
  79. data/smoke/rescue/Steepfile +1 -0
  80. data/smoke/rescue/a.rb +1 -1
  81. data/smoke/self/Steepfile +1 -0
  82. data/smoke/skip/Steepfile +1 -0
  83. data/smoke/stdout/Steepfile +1 -0
  84. data/smoke/super/Steepfile +1 -0
  85. data/smoke/type_case/Steepfile +1 -0
  86. data/smoke/yield/Steepfile +1 -0
  87. data/steep.gemspec +8 -8
  88. metadata +38 -138
  89. data/exe/rbs +0 -3
  90. data/exe/ruby-signature +0 -3
  91. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  92. data/vendor/ruby-signature/.gitignore +0 -12
  93. data/vendor/ruby-signature/.rubocop.yml +0 -15
  94. data/vendor/ruby-signature/BSDL +0 -22
  95. data/vendor/ruby-signature/COPYING +0 -56
  96. data/vendor/ruby-signature/Gemfile +0 -6
  97. data/vendor/ruby-signature/README.md +0 -93
  98. data/vendor/ruby-signature/Rakefile +0 -66
  99. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
  100. data/vendor/ruby-signature/bin/console +0 -14
  101. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  102. data/vendor/ruby-signature/bin/setup +0 -10
  103. data/vendor/ruby-signature/bin/sort +0 -88
  104. data/vendor/ruby-signature/bin/test_runner.rb +0 -17
  105. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  106. data/vendor/ruby-signature/docs/sigs.md +0 -148
  107. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  108. data/vendor/ruby-signature/docs/syntax.md +0 -528
  109. data/vendor/ruby-signature/exe/rbs +0 -3
  110. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  111. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
  112. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  113. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  114. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  115. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  116. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  117. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  118. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
  119. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  120. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  121. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  122. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  123. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  124. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  125. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  126. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  127. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  128. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  129. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  130. data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
  131. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
  132. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  133. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  134. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  135. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  136. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  137. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  138. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
  139. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
  140. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  141. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  142. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  143. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  144. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  145. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  146. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  147. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
  148. data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
  149. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
  150. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
  151. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  152. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  153. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  154. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
  155. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  156. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  157. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  158. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  159. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  160. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  161. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
  162. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
  163. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  164. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  165. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  166. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  167. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
  168. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  169. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  170. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  171. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
  172. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  173. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  174. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
  175. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  176. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
  177. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  178. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
  179. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
  180. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
  181. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
  182. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
  183. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
  184. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  185. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  186. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  187. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
  188. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
  189. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
  190. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  191. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  192. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
  193. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
  194. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  195. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  196. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
  197. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
  198. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  199. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
  200. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
  201. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  202. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
  203. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
  204. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  205. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
  206. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  207. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
  208. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
  209. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
  210. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  211. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  212. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  213. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
  214. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e95857ced793435c07c948b2a51ac914c52816811ae8e5d18337bcf946eb33d
4
- data.tar.gz: 9038e63999222be3e0b7172aa423056ef7792b905e1d277271fa795b6ca06889
3
+ metadata.gz: 551b6bb90b8fe98210d56cf53f62fb57e1bf0ce74e4c40ad931ddfe598507437
4
+ data.tar.gz: b01aed4e95d34dd6fad93fbeac1e5a427dbfa94e5ea9ce4130d2e89f14693159
5
5
  SHA512:
6
- metadata.gz: 2747b3e5f3303ae48a91e76b2256cd1e402e7022caa714083267da0820f1bce2d81188586e551a10158d4c6716ab7a8db8562aa84b31c98731872b08d05048c9
7
- data.tar.gz: 9d5bd44685d8228ee304bdaf94ae52e5eef2a2871580e7190ef941ea510406eab28bdb3aa6849fd9234649da10cd9344e2c38ba309a11a73cca70c6ed7e946e3
6
+ metadata.gz: 1e7aa1961819c9998182ef50ddd6d50c18985a9c2697715d35e062a069c87cd71bff416cb900a3bb3b5fff5c0a85970e3cb7f9e2183ca99656be6f87a4a4fdb5
7
+ data.tar.gz: 846810f3de6b4ec1a0e9f0a07ee3755c2e1258de6e7344339eef3e35b1912d6b591e36c55ef6e108f60c79a06ff9fed7ee940512ade80ba91bdab1a21e71bc28
@@ -1,3 +0,0 @@
1
- [submodule "vendor/ruby-signature"]
2
- path = vendor/ruby-signature
3
- url = https://github.com/ruby/ruby-signature.git
@@ -2,6 +2,34 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.16.2 (2020-05-27)
6
+
7
+ * Update gems ([144](https://github.com/soutaro/steep/pull/144), [145](https://github.com/soutaro/steep/pull/145))
8
+
9
+ ## 0.16.1 (2020-05-22)
10
+
11
+ * Fix constant resolution ([#143](https://github.com/soutaro/steep/pull/143))
12
+ * Fix RBS diagnostics line number in LSP ([142](https://github.com/soutaro/steep/pull/142))
13
+ * Fix crash caused by hover on `def` in LSP ([140](https://github.com/soutaro/steep/pull/140))
14
+
15
+ ## 0.16.0 (2020-05-19)
16
+
17
+ * Spawn workers for type check performance ([#137](https://github.com/soutaro/steep/pull/137))
18
+ * Fix `check` and `signature` methods in Steepfile ([8f3e4c7](https://github.com/soutaro/steep/pull/137/commits/8f3e4c75b29ac26920f02294be06d6c68dbd4dca))
19
+
20
+ ## 0.15.0 (2020-05-05)
21
+
22
+ * Add type checking configuration to dsl ([#132](https://github.com/soutaro/steep/pull/132))
23
+ * More flow sensitive type checking
24
+
25
+ ## 0.14.0 (2020-02-24)
26
+
27
+ * Implementat LSP _completion_. ([#119](https://github.com/soutaro/steep/pull/119))
28
+ * Update ruby-signature. ([#120](https://github.com/soutaro/steep/pull/120))
29
+ * Rescue errors during `langserver`. ([#121](https://github.com/soutaro/steep/pull/121))
30
+ * Pass hint when type checking `return`. ([#122](https://github.com/soutaro/steep/pull/122))
31
+ * Remove trailing spaces from Steepfile. ([#118](https://github.com/soutaro/steep/pull/118))
32
+
5
33
  ## 0.13.0 (2020-02-16)
6
34
 
7
35
  * Improve LSP _hover_ support. ([#117](https://github.com/soutaro/steep/pull/117))
data/Rakefile CHANGED
@@ -8,19 +8,6 @@ Rake::TestTask.new(:test) do |t|
8
8
  end
9
9
 
10
10
  task :default => :test
11
- task :build => :parser
12
- task :test => :parser
13
- task :install => [:reset, :parser]
14
-
15
- task :parser do
16
- Dir.chdir "vendor/ruby-signature" do
17
- sh "bundle exec rake parser"
18
- end
19
- end
20
-
21
- task :reset do
22
- sh "git submodule update -f --init"
23
- end
24
11
 
25
12
  task :smoke do
26
13
  sh "bundle", "exec", "bin/smoke_runner.rb", *Dir.glob("smoke/*")
data/bin/setup CHANGED
@@ -5,5 +5,3 @@ set -vx
5
5
 
6
6
  bundle install
7
7
 
8
- # Do any other automated setup that you need to do here
9
- bundle exec rake reset parser
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "pathname"
4
4
 
5
- $LOAD_PATH << Pathname(__dir__) + '../vendor/ruby-signature/lib'
6
5
  $LOAD_PATH << Pathname(__dir__) + "../lib"
7
6
 
8
7
  require "steep"
data/exe/steep CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'pathname'
4
4
 
5
- $LOAD_PATH << Pathname(__dir__) + "../vendor/ruby-signature/lib"
6
5
  $LOAD_PATH << Pathname(__dir__) + "../lib"
7
6
 
8
7
  require 'steep'
@@ -10,8 +10,10 @@ require "rainbow"
10
10
  require "listen"
11
11
  require 'pry'
12
12
  require 'language_server-protocol'
13
+ require "etc"
14
+ require "open3"
13
15
 
14
- require "ruby/signature"
16
+ require "rbs"
15
17
 
16
18
  require "steep/ast/namespace"
17
19
  require "steep/names"
@@ -61,12 +63,23 @@ require "steep/typing"
61
63
  require "steep/errors"
62
64
  require "steep/type_construction"
63
65
  require "steep/type_inference/context"
66
+ require "steep/type_inference/context_array"
64
67
  require "steep/type_inference/send_args"
65
68
  require "steep/type_inference/block_params"
66
69
  require "steep/type_inference/constant_env"
67
70
  require "steep/type_inference/type_env"
71
+ require "steep/type_inference/local_variable_type_env"
72
+ require "steep/type_inference/logic"
68
73
  require "steep/ast/types"
69
74
 
75
+ require "steep/server/utils"
76
+ require "steep/server/base_worker"
77
+ require "steep/server/code_worker"
78
+ require "steep/server/signature_worker"
79
+ require "steep/server/worker_process"
80
+ require "steep/server/interaction_worker"
81
+ require "steep/server/master"
82
+
70
83
  require "steep/project"
71
84
  require "steep/project/file"
72
85
  require "steep/project/options"
@@ -74,6 +87,7 @@ require "steep/project/target"
74
87
  require "steep/project/dsl"
75
88
  require "steep/project/file_loader"
76
89
  require "steep/project/hover_content"
90
+ require "steep/project/completion_provider"
77
91
  require "steep/drivers/utils/driver_helper"
78
92
  require "steep/drivers/check"
79
93
  require "steep/drivers/validate"
@@ -85,11 +99,14 @@ require "steep/drivers/trace_printer"
85
99
  require "steep/drivers/print_project"
86
100
  require "steep/drivers/init"
87
101
  require "steep/drivers/vendor"
102
+ require "steep/drivers/worker"
88
103
 
89
104
  if ENV["NO_COLOR"]
90
105
  Rainbow.enabled = false
91
106
  end
92
107
 
108
+ $stderr = STDERR
109
+
93
110
  module Steep
94
111
  def self.logger
95
112
  @logger
@@ -114,4 +131,19 @@ module Steep
114
131
 
115
132
  @logger = nil
116
133
  self.log_output = STDERR
134
+
135
+ def self.measure(message)
136
+ start = Time.now
137
+ yield.tap do
138
+ time = Time.now - start
139
+ self.logger.info "#{message} took #{time} seconds"
140
+ end
141
+ end
142
+
143
+ def self.log_error(exn, message: "Unexpected error: #{exn.inspect}")
144
+ Steep.logger.error message
145
+ exn.backtrace.each do |loc|
146
+ Steep.logger.warn " #{loc}"
147
+ end
148
+ end
117
149
  end
@@ -2,7 +2,7 @@ module Steep
2
2
  class AnnotationParser
3
3
  VAR_NAME = /[a-z][A-Za-z0-9_]*/
4
4
  METHOD_NAME = Regexp.union(
5
- /[A-Za-z][A-Za-z0-9_]*[?!]?/
5
+ /[^.:\s]+/
6
6
  )
7
7
  CONST_NAME = Regexp.union(
8
8
  /(::)?([A-Z][A-Za-z0-9_]*::)*[A-Z][A-Za-z0-9_]*/
@@ -34,7 +34,7 @@ module Steep
34
34
  TYPE_PARAMS = /(\[(?<params>#{PARAM}(,\s*#{PARAM})*)\])?/
35
35
 
36
36
  def parse_type(string)
37
- factory.type(Ruby::Signature::Parser.parse_type(string))
37
+ factory.type(RBS::Parser.parse_type(string))
38
38
  end
39
39
 
40
40
  # @type ${keyword} ${name}: ${type}
@@ -68,7 +68,7 @@ module Steep
68
68
  name = match[:name]
69
69
  type = match[:type]
70
70
 
71
- method_type = factory.method_type(Ruby::Signature::Parser.parse_method_type(type), self_type: AST::Types::Self.new)
71
+ method_type = factory.method_type(RBS::Parser.parse_method_type(type), self_type: AST::Types::Self.new)
72
72
 
73
73
  AST::Annotation::MethodType.new(name: name.to_sym,
74
74
  type: method_type,
@@ -160,7 +160,7 @@ module Steep
160
160
  end
161
161
  end
162
162
 
163
- rescue Ruby::Signature::Parser::SyntaxError, Ruby::Signature::Parser::SemanticsError => exn
163
+ rescue RBS::Parser::SyntaxError, RBS::Parser::SemanticsError => exn
164
164
  raise SyntaxError.new(source: src, location: location, exn: exn)
165
165
  end
166
166
  end
@@ -10,21 +10,25 @@ module Steep
10
10
  @name = name
11
11
  @content = content
12
12
 
13
- @lines = content.lines
13
+ @lines = content.split(/\n/, -1)
14
14
 
15
15
  @ranges = []
16
16
  offset = 0
17
- lines.each do |line|
18
- size = line.bytesize
19
- range = offset .. (offset+size)
20
- ranges << range
21
- offset += size
17
+ lines.each.with_index do |line, index|
18
+ if index == lines.size - 1
19
+ ranges << (offset..offset)
20
+ else
21
+ size = line.size
22
+ range = offset..(offset+size)
23
+ ranges << range
24
+ offset += size+1
25
+ end
22
26
  end
23
27
  end
24
28
 
25
29
  def pos_to_loc(pos)
26
30
  index = ranges.bsearch_index do |range|
27
- pos < range.end
31
+ pos <= range.end
28
32
  end
29
33
 
30
34
  if index
@@ -88,6 +88,14 @@ module Steep
88
88
  AST::Types::Boolean.new
89
89
  end
90
90
 
91
+ def self.bottom_type
92
+ AST::Types::Bot.new
93
+ end
94
+
95
+ def self.top_type
96
+ AST::Types::Top.new
97
+ end
98
+
91
99
  def self.optional(type)
92
100
  AST::Types::Union.build(types: [type, nil_type])
93
101
  end
@@ -10,56 +10,56 @@ module Steep
10
10
 
11
11
  def type(type)
12
12
  case type
13
- when Ruby::Signature::Types::Bases::Any
13
+ when RBS::Types::Bases::Any
14
14
  Any.new(location: nil)
15
- when Ruby::Signature::Types::Bases::Class
15
+ when RBS::Types::Bases::Class
16
16
  Class.new(location: nil)
17
- when Ruby::Signature::Types::Bases::Instance
17
+ when RBS::Types::Bases::Instance
18
18
  Instance.new(location: nil)
19
- when Ruby::Signature::Types::Bases::Self
19
+ when RBS::Types::Bases::Self
20
20
  Self.new(location: nil)
21
- when Ruby::Signature::Types::Bases::Top
21
+ when RBS::Types::Bases::Top
22
22
  Top.new(location: nil)
23
- when Ruby::Signature::Types::Bases::Bottom
23
+ when RBS::Types::Bases::Bottom
24
24
  Bot.new(location: nil)
25
- when Ruby::Signature::Types::Bases::Bool
25
+ when RBS::Types::Bases::Bool
26
26
  Boolean.new(location: nil)
27
- when Ruby::Signature::Types::Bases::Void
27
+ when RBS::Types::Bases::Void
28
28
  Void.new(location: nil)
29
- when Ruby::Signature::Types::Bases::Nil
29
+ when RBS::Types::Bases::Nil
30
30
  Nil.new(location: nil)
31
- when Ruby::Signature::Types::Variable
31
+ when RBS::Types::Variable
32
32
  Var.new(name: type.name, location: nil)
33
- when Ruby::Signature::Types::ClassSingleton
33
+ when RBS::Types::ClassSingleton
34
34
  type_name = type_name(type.name)
35
35
  Name::Class.new(name: type_name, location: nil, constructor: nil)
36
- when Ruby::Signature::Types::ClassInstance
36
+ when RBS::Types::ClassInstance
37
37
  type_name = type_name(type.name)
38
38
  args = type.args.map {|arg| type(arg) }
39
39
  Name::Instance.new(name: type_name, args: args, location: nil)
40
- when Ruby::Signature::Types::Interface
40
+ when RBS::Types::Interface
41
41
  type_name = type_name(type.name)
42
42
  args = type.args.map {|arg| type(arg) }
43
43
  Name::Interface.new(name: type_name, args: args, location: nil)
44
- when Ruby::Signature::Types::Alias
44
+ when RBS::Types::Alias
45
45
  type_name = type_name(type.name)
46
46
  Name::Alias.new(name: type_name, args: [], location: nil)
47
- when Ruby::Signature::Types::Union
47
+ when RBS::Types::Union
48
48
  Union.build(types: type.types.map {|ty| type(ty) }, location: nil)
49
- when Ruby::Signature::Types::Intersection
49
+ when RBS::Types::Intersection
50
50
  Intersection.build(types: type.types.map {|ty| type(ty) }, location: nil)
51
- when Ruby::Signature::Types::Optional
51
+ when RBS::Types::Optional
52
52
  Union.build(types: [type(type.type), Nil.new(location: nil)], location: nil)
53
- when Ruby::Signature::Types::Literal
53
+ when RBS::Types::Literal
54
54
  Literal.new(value: type.literal, location: nil)
55
- when Ruby::Signature::Types::Tuple
55
+ when RBS::Types::Tuple
56
56
  Tuple.new(types: type.types.map {|ty| type(ty) }, location: nil)
57
- when Ruby::Signature::Types::Record
57
+ when RBS::Types::Record
58
58
  elements = type.fields.each.with_object({}) do |(key, value), hash|
59
59
  hash[key] = type(value)
60
60
  end
61
61
  Record.new(elements: elements, location: nil)
62
- when Ruby::Signature::Types::Proc
62
+ when RBS::Types::Proc
63
63
  params = params(type.type)
64
64
  return_type = type(type.type.return_type)
65
65
  Proc.new(params: params, return_type: return_type, location: nil)
@@ -71,56 +71,56 @@ module Steep
71
71
  def type_1(type)
72
72
  case type
73
73
  when Any
74
- Ruby::Signature::Types::Bases::Any.new(location: nil)
74
+ RBS::Types::Bases::Any.new(location: nil)
75
75
  when Class
76
- Ruby::Signature::Types::Bases::Class.new(location: nil)
76
+ RBS::Types::Bases::Class.new(location: nil)
77
77
  when Instance
78
- Ruby::Signature::Types::Bases::Instance.new(location: nil)
78
+ RBS::Types::Bases::Instance.new(location: nil)
79
79
  when Self
80
- Ruby::Signature::Types::Bases::Self.new(location: nil)
80
+ RBS::Types::Bases::Self.new(location: nil)
81
81
  when Top
82
- Ruby::Signature::Types::Bases::Top.new(location: nil)
82
+ RBS::Types::Bases::Top.new(location: nil)
83
83
  when Bot
84
- Ruby::Signature::Types::Bases::Bottom.new(location: nil)
84
+ RBS::Types::Bases::Bottom.new(location: nil)
85
85
  when Boolean
86
- Ruby::Signature::Types::Bases::Bool.new(location: nil)
86
+ RBS::Types::Bases::Bool.new(location: nil)
87
87
  when Void
88
- Ruby::Signature::Types::Bases::Void.new(location: nil)
88
+ RBS::Types::Bases::Void.new(location: nil)
89
89
  when Nil
90
- Ruby::Signature::Types::Bases::Nil.new(location: nil)
90
+ RBS::Types::Bases::Nil.new(location: nil)
91
91
  when Var
92
- Ruby::Signature::Types::Variable.new(name: type.name, location: nil)
92
+ RBS::Types::Variable.new(name: type.name, location: nil)
93
93
  when Name::Class, Name::Module
94
- Ruby::Signature::Types::ClassSingleton.new(name: type_name_1(type.name), location: nil)
94
+ RBS::Types::ClassSingleton.new(name: type_name_1(type.name), location: nil)
95
95
  when Name::Instance
96
- Ruby::Signature::Types::ClassInstance.new(
96
+ RBS::Types::ClassInstance.new(
97
97
  name: type_name_1(type.name),
98
98
  args: type.args.map {|arg| type_1(arg) },
99
99
  location: nil
100
100
  )
101
101
  when Name::Interface
102
- Ruby::Signature::Types::Interface.new(
102
+ RBS::Types::Interface.new(
103
103
  name: type_name_1(type.name),
104
104
  args: type.args.map {|arg| type_1(arg) },
105
105
  location: nil
106
106
  )
107
107
  when Name::Alias
108
108
  type.args.empty? or raise "alias type with args is not supported"
109
- Ruby::Signature::Types::Alias.new(name: type_name_1(type.name), location: nil)
109
+ RBS::Types::Alias.new(name: type_name_1(type.name), location: nil)
110
110
  when Union
111
- Ruby::Signature::Types::Union.new(
111
+ RBS::Types::Union.new(
112
112
  types: type.types.map {|ty| type_1(ty) },
113
113
  location: nil
114
114
  )
115
115
  when Intersection
116
- Ruby::Signature::Types::Intersection.new(
116
+ RBS::Types::Intersection.new(
117
117
  types: type.types.map {|ty| type_1(ty) },
118
118
  location: nil
119
119
  )
120
120
  when Literal
121
- Ruby::Signature::Types::Literal.new(literal: type.value, location: nil)
121
+ RBS::Types::Literal.new(literal: type.value, location: nil)
122
122
  when Tuple
123
- Ruby::Signature::Types::Tuple.new(
123
+ RBS::Types::Tuple.new(
124
124
  types: type.types.map {|ty| type_1(ty) },
125
125
  location: nil
126
126
  )
@@ -128,9 +128,9 @@ module Steep
128
128
  fields = type.elements.each.with_object({}) do |(key, value), hash|
129
129
  hash[key] = type_1(value)
130
130
  end
131
- Ruby::Signature::Types::Record.new(fields: fields, location: nil)
131
+ RBS::Types::Record.new(fields: fields, location: nil)
132
132
  when Proc
133
- Ruby::Signature::Types::Proc.new(
133
+ RBS::Types::Proc.new(
134
134
  type: function_1(type.params, type.return_type),
135
135
  location: nil
136
136
  )
@@ -151,7 +151,7 @@ module Steep
151
151
  end
152
152
 
153
153
  def type_name_1(name)
154
- Ruby::Signature::TypeName.new(name: name.name, namespace: namespace_1(name.namespace))
154
+ RBS::TypeName.new(name: name.name, namespace: namespace_1(name.namespace))
155
155
  end
156
156
 
157
157
  def namespace(namespace)
@@ -159,18 +159,18 @@ module Steep
159
159
  end
160
160
 
161
161
  def namespace_1(namespace)
162
- Ruby::Signature::Namespace.parse(namespace.to_s)
162
+ RBS::Namespace.parse(namespace.to_s)
163
163
  end
164
164
 
165
165
  def function_1(params, return_type)
166
- Ruby::Signature::Types::Function.new(
167
- required_positionals: params.required.map {|type| Ruby::Signature::Types::Function::Param.new(name: nil, type: type_1(type)) },
168
- optional_positionals: params.optional.map {|type| Ruby::Signature::Types::Function::Param.new(name: nil, type: type_1(type)) },
169
- rest_positionals: params.rest&.yield_self {|type| Ruby::Signature::Types::Function::Param.new(name: nil, type: type_1(type)) },
166
+ RBS::Types::Function.new(
167
+ required_positionals: params.required.map {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
168
+ optional_positionals: params.optional.map {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
169
+ rest_positionals: params.rest&.yield_self {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
170
170
  trailing_positionals: [],
171
- required_keywords: params.required_keywords.transform_values {|type| Ruby::Signature::Types::Function::Param.new(name: nil, type: type_1(type)) },
172
- optional_keywords: params.optional_keywords.transform_values {|type| Ruby::Signature::Types::Function::Param.new(name: nil, type: type_1(type)) },
173
- rest_keywords: params.rest_keywords&.yield_self {|type| Ruby::Signature::Types::Function::Param.new(name: nil, type: type_1(type)) },
171
+ required_keywords: params.required_keywords.transform_values {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
172
+ optional_keywords: params.optional_keywords.transform_values {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
173
+ rest_keywords: params.rest_keywords&.yield_self {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
174
174
  return_type: type_1(return_type)
175
175
  )
176
176
  end
@@ -187,47 +187,82 @@ module Steep
187
187
  end
188
188
 
189
189
  def method_type(method_type, self_type:)
190
- case method_type
191
- when Ruby::Signature::MethodType
192
- fvs = self_type.free_variables()
193
-
194
- type_params = []
195
- alpha_vars = []
196
- alpha_types = []
197
-
198
- method_type.type_params.map do |name|
199
- if fvs.include?(name)
200
- type = Types::Var.fresh(name)
201
- alpha_vars << name
202
- alpha_types << type
203
- type_params << type.name
204
- else
205
- type_params << name
206
- end
190
+ fvs = self_type.free_variables()
191
+
192
+ type_params = []
193
+ alpha_vars = []
194
+ alpha_types = []
195
+
196
+ method_type.type_params.map do |name|
197
+ if fvs.include?(name)
198
+ type = Types::Var.fresh(name)
199
+ alpha_vars << name
200
+ alpha_types << type
201
+ type_params << type.name
202
+ else
203
+ type_params << name
207
204
  end
208
- subst = Interface::Substitution.build(alpha_vars, alpha_types)
209
-
210
- type = Interface::MethodType.new(
211
- type_params: type_params,
212
- return_type: type(method_type.type.return_type).subst(subst),
213
- params: params(method_type.type).subst(subst),
214
- location: nil,
215
- block: method_type.block&.yield_self do |block|
216
- Interface::Block.new(
217
- optional: !block.required,
218
- type: Proc.new(params: params(block.type).subst(subst),
219
- return_type: type(block.type.return_type).subst(subst), location: nil)
220
- )
221
- end
222
- )
205
+ end
206
+ subst = Interface::Substitution.build(alpha_vars, alpha_types)
207
+
208
+ type = Interface::MethodType.new(
209
+ type_params: type_params,
210
+ return_type: type(method_type.type.return_type).subst(subst),
211
+ params: params(method_type.type).subst(subst),
212
+ location: nil,
213
+ block: method_type.block&.yield_self do |block|
214
+ Interface::Block.new(
215
+ optional: !block.required,
216
+ type: Proc.new(params: params(block.type).subst(subst),
217
+ return_type: type(block.type.return_type).subst(subst), location: nil)
218
+ )
219
+ end
220
+ )
221
+
222
+ if block_given?
223
+ yield type
224
+ else
225
+ type
226
+ end
227
+ end
228
+
229
+ def method_type_1(method_type, self_type:)
230
+ fvs = self_type.free_variables()
223
231
 
224
- if block_given?
225
- yield type
232
+ type_params = []
233
+ alpha_vars = []
234
+ alpha_types = []
235
+
236
+ method_type.type_params.map do |name|
237
+ if fvs.include?(name)
238
+ type = RBS::Types::Variable.new(name: name, location: nil),
239
+ alpha_vars << name
240
+ alpha_types << type
241
+ type_params << type.name
226
242
  else
227
- type
243
+ type_params << name
228
244
  end
229
- when :any
230
- :any
245
+ end
246
+ subst = Interface::Substitution.build(alpha_vars, alpha_types)
247
+
248
+ type = RBS::MethodType.new(
249
+ type_params: type_params,
250
+ type: function_1(method_type.params.subst(subst), method_type.return_type.subst(subst)),
251
+ block: method_type.block&.yield_self do |block|
252
+ block_type = block.type.subst(subst)
253
+
254
+ RBS::MethodType::Block.new(
255
+ type: function_1(block_type.params, block_type.return_type),
256
+ required: !block.optional
257
+ )
258
+ end,
259
+ location: nil
260
+ )
261
+
262
+ if block_given?
263
+ yield type
264
+ else
265
+ type
231
266
  end
232
267
  end
233
268
 
@@ -508,12 +543,12 @@ module Steep
508
543
 
509
544
  def module_name?(type_name)
510
545
  name = type_name_1(type_name)
511
- env.class?(name) && env.find_class(name).is_a?(Ruby::Signature::AST::Declarations::Module)
546
+ env.class?(name) && env.find_class(name).is_a?(RBS::AST::Declarations::Module)
512
547
  end
513
548
 
514
549
  def class_name?(type_name)
515
550
  name = type_name_1(type_name)
516
- env.class?(name) && env.find_class(name).is_a?(Ruby::Signature::AST::Declarations::Class)
551
+ env.class?(name) && env.find_class(name).is_a?(RBS::AST::Declarations::Class)
517
552
  end
518
553
 
519
554
  def env