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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86924db409406024edb29a087196304bacba8730dfa3c986c604fbe8b6b9a6fd
4
- data.tar.gz: d688f6b2f58343da51328f13bc26da7e4e54de7f1dd9393f0cd98d48c5ea8420
3
+ metadata.gz: 2b1c04c7f20a2ed355b58570363447b3e8f2bd1710407de1e23c7b9fbe279cb8
4
+ data.tar.gz: 62101db41144f3fd218ee8478ab377f3414ad1d8a7689ac73356aa28bf7f6842
5
5
  SHA512:
6
- metadata.gz: a70b109afc79267f2a47425dcc8b93f05074fbffa1e410fa62824b5a94320f18a9274182ad2fbaa4083867dd0bab9e4e8796fc8b472edd2328d2b332e76f9f66
7
- data.tar.gz: 6b4dc08b74b0f042b325180f1b358862d510fefe06a9e07f06380bbf7e86f47e3547d365d0cc94a278c80946befec64689a5c56e87a3e820db767103727e69f7
6
+ metadata.gz: d8ac130b1adb7755709f4b1590939b442d6d4b4aa5ea38a95423db539a1b52b0c4078abf1a543b92a84477d99846d5ab30060dc26c693f52785de0c205041a2d
7
+ data.tar.gz: e7ccec14707e49d51b88429ab0922c4e6fbbc190bbafb0e107c30ea681b04415245e40708909fd28458a89a565a816fd88a6bfa1c14b76e24185a2ece153148c
@@ -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,31 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.16.3
6
+
7
+ * Fix `steep watch` ([#147](https://github.com/soutaro/steep/pull/147))
8
+ * Stop using pry ([#148](https://github.com/soutaro/steep/pull/148))
9
+
10
+ ## 0.16.2 (2020-05-27)
11
+
12
+ * Update gems ([#144](https://github.com/soutaro/steep/pull/144), [#145](https://github.com/soutaro/steep/pull/145))
13
+
14
+ ## 0.16.1 (2020-05-22)
15
+
16
+ * Fix constant resolution ([#143](https://github.com/soutaro/steep/pull/143))
17
+ * Fix RBS diagnostics line number in LSP ([#142](https://github.com/soutaro/steep/pull/142))
18
+ * Fix crash caused by hover on `def` in LSP ([#140](https://github.com/soutaro/steep/pull/140))
19
+
20
+ ## 0.16.0 (2020-05-19)
21
+
22
+ * Spawn workers for type check performance ([#137](https://github.com/soutaro/steep/pull/137))
23
+ * Fix `check` and `signature` methods in Steepfile ([8f3e4c7](https://github.com/soutaro/steep/pull/137/commits/8f3e4c75b29ac26920f02294be06d6c68dbd4dca))
24
+
25
+ ## 0.15.0 (2020-05-05)
26
+
27
+ * Add type checking configuration to dsl ([#132](https://github.com/soutaro/steep/pull/132))
28
+ * More flow sensitive type checking
29
+
5
30
  ## 0.14.0 (2020-02-24)
6
31
 
7
32
  * Implementat LSP _completion_. ([#119](https://github.com/soutaro/steep/pull/119))
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'
@@ -8,10 +8,12 @@ require "logger"
8
8
  require "active_support/tagged_logging"
9
9
  require "rainbow"
10
10
  require "listen"
11
- require 'pry'
12
11
  require 'language_server-protocol'
12
+ require "etc"
13
+ require "open3"
14
+ require "stringio"
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"
@@ -86,11 +99,14 @@ require "steep/drivers/trace_printer"
86
99
  require "steep/drivers/print_project"
87
100
  require "steep/drivers/init"
88
101
  require "steep/drivers/vendor"
102
+ require "steep/drivers/worker"
89
103
 
90
104
  if ENV["NO_COLOR"]
91
105
  Rainbow.enabled = false
92
106
  end
93
107
 
108
+ $stderr = STDERR
109
+
94
110
  module Steep
95
111
  def self.logger
96
112
  @logger
@@ -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
@@ -235,7 +235,7 @@ module Steep
235
235
 
236
236
  method_type.type_params.map do |name|
237
237
  if fvs.include?(name)
238
- type = Ruby::Signature::Types::Variable.new(name: name, location: nil),
238
+ type = RBS::Types::Variable.new(name: name, location: nil),
239
239
  alpha_vars << name
240
240
  alpha_types << type
241
241
  type_params << type.name
@@ -245,13 +245,13 @@ module Steep
245
245
  end
246
246
  subst = Interface::Substitution.build(alpha_vars, alpha_types)
247
247
 
248
- type = Ruby::Signature::MethodType.new(
248
+ type = RBS::MethodType.new(
249
249
  type_params: type_params,
250
250
  type: function_1(method_type.params.subst(subst), method_type.return_type.subst(subst)),
251
251
  block: method_type.block&.yield_self do |block|
252
252
  block_type = block.type.subst(subst)
253
253
 
254
- Ruby::Signature::MethodType::Block.new(
254
+ RBS::MethodType::Block.new(
255
255
  type: function_1(block_type.params, block_type.return_type),
256
256
  required: !block.optional
257
257
  )
@@ -543,12 +543,12 @@ module Steep
543
543
 
544
544
  def module_name?(type_name)
545
545
  name = type_name_1(type_name)
546
- 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)
547
547
  end
548
548
 
549
549
  def class_name?(type_name)
550
550
  name = type_name_1(type_name)
551
- 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)
552
552
  end
553
553
 
554
554
  def env