steep 0.39.0 → 0.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/CHANGELOG.md +37 -0
  4. data/Rakefile +5 -2
  5. data/bin/output_rebaseline.rb +34 -0
  6. data/bin/output_test.rb +53 -0
  7. data/lib/steep.rb +95 -17
  8. data/lib/steep/annotation_parser.rb +10 -2
  9. data/lib/steep/ast/types/class.rb +4 -0
  10. data/lib/steep/cli.rb +32 -7
  11. data/lib/steep/diagnostic/helper.rb +17 -0
  12. data/lib/steep/diagnostic/lsp_formatter.rb +16 -0
  13. data/lib/steep/diagnostic/ruby.rb +628 -0
  14. data/lib/steep/diagnostic/signature.rb +374 -0
  15. data/lib/steep/drivers/annotations.rb +19 -30
  16. data/lib/steep/drivers/check.rb +191 -59
  17. data/lib/steep/drivers/diagnostic_printer.rb +103 -0
  18. data/lib/steep/drivers/langserver.rb +4 -8
  19. data/lib/steep/drivers/print_project.rb +10 -9
  20. data/lib/steep/drivers/stats.rb +168 -56
  21. data/lib/steep/drivers/trace_printer.rb +5 -1
  22. data/lib/steep/drivers/utils/driver_helper.rb +35 -0
  23. data/lib/steep/drivers/utils/jobs_count.rb +9 -0
  24. data/lib/steep/drivers/validate.rb +31 -13
  25. data/lib/steep/drivers/watch.rb +74 -51
  26. data/lib/steep/drivers/worker.rb +16 -8
  27. data/lib/steep/expectations.rb +159 -0
  28. data/lib/steep/index/signature_symbol_provider.rb +23 -1
  29. data/lib/steep/project.rb +0 -30
  30. data/lib/steep/project/dsl.rb +5 -3
  31. data/lib/steep/project/options.rb +4 -4
  32. data/lib/steep/project/pattern.rb +56 -0
  33. data/lib/steep/project/target.rb +11 -216
  34. data/lib/steep/range_extension.rb +29 -0
  35. data/lib/steep/server/base_worker.rb +43 -7
  36. data/lib/steep/server/change_buffer.rb +63 -0
  37. data/lib/steep/server/interaction_worker.rb +72 -56
  38. data/lib/steep/server/master.rb +695 -112
  39. data/lib/steep/server/type_check_worker.rb +236 -0
  40. data/lib/steep/server/worker_process.rb +22 -17
  41. data/lib/steep/{project → services}/completion_provider.rb +5 -5
  42. data/lib/steep/services/content_change.rb +61 -0
  43. data/lib/steep/services/file_loader.rb +48 -0
  44. data/lib/steep/{project → services}/hover_content.rb +19 -20
  45. data/lib/steep/services/path_assignment.rb +27 -0
  46. data/lib/steep/services/signature_service.rb +403 -0
  47. data/lib/steep/services/stats_calculator.rb +69 -0
  48. data/lib/steep/services/type_check_service.rb +388 -0
  49. data/lib/steep/signature/validator.rb +187 -61
  50. data/lib/steep/source.rb +21 -18
  51. data/lib/steep/subtyping/check.rb +246 -45
  52. data/lib/steep/subtyping/constraints.rb +4 -4
  53. data/lib/steep/type_construction.rb +627 -355
  54. data/lib/steep/type_inference/block_params.rb +1 -1
  55. data/lib/steep/type_inference/context.rb +22 -0
  56. data/lib/steep/type_inference/local_variable_type_env.rb +26 -12
  57. data/lib/steep/type_inference/logic.rb +1 -1
  58. data/lib/steep/type_inference/logic_type_interpreter.rb +4 -4
  59. data/lib/steep/type_inference/type_env.rb +43 -17
  60. data/lib/steep/version.rb +1 -1
  61. data/smoke/alias/a.rb +0 -3
  62. data/smoke/alias/b.rb +0 -1
  63. data/smoke/alias/c.rb +0 -2
  64. data/smoke/alias/test_expectations.yml +96 -0
  65. data/smoke/and/a.rb +0 -3
  66. data/smoke/and/test_expectations.yml +31 -0
  67. data/smoke/array/a.rb +0 -3
  68. data/smoke/array/b.rb +0 -2
  69. data/smoke/array/c.rb +0 -1
  70. data/smoke/array/test_expectations.yml +103 -0
  71. data/smoke/block/a.rb +0 -2
  72. data/smoke/block/b.rb +0 -2
  73. data/smoke/block/d.rb +0 -4
  74. data/smoke/block/test_expectations.yml +125 -0
  75. data/smoke/case/a.rb +0 -3
  76. data/smoke/case/test_expectations.yml +47 -0
  77. data/smoke/class/a.rb +0 -3
  78. data/smoke/class/c.rb +0 -1
  79. data/smoke/class/f.rb +0 -1
  80. data/smoke/class/g.rb +0 -2
  81. data/smoke/class/i.rb +0 -2
  82. data/smoke/class/test_expectations.yml +120 -0
  83. data/smoke/const/a.rb +0 -3
  84. data/smoke/const/b.rb +7 -0
  85. data/smoke/const/b.rbs +5 -0
  86. data/smoke/const/test_expectations.yml +139 -0
  87. data/smoke/diagnostics-rbs-duplicated/Steepfile +5 -0
  88. data/smoke/diagnostics-rbs-duplicated/a.rbs +5 -0
  89. data/smoke/diagnostics-rbs-duplicated/test_expectations.yml +13 -0
  90. data/smoke/diagnostics-rbs/Steepfile +8 -0
  91. data/smoke/diagnostics-rbs/duplicated-method-definition.rbs +20 -0
  92. data/smoke/diagnostics-rbs/generic-parameter-mismatch.rbs +7 -0
  93. data/smoke/diagnostics-rbs/invalid-method-overload.rbs +3 -0
  94. data/smoke/diagnostics-rbs/invalid-type-application.rbs +7 -0
  95. data/smoke/diagnostics-rbs/invalid_variance_annotation.rbs +3 -0
  96. data/smoke/diagnostics-rbs/recursive-alias.rbs +5 -0
  97. data/smoke/diagnostics-rbs/recursive-class.rbs +8 -0
  98. data/smoke/diagnostics-rbs/superclass-mismatch.rbs +7 -0
  99. data/smoke/diagnostics-rbs/test_expectations.yml +231 -0
  100. data/smoke/diagnostics-rbs/unknown-method-alias.rbs +3 -0
  101. data/smoke/diagnostics-rbs/unknown-type-name-2.rbs +5 -0
  102. data/smoke/diagnostics-rbs/unknown-type-name.rbs +13 -0
  103. data/smoke/diagnostics/Steepfile +5 -0
  104. data/smoke/diagnostics/a.rbs +26 -0
  105. data/smoke/diagnostics/argument_type_mismatch.rb +1 -0
  106. data/smoke/diagnostics/block_body_type_mismatch.rb +1 -0
  107. data/smoke/diagnostics/block_type_mismatch.rb +3 -0
  108. data/smoke/diagnostics/break_type_mismatch.rb +1 -0
  109. data/smoke/diagnostics/else_on_exhaustive_case.rb +12 -0
  110. data/smoke/diagnostics/incompatible_annotation.rb +6 -0
  111. data/smoke/diagnostics/incompatible_argument.rb +1 -0
  112. data/smoke/diagnostics/incompatible_assignment.rb +8 -0
  113. data/smoke/diagnostics/method_arity_mismatch.rb +11 -0
  114. data/smoke/diagnostics/method_body_type_mismatch.rb +6 -0
  115. data/smoke/diagnostics/method_definition_missing.rb +2 -0
  116. data/smoke/diagnostics/method_return_type_annotation_mismatch.rb +7 -0
  117. data/smoke/diagnostics/missing_keyword.rb +1 -0
  118. data/smoke/diagnostics/no_method.rb +1 -0
  119. data/smoke/diagnostics/required_block_missing.rb +1 -0
  120. data/smoke/diagnostics/return_type_mismatch.rb +6 -0
  121. data/smoke/diagnostics/test_expectations.yml +477 -0
  122. data/smoke/diagnostics/unexpected_block_given.rb +1 -0
  123. data/smoke/diagnostics/unexpected_dynamic_method.rb +3 -0
  124. data/smoke/diagnostics/unexpected_jump.rb +4 -0
  125. data/smoke/diagnostics/unexpected_jump_value.rb +3 -0
  126. data/smoke/diagnostics/unexpected_keyword.rb +1 -0
  127. data/smoke/diagnostics/unexpected_splat.rb +1 -0
  128. data/smoke/diagnostics/unexpected_yield.rb +6 -0
  129. data/smoke/diagnostics/unknown_constant_assigned.rb +7 -0
  130. data/smoke/diagnostics/unresolved_overloading.rb +1 -0
  131. data/smoke/diagnostics/unsatisfiable_constraint.rb +7 -0
  132. data/smoke/diagnostics/unsupported_syntax.rb +2 -0
  133. data/smoke/dstr/a.rb +0 -1
  134. data/smoke/dstr/test_expectations.yml +13 -0
  135. data/smoke/ensure/a.rb +0 -4
  136. data/smoke/ensure/test_expectations.yml +62 -0
  137. data/smoke/enumerator/a.rb +0 -6
  138. data/smoke/enumerator/b.rb +0 -3
  139. data/smoke/enumerator/test_expectations.yml +135 -0
  140. data/smoke/extension/a.rb +0 -1
  141. data/smoke/extension/b.rb +0 -2
  142. data/smoke/extension/c.rb +0 -1
  143. data/smoke/extension/f.rb +2 -0
  144. data/smoke/extension/f.rbs +3 -0
  145. data/smoke/extension/test_expectations.yml +73 -0
  146. data/smoke/hash/b.rb +0 -1
  147. data/smoke/hash/c.rb +0 -3
  148. data/smoke/hash/d.rb +0 -1
  149. data/smoke/hash/e.rb +0 -1
  150. data/smoke/hash/test_expectations.yml +81 -0
  151. data/smoke/hello/hello.rb +0 -2
  152. data/smoke/hello/test_expectations.yml +25 -0
  153. data/smoke/if/a.rb +0 -2
  154. data/smoke/if/test_expectations.yml +34 -0
  155. data/smoke/implements/a.rb +0 -2
  156. data/smoke/implements/b.rb +13 -0
  157. data/smoke/implements/b.rbs +12 -0
  158. data/smoke/implements/test_expectations.yml +23 -0
  159. data/smoke/initialize/test_expectations.yml +1 -0
  160. data/smoke/integer/a.rb +0 -7
  161. data/smoke/integer/test_expectations.yml +101 -0
  162. data/smoke/interface/a.rb +0 -2
  163. data/smoke/interface/test_expectations.yml +23 -0
  164. data/smoke/kwbegin/a.rb +0 -1
  165. data/smoke/kwbegin/test_expectations.yml +17 -0
  166. data/smoke/lambda/a.rb +1 -4
  167. data/smoke/lambda/test_expectations.yml +39 -0
  168. data/smoke/literal/a.rb +0 -5
  169. data/smoke/literal/b.rb +0 -2
  170. data/smoke/literal/test_expectations.yml +106 -0
  171. data/smoke/map/test_expectations.yml +1 -0
  172. data/smoke/method/a.rb +0 -5
  173. data/smoke/method/b.rb +0 -1
  174. data/smoke/method/test_expectations.yml +90 -0
  175. data/smoke/module/a.rb +0 -2
  176. data/smoke/module/b.rb +0 -2
  177. data/smoke/module/c.rb +0 -1
  178. data/smoke/module/d.rb +0 -1
  179. data/smoke/module/f.rb +0 -2
  180. data/smoke/module/test_expectations.yml +75 -0
  181. data/smoke/regexp/a.rb +0 -38
  182. data/smoke/regexp/b.rb +0 -26
  183. data/smoke/regexp/test_expectations.yml +615 -0
  184. data/smoke/regression/issue_328.rb +1 -0
  185. data/smoke/regression/issue_328.rbs +0 -0
  186. data/smoke/regression/issue_332.rb +11 -0
  187. data/smoke/regression/issue_332.rbs +19 -0
  188. data/smoke/regression/masgn.rb +4 -0
  189. data/smoke/regression/set_divide.rb +0 -4
  190. data/smoke/regression/test_expectations.yml +72 -0
  191. data/smoke/regression/thread.rb +7 -0
  192. data/smoke/rescue/a.rb +0 -5
  193. data/smoke/rescue/test_expectations.yml +79 -0
  194. data/smoke/self/a.rb +0 -2
  195. data/smoke/self/test_expectations.yml +23 -0
  196. data/smoke/skip/skip.rb +0 -2
  197. data/smoke/skip/test_expectations.yml +23 -0
  198. data/smoke/stdout/test_expectations.yml +1 -0
  199. data/smoke/super/a.rb +0 -4
  200. data/smoke/super/test_expectations.yml +69 -0
  201. data/smoke/toplevel/a.rb +0 -1
  202. data/smoke/toplevel/test_expectations.yml +15 -0
  203. data/smoke/tsort/Steepfile +2 -0
  204. data/smoke/tsort/a.rb +0 -3
  205. data/smoke/tsort/test_expectations.yml +63 -0
  206. data/smoke/type_case/a.rb +0 -4
  207. data/smoke/type_case/test_expectations.yml +48 -0
  208. data/smoke/unexpected/Steepfile +5 -0
  209. data/smoke/unexpected/test_expectations.yml +25 -0
  210. data/smoke/unexpected/unexpected.rb +1 -0
  211. data/smoke/unexpected/unexpected.rbs +3 -0
  212. data/smoke/yield/a.rb +0 -3
  213. data/smoke/yield/b.rb +6 -0
  214. data/smoke/yield/test_expectations.yml +68 -0
  215. data/steep.gemspec +5 -4
  216. metadata +174 -42
  217. data/bin/smoke_runner.rb +0 -139
  218. data/lib/steep/drivers/signature_error_printer.rb +0 -25
  219. data/lib/steep/errors.rb +0 -594
  220. data/lib/steep/project/file_loader.rb +0 -68
  221. data/lib/steep/project/signature_file.rb +0 -33
  222. data/lib/steep/project/source_file.rb +0 -129
  223. data/lib/steep/server/code_worker.rb +0 -137
  224. data/lib/steep/server/signature_worker.rb +0 -209
  225. data/lib/steep/server/utils.rb +0 -69
  226. data/lib/steep/signature/errors.rb +0 -128
  227. data/lib/steep/type_assignability.rb +0 -367
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33c89b6005654ebdc947af336b1c7fa47e02c45c480d27b9f4ef0ab6d3403dd1
4
- data.tar.gz: be7b7812e1ba321b91680884fccc55fd57dd5836c89bf7817624b72706490d6e
3
+ metadata.gz: 7af0aaa9c4c7b0dd2bae9104603131370d976133d866e3d7760c4b2fa581e694
4
+ data.tar.gz: eb1421e3b07c1f06e427073bb72d55138eda935e2269874f5727eecb035a00fb
5
5
  SHA512:
6
- metadata.gz: 36945eb5fe4a04061c87bc76488c65ef2b009fcdb8279fd542a1249a10a223cd9571371f333e4ec29870a66dd120c4d9e65d572a9d3c90d56dba5c2c1dd95761
7
- data.tar.gz: d9c2e56878f06d71edeb9a10b275c19afd7ba42b1af16ef01ef890ca3791ad4f92f903f7679fcf77b310638b0d0f5fced596e094ec225ff2f567e0f063bfc527
6
+ metadata.gz: 815776632903ca2679af4ae7e7b4a22fa4388956b56706b862f21d76bea6edbbb928d8423504a99a352db71bf7d777e1148a57fe803b582814f1f1526cc45358
7
+ data.tar.gz: 70839258fe699f8b246b66cf5e865cb33a9231b5d34e12b40f880bc6b3c50566fe53e0df74645785a3bf1091cbbe34ad4e216ac9d37fdcc3bb3ef32532ab5363
@@ -16,7 +16,7 @@ jobs:
16
16
  - 2.7.0-bionic
17
17
  task:
18
18
  - test
19
- - smoke
19
+ - test:output
20
20
  - build
21
21
  container:
22
22
  image: rubylang/ruby:${{ matrix.container_tag }}
data/CHANGELOG.md CHANGED
@@ -2,6 +2,43 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.43.1 (2021-04-01)
6
+
7
+ * Fix LSP `textDocument/didSave` notification handling ([#368](https://github.com/soutaro/steep/issues/368))
8
+
9
+ ## 0.43.0 (2021-03-30)
10
+
11
+ * LSP responsiveness improvements ([\#352](https://github.com/soutaro/steep/issues/352))
12
+ * `@implements` annotation in blocks ([#338](https://github.com/soutaro/steep/issues/338))
13
+ * Better `steep stats` table formatting ([\#300](https://github.com/soutaro/steep/issues/300))
14
+ * Fix retry type checking ([\#293](https://github.com/soutaro/steep/issues/293))
15
+ * Better tuple type checking ([\#328](https://github.com/soutaro/steep/issues/328))
16
+ * Fix unexpected `add_call` error ([\#358](https://github.com/soutaro/steep/pull/358))
17
+ * Ignore passing nil as a block `&nil` ([\#356](https://github.com/soutaro/steep/pull/356))
18
+ * Better type checking for non-trivial block parameters ([\#354](https://github.com/soutaro/steep/pull/354))
19
+ * Avoid unexpected error on splat assignments ([\#330](https://github.com/soutaro/steep/pull/330))
20
+ * Fix constraint solver ([\#343](https://github.com/soutaro/steep/pull/343))
21
+ * Ruby 2.7 compatible private method call typing ([\#344](https://github.com/soutaro/steep/pull/344))
22
+
23
+ ## 0.42.0 (2021-03-08)
24
+
25
+ * Type checking performance improvement ([\#309](https://github.com/soutaro/steep/pull/309), [\#311](https://github.com/soutaro/steep/pull/311), [\#312](https://github.com/soutaro/steep/pull/312), [\#313](https://github.com/soutaro/steep/pull/313), [\#314](https://github.com/soutaro/steep/pull/314), [\#315](https://github.com/soutaro/steep/pull/315), [\#316](https://github.com/soutaro/steep/pull/316), [\#320](https://github.com/soutaro/steep/pull/320), [\#322](https://github.com/soutaro/steep/pull/322))
26
+ * Let `watch` command support files ([\#323](https://github.com/soutaro/steep/pull/323))
27
+ * Validate _module-self-type_ constraints ([\#308](https://github.com/soutaro/steep/pull/308))
28
+ * Add `-j` option to specify number of worker processes ([\#318](https://github.com/soutaro/steep/pull/318), [\#325](https://github.com/soutaro/steep/pull/325))
29
+ * Fix `code` of RBS diagnostics ([\#306](https://github.com/soutaro/steep/pull/306))
30
+ * Skip printing source code from out of date _expectations_ file ([\#305](https://github.com/soutaro/steep/pull/305))
31
+
32
+ ## 0.41.0 (2021-02-07)
33
+
34
+ * Add `--with-expectations` and `--save-expectations` option ([#303](https://github.com/soutaro/steep/pull/303))
35
+
36
+ ## 0.40.0 (2021-01-31)
37
+
38
+ * Report progress with dots ([#287](https://github.com/soutaro/steep/pull/287))
39
+ * Diagnostics message improvements ([#297](https://github.com/soutaro/steep/pull/297), [#301](https://github.com/soutaro/steep/pull/301))
40
+ * Fix error on implicit `to_proc` syntax when `untyped` is yielded ([#291](https://github.com/soutaro/steep/pull/291))
41
+
5
42
  ## 0.39.0 (2020-12-25)
6
43
 
7
44
  * Update RBS to 1.0.0 ([#282](https://github.com/soutaro/steep/pull/282))
data/Rakefile CHANGED
@@ -9,6 +9,9 @@ end
9
9
 
10
10
  task :default => :test
11
11
 
12
- task :smoke do
13
- sh "bundle", "exec", "bin/smoke_runner.rb", *Dir.glob("smoke/*")
12
+ namespace :test do
13
+ desc "Run output test"
14
+ task :output do
15
+ sh "ruby", "bin/output_test.rb"
16
+ end
14
17
  end
@@ -0,0 +1,34 @@
1
+ require "pathname"
2
+ require "yaml"
3
+ require "open3"
4
+ require "tempfile"
5
+
6
+ if ARGV.empty?
7
+ test_dirs = (Pathname(__dir__) + "../smoke").children
8
+ else
9
+ test_dirs = ARGV.map {|p| Pathname.pwd + p }
10
+ end
11
+
12
+ failed_tests = []
13
+
14
+ test_dirs.each do |dir|
15
+ puts "Rebaselining #{dir}..."
16
+
17
+ command = %w(steep check --save-expectations=test_expectations.yml)
18
+ puts " command: #{command.join(" ")}"
19
+
20
+ output, status = Open3.capture2(*command, chdir: dir.to_s)
21
+
22
+ unless status.success?
23
+ puts "Error!!! 👺"
24
+ failed_tests << dir.basename
25
+ end
26
+ end
27
+
28
+ if failed_tests.empty?
29
+ puts "Successfully updated output expectations! 🤡"
30
+ else
31
+ puts "Failed to update the following tests! 💀"
32
+ puts " #{failed_tests.join(", ")}"
33
+ exit 1
34
+ end
@@ -0,0 +1,53 @@
1
+ require "pathname"
2
+ require "yaml"
3
+ require "open3"
4
+ require "tempfile"
5
+ require "optparse"
6
+
7
+ OptionParser.new do |opts|
8
+ opts.on("--verbose", "-v") { @verbose = true }
9
+ end.parse!(ARGV)
10
+
11
+ if ARGV.empty?
12
+ test_dirs = (Pathname(__dir__) + "../smoke").children
13
+ else
14
+ test_dirs = ARGV.map {|p| Pathname.pwd + p }
15
+ end
16
+
17
+ failed_tests = []
18
+
19
+ test_dirs.each do |dir|
20
+ puts "Running test #{dir}..."
21
+
22
+ unless (dir + "test_expectations.yml").file?
23
+ puts "Skipped ⛹️‍♀️"
24
+ next
25
+ end
26
+
27
+ command = %w(steep check --with-expectations=test_expectations.yml)
28
+ puts " command: #{command.join(" ")}"
29
+
30
+ output, status = Open3.capture2(*command, chdir: dir.to_s)
31
+
32
+ unless status.success?
33
+ failed_tests << dir.basename
34
+ puts " Failed! 🤕"
35
+ else
36
+ puts " Succeed! 👍"
37
+ end
38
+
39
+ if @verbose
40
+ puts " Raw output:"
41
+ output.split(/\n/).each do |line|
42
+ puts " > #{line.chomp}"
43
+ end
44
+ end
45
+ end
46
+
47
+ if failed_tests.empty?
48
+ puts "All tests ok! 👏"
49
+ else
50
+ puts "Errors detected! 🤮"
51
+ puts " #{failed_tests.join(", ")}"
52
+ exit 1
53
+ end
data/lib/steep.rb CHANGED
@@ -2,8 +2,8 @@ require "steep/version"
2
2
 
3
3
  require "pathname"
4
4
  require "parser/ruby27"
5
- require "ast_utils"
6
5
  require "active_support/core_ext/object/try"
6
+ require "active_support/core_ext/string/inflections"
7
7
  require "logger"
8
8
  require "active_support/tagged_logging"
9
9
  require "rainbow"
@@ -13,6 +13,11 @@ require "etc"
13
13
  require "open3"
14
14
  require "stringio"
15
15
  require 'uri'
16
+ require "yaml"
17
+ require "securerandom"
18
+
19
+ require "parallel/processor_count"
20
+ require "terminal-table"
16
21
 
17
22
  require "rbs"
18
23
 
@@ -42,6 +47,8 @@ require "steep/ast/annotation/collection"
42
47
  require "steep/ast/builtin"
43
48
  require "steep/ast/types/factory"
44
49
 
50
+ require "steep/range_extension"
51
+
45
52
  require "steep/interface/function"
46
53
  require "steep/interface/block"
47
54
  require "steep/interface/method_type"
@@ -56,12 +63,14 @@ require "steep/subtyping/constraints"
56
63
  require "steep/subtyping/variable_variance"
57
64
  require "steep/subtyping/variable_occurrence"
58
65
 
59
- require "steep/signature/errors"
66
+ require "steep/diagnostic/helper"
67
+ require "steep/diagnostic/ruby"
68
+ require "steep/diagnostic/signature"
69
+ require "steep/diagnostic/lsp_formatter"
60
70
  require "steep/signature/validator"
61
71
  require "steep/source"
62
72
  require "steep/annotation_parser"
63
73
  require "steep/typing"
64
- require "steep/errors"
65
74
  require "steep/module_helper"
66
75
  require "steep/type_construction"
67
76
  require "steep/type_inference/context"
@@ -80,36 +89,43 @@ require "steep/index/rbs_index"
80
89
  require "steep/index/signature_symbol_provider"
81
90
  require "steep/index/source_index"
82
91
 
83
- require "steep/server/utils"
92
+ require "steep/server/change_buffer"
84
93
  require "steep/server/base_worker"
85
- require "steep/server/code_worker"
86
- require "steep/server/signature_worker"
87
94
  require "steep/server/worker_process"
88
95
  require "steep/server/interaction_worker"
96
+ require "steep/server/type_check_worker"
89
97
  require "steep/server/master"
90
98
 
99
+ require "steep/services/content_change"
100
+ require "steep/services/path_assignment"
101
+ require "steep/services/signature_service"
102
+ require "steep/services/type_check_service"
103
+ require "steep/services/hover_content"
104
+ require "steep/services/completion_provider"
105
+ require "steep/services/stats_calculator"
106
+ require "steep/services/file_loader"
107
+
91
108
  require "steep/project"
92
- require "steep/project/signature_file"
93
- require "steep/project/source_file"
109
+ require "steep/project/pattern"
94
110
  require "steep/project/options"
95
111
  require "steep/project/target"
96
112
  require "steep/project/dsl"
97
- require "steep/project/file_loader"
98
- require "steep/project/hover_content"
99
- require "steep/project/completion_provider"
113
+
114
+ require "steep/expectations"
100
115
  require "steep/drivers/utils/driver_helper"
116
+ require "steep/drivers/utils/jobs_count"
101
117
  require "steep/drivers/check"
102
118
  require "steep/drivers/stats"
103
119
  require "steep/drivers/validate"
104
120
  require "steep/drivers/annotations"
105
121
  require "steep/drivers/watch"
106
122
  require "steep/drivers/langserver"
107
- require "steep/drivers/signature_error_printer"
108
123
  require "steep/drivers/trace_printer"
109
124
  require "steep/drivers/print_project"
110
125
  require "steep/drivers/init"
111
126
  require "steep/drivers/vendor"
112
127
  require "steep/drivers/worker"
128
+ require "steep/drivers/diagnostic_printer"
113
129
 
114
130
  if ENV["NO_COLOR"]
115
131
  Rainbow.enabled = false
@@ -125,7 +141,7 @@ module Steep
125
141
  def self.new_logger(output, prev_level)
126
142
  ActiveSupport::TaggedLogging.new(Logger.new(output)).tap do |logger|
127
143
  logger.push_tags "Steep #{VERSION}"
128
- logger.level = prev_level || Logger::WARN
144
+ logger.level = prev_level || Logger::ERROR
129
145
  end
130
146
  end
131
147
 
@@ -142,18 +158,80 @@ module Steep
142
158
  @logger = nil
143
159
  self.log_output = STDERR
144
160
 
145
- def self.measure(message)
161
+ def self.measure(message, level: :warn)
146
162
  start = Time.now
147
163
  yield.tap do
148
164
  time = Time.now - start
149
- self.logger.info "#{message} took #{time} seconds"
165
+ if level.is_a?(Symbol)
166
+ level = Logger.const_get(level.to_s.upcase)
167
+ end
168
+ self.logger.log(level) { "#{message} took #{time} seconds" }
150
169
  end
151
170
  end
152
171
 
153
172
  def self.log_error(exn, message: "Unexpected error: #{exn.inspect}")
154
- Steep.logger.error message
173
+ Steep.logger.fatal message
155
174
  exn.backtrace.each do |loc|
156
- Steep.logger.warn " #{loc}"
175
+ Steep.logger.error " #{loc}"
176
+ end
177
+ end
178
+
179
+ class Sampler
180
+ def initialize()
181
+ @samples = []
182
+ end
183
+
184
+ def sample(message)
185
+ start = Time.now
186
+ yield.tap do
187
+ time = Time.now - start
188
+ @samples << [message, time]
189
+ end
190
+ end
191
+
192
+ def count
193
+ @samples.count
194
+ end
195
+
196
+ def total
197
+ @samples.sum(&:last)
157
198
  end
199
+
200
+ def slowests(num)
201
+ @samples.sort_by(&:last).reverse.take(num)
202
+ end
203
+
204
+ def average
205
+ if count > 0
206
+ total/count
207
+ else
208
+ 0
209
+ end
210
+ end
211
+
212
+ def percentile(p)
213
+ slowests(count - count * p / 100r).last&.last || 0
214
+ end
215
+ end
216
+
217
+ def self.measure2(message, level: :warn)
218
+ sampler = Sampler.new
219
+ result = yield(sampler)
220
+
221
+ if level.is_a?(Symbol)
222
+ level = Logger.const_get(level.to_s.upcase)
223
+ end
224
+ logger.log(level) { "#{sampler.total}secs for \"#{message}\"" }
225
+ logger.log(level) { " Average: #{sampler.average}secs"}
226
+ logger.log(level) { " Median: #{sampler.percentile(50)}secs"}
227
+ logger.log(level) { " Samples: #{sampler.count}"}
228
+ logger.log(level) { " 99 percentile: #{sampler.percentile(99)}secs"}
229
+ logger.log(level) { " 90 percentile: #{sampler.percentile(90)}secs"}
230
+ logger.log(level) { " 10 Slowests:"}
231
+ sampler.slowests(10).each do |message, time|
232
+ logger.log(level) { " #{message} (#{time}secs)"}
233
+ end
234
+
235
+ result
158
236
  end
159
237
  end
@@ -23,7 +23,15 @@ module Steep
23
23
  def initialize(source:, location:, exn: nil)
24
24
  @source = source
25
25
  @location = location
26
- super "Syntax error on annotation: `#{source}`, cause=#{exn.inspect}"
26
+
27
+ message = case exn
28
+ when RBS::Parser::SyntaxError
29
+ Diagnostic::Signature::SyntaxError.parser_syntax_error_message(exn)
30
+ else
31
+ exn.message
32
+ end
33
+
34
+ super message
27
35
  end
28
36
  end
29
37
 
@@ -158,7 +166,7 @@ module Steep
158
166
  end
159
167
  end
160
168
 
161
- rescue RBS::Parser::SyntaxError, RBS::Parser::SemanticsError => exn
169
+ rescue RBS::ParsingError => exn
162
170
  raise SyntaxError.new(source: src, location: location, exn: exn)
163
171
  end
164
172
  end
@@ -8,6 +8,10 @@ module Steep
8
8
  @location = location
9
9
  end
10
10
 
11
+ def to_s
12
+ "class"
13
+ end
14
+
11
15
  def ==(other)
12
16
  other.is_a?(Class)
13
17
  end
data/lib/steep/cli.rb CHANGED
@@ -8,6 +8,8 @@ module Steep
8
8
  attr_reader :stderr
9
9
  attr_reader :command
10
10
 
11
+ include Parallel::ProcessorCount
12
+
11
13
  def initialize(stdout:, stdin:, stderr:, argv:)
12
14
  @stdout = stdout
13
15
  @stdin = stdin
@@ -51,19 +53,27 @@ module Steep
51
53
  end
52
54
 
53
55
  def handle_logging_options(opts)
54
- opts.on("--log-level=[debug,info,warn,error,fatal]") do |level|
56
+ opts.on("--log-level=LEVEL", "Specify log level: debug, info, warn, error, fatal") do |level|
55
57
  Steep.logger.level = level
56
58
  end
57
59
 
58
- opts.on("--log-output=[PATH]") do |file|
60
+ opts.on("--log-output=PATH", "Print logs to given path") do |file|
59
61
  Steep.log_output = file
60
62
  end
61
63
 
62
- opts.on("--verbose") do
64
+ opts.on("--verbose", "Set log level to debug") do
63
65
  Steep.logger.level = Logger::DEBUG
64
66
  end
65
67
  end
66
68
 
69
+ def handle_jobs_option(command, opts, modifier = 0)
70
+ default = physical_processor_count + modifier
71
+ command.jobs_count = default
72
+ opts.on("-j N", "--jobs=N", "Specify the number of type check workers (defaults: #{default})") do |count|
73
+ command.jobs_count = Integer(count)
74
+ end
75
+ end
76
+
67
77
  def process_init
68
78
  Drivers::Init.new(stdout: stdout, stderr: stderr).tap do |command|
69
79
  OptionParser.new do |opts|
@@ -83,7 +93,13 @@ module Steep
83
93
  opts.banner = "Usage: steep check [options] [sources]"
84
94
 
85
95
  opts.on("--steepfile=PATH") {|path| check.steepfile = Pathname(path) }
86
- opts.on("--dump-all-types") { check.dump_all_types = true }
96
+ opts.on("--with-expectations[=PATH]", "Type check with expectations saved in PATH (or steep_expectations.yml)") do |path|
97
+ check.with_expectations_path = Pathname(path || "steep_expectations.yml")
98
+ end
99
+ opts.on("--save-expectations[=PATH]", "Save expectations with current type check result to PATH (or steep_expectations.yml)") do |path|
100
+ check.save_expectations_path = Pathname(path || "steep_expectations.yml")
101
+ end
102
+ handle_jobs_option check, opts
87
103
  handle_logging_options opts
88
104
  end.parse!(argv)
89
105
 
@@ -97,6 +113,8 @@ module Steep
97
113
  opts.banner = "Usage: steep stats [options] [sources]"
98
114
 
99
115
  opts.on("--steepfile=PATH") {|path| check.steepfile = Pathname(path) }
116
+ opts.on("--format=FORMAT", "Specify output format: csv, table") {|format| check.format = format }
117
+ handle_jobs_option check, opts
100
118
  handle_logging_options opts
101
119
  end.parse!(argv)
102
120
 
@@ -137,10 +155,12 @@ module Steep
137
155
  Drivers::Watch.new(stdout: stdout, stderr: stderr).tap do |command|
138
156
  OptionParser.new do |opts|
139
157
  opts.banner = "Usage: steep watch [options] [dirs]"
158
+ handle_jobs_option command, opts
140
159
  handle_logging_options opts
141
160
  end.parse!(argv)
142
161
 
143
- command.dirs.push *argv
162
+ dirs = argv.map {|dir| Pathname(dir) }
163
+ command.dirs.push(*dirs)
144
164
  end.run
145
165
  end
146
166
 
@@ -148,6 +168,7 @@ module Steep
148
168
  Drivers::Langserver.new(stdout: stdout, stderr: stderr, stdin: stdin).tap do |command|
149
169
  OptionParser.new do |opts|
150
170
  opts.on("--steepfile=PATH") {|path| command.steepfile = Pathname(path) }
171
+ handle_jobs_option command, opts, -1
151
172
  handle_logging_options opts
152
173
  end.parse!(argv)
153
174
  end.run
@@ -180,11 +201,15 @@ module Steep
180
201
  handle_logging_options opts
181
202
 
182
203
  opts.on("--interaction") { command.worker_type = :interaction }
183
- opts.on("--code") { command.worker_type = :code }
184
- opts.on("--signature") { command.worker_type = :signature }
204
+ opts.on("--typecheck") { command.worker_type = :typecheck }
185
205
  opts.on("--steepfile=PATH") {|path| command.steepfile = Pathname(path) }
186
206
  opts.on("--name=NAME") {|name| command.worker_name = name }
207
+ opts.on("--delay-shutdown") { command.delay_shutdown = true }
208
+ opts.on("--max-index=COUNT") {|count| command.max_index = Integer(count) }
209
+ opts.on("--index=INDEX") {|index| command.index = Integer(index) }
187
210
  end.parse!(argv)
211
+
212
+ command.commandline_args.push(*argv)
188
213
  end.run
189
214
  end
190
215
  end