steep 0.37.0 → 0.42.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/CHANGELOG.md +34 -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 -14
  8. data/lib/steep/ast/types/bot.rb +1 -1
  9. data/lib/steep/ast/types/class.rb +4 -0
  10. data/lib/steep/ast/types/factory.rb +10 -0
  11. data/lib/steep/ast/types/logic.rb +16 -3
  12. data/lib/steep/ast/types/top.rb +1 -1
  13. data/lib/steep/cli.rb +31 -7
  14. data/lib/steep/diagnostic/helper.rb +17 -0
  15. data/lib/steep/diagnostic/lsp_formatter.rb +16 -0
  16. data/lib/steep/diagnostic/ruby.rb +619 -0
  17. data/lib/steep/diagnostic/signature.rb +357 -0
  18. data/lib/steep/drivers/annotations.rb +19 -28
  19. data/lib/steep/drivers/check.rb +182 -60
  20. data/lib/steep/drivers/diagnostic_printer.rb +99 -0
  21. data/lib/steep/drivers/langserver.rb +3 -8
  22. data/lib/steep/drivers/print_project.rb +10 -9
  23. data/lib/steep/drivers/stats.rb +124 -32
  24. data/lib/steep/drivers/trace_printer.rb +5 -1
  25. data/lib/steep/drivers/utils/jobs_count.rb +9 -0
  26. data/lib/steep/drivers/validate.rb +31 -13
  27. data/lib/steep/drivers/watch.rb +69 -48
  28. data/lib/steep/drivers/worker.rb +16 -8
  29. data/lib/steep/expectations.rb +159 -0
  30. data/lib/steep/index/rbs_index.rb +334 -0
  31. data/lib/steep/index/signature_symbol_provider.rb +162 -0
  32. data/lib/steep/index/source_index.rb +100 -0
  33. data/lib/steep/project.rb +0 -30
  34. data/lib/steep/project/dsl.rb +5 -3
  35. data/lib/steep/project/options.rb +4 -4
  36. data/lib/steep/project/pattern.rb +56 -0
  37. data/lib/steep/project/target.rb +9 -214
  38. data/lib/steep/range_extension.rb +29 -0
  39. data/lib/steep/server/base_worker.rb +43 -7
  40. data/lib/steep/server/change_buffer.rb +63 -0
  41. data/lib/steep/server/interaction_worker.rb +73 -56
  42. data/lib/steep/server/master.rb +245 -109
  43. data/lib/steep/server/type_check_worker.rb +122 -0
  44. data/lib/steep/server/worker_process.rb +17 -15
  45. data/lib/steep/{project → services}/completion_provider.rb +3 -3
  46. data/lib/steep/services/content_change.rb +61 -0
  47. data/lib/steep/services/file_loader.rb +48 -0
  48. data/lib/steep/{project → services}/hover_content.rb +14 -16
  49. data/lib/steep/services/path_assignment.rb +29 -0
  50. data/lib/steep/services/signature_service.rb +369 -0
  51. data/lib/steep/services/stats_calculator.rb +69 -0
  52. data/lib/steep/services/type_check_service.rb +342 -0
  53. data/lib/steep/signature/validator.rb +174 -32
  54. data/lib/steep/subtyping/check.rb +248 -47
  55. data/lib/steep/subtyping/constraints.rb +2 -2
  56. data/lib/steep/type_construction.rb +565 -295
  57. data/lib/steep/type_inference/constant_env.rb +5 -1
  58. data/lib/steep/type_inference/local_variable_type_env.rb +26 -12
  59. data/lib/steep/type_inference/logic_type_interpreter.rb +99 -26
  60. data/lib/steep/type_inference/type_env.rb +43 -17
  61. data/lib/steep/typing.rb +8 -2
  62. data/lib/steep/version.rb +1 -1
  63. data/smoke/alias/a.rb +0 -3
  64. data/smoke/alias/b.rb +0 -1
  65. data/smoke/alias/c.rb +0 -2
  66. data/smoke/alias/test_expectations.yml +96 -0
  67. data/smoke/and/a.rb +0 -3
  68. data/smoke/and/test_expectations.yml +31 -0
  69. data/smoke/array/a.rb +0 -3
  70. data/smoke/array/b.rb +0 -2
  71. data/smoke/array/c.rb +0 -1
  72. data/smoke/array/test_expectations.yml +103 -0
  73. data/smoke/block/a.rb +0 -2
  74. data/smoke/block/b.rb +0 -2
  75. data/smoke/block/d.rb +0 -4
  76. data/smoke/block/test_expectations.yml +125 -0
  77. data/smoke/case/a.rb +0 -3
  78. data/smoke/case/test_expectations.yml +47 -0
  79. data/smoke/class/a.rb +0 -3
  80. data/smoke/class/c.rb +0 -1
  81. data/smoke/class/f.rb +0 -1
  82. data/smoke/class/g.rb +0 -2
  83. data/smoke/class/i.rb +0 -2
  84. data/smoke/class/test_expectations.yml +120 -0
  85. data/smoke/const/a.rb +0 -3
  86. data/smoke/const/b.rb +7 -0
  87. data/smoke/const/b.rbs +5 -0
  88. data/smoke/const/test_expectations.yml +139 -0
  89. data/smoke/diagnostics-rbs-duplicated/Steepfile +5 -0
  90. data/smoke/diagnostics-rbs-duplicated/a.rbs +5 -0
  91. data/smoke/diagnostics-rbs-duplicated/test_expectations.yml +13 -0
  92. data/smoke/diagnostics-rbs/Steepfile +8 -0
  93. data/smoke/diagnostics-rbs/duplicated-method-definition.rbs +20 -0
  94. data/smoke/diagnostics-rbs/generic-parameter-mismatch.rbs +7 -0
  95. data/smoke/diagnostics-rbs/invalid-method-overload.rbs +3 -0
  96. data/smoke/diagnostics-rbs/invalid-type-application.rbs +7 -0
  97. data/smoke/diagnostics-rbs/invalid_variance_annotation.rbs +3 -0
  98. data/smoke/diagnostics-rbs/recursive-alias.rbs +5 -0
  99. data/smoke/diagnostics-rbs/recursive-class.rbs +8 -0
  100. data/smoke/diagnostics-rbs/superclass-mismatch.rbs +7 -0
  101. data/smoke/diagnostics-rbs/test_expectations.yml +231 -0
  102. data/smoke/diagnostics-rbs/unknown-method-alias.rbs +3 -0
  103. data/smoke/diagnostics-rbs/unknown-type-name-2.rbs +5 -0
  104. data/smoke/diagnostics-rbs/unknown-type-name.rbs +13 -0
  105. data/smoke/diagnostics/Steepfile +5 -0
  106. data/smoke/diagnostics/a.rbs +26 -0
  107. data/smoke/diagnostics/argument_type_mismatch.rb +1 -0
  108. data/smoke/diagnostics/block_body_type_mismatch.rb +1 -0
  109. data/smoke/diagnostics/block_type_mismatch.rb +3 -0
  110. data/smoke/diagnostics/break_type_mismatch.rb +1 -0
  111. data/smoke/diagnostics/else_on_exhaustive_case.rb +12 -0
  112. data/smoke/diagnostics/incompatible_annotation.rb +6 -0
  113. data/smoke/diagnostics/incompatible_argument.rb +1 -0
  114. data/smoke/diagnostics/incompatible_assignment.rb +8 -0
  115. data/smoke/diagnostics/method_arity_mismatch.rb +11 -0
  116. data/smoke/diagnostics/method_body_type_mismatch.rb +6 -0
  117. data/smoke/diagnostics/method_definition_missing.rb +2 -0
  118. data/smoke/diagnostics/method_return_type_annotation_mismatch.rb +7 -0
  119. data/smoke/diagnostics/missing_keyword.rb +1 -0
  120. data/smoke/diagnostics/no_method.rb +1 -0
  121. data/smoke/diagnostics/required_block_missing.rb +1 -0
  122. data/smoke/diagnostics/return_type_mismatch.rb +6 -0
  123. data/smoke/diagnostics/test_expectations.yml +477 -0
  124. data/smoke/diagnostics/unexpected_block_given.rb +1 -0
  125. data/smoke/diagnostics/unexpected_dynamic_method.rb +3 -0
  126. data/smoke/diagnostics/unexpected_jump.rb +4 -0
  127. data/smoke/diagnostics/unexpected_jump_value.rb +3 -0
  128. data/smoke/diagnostics/unexpected_keyword.rb +1 -0
  129. data/smoke/diagnostics/unexpected_splat.rb +1 -0
  130. data/smoke/diagnostics/unexpected_yield.rb +6 -0
  131. data/smoke/diagnostics/unknown_constant_assigned.rb +7 -0
  132. data/smoke/diagnostics/unresolved_overloading.rb +1 -0
  133. data/smoke/diagnostics/unsatisfiable_constraint.rb +7 -0
  134. data/smoke/diagnostics/unsupported_syntax.rb +2 -0
  135. data/smoke/dstr/a.rb +0 -1
  136. data/smoke/dstr/test_expectations.yml +13 -0
  137. data/smoke/ensure/a.rb +0 -4
  138. data/smoke/ensure/test_expectations.yml +62 -0
  139. data/smoke/enumerator/a.rb +0 -6
  140. data/smoke/enumerator/b.rb +0 -3
  141. data/smoke/enumerator/test_expectations.yml +135 -0
  142. data/smoke/extension/a.rb +0 -1
  143. data/smoke/extension/b.rb +0 -2
  144. data/smoke/extension/c.rb +0 -1
  145. data/smoke/extension/f.rb +2 -0
  146. data/smoke/extension/f.rbs +3 -0
  147. data/smoke/extension/test_expectations.yml +73 -0
  148. data/smoke/hash/b.rb +0 -1
  149. data/smoke/hash/c.rb +0 -3
  150. data/smoke/hash/d.rb +0 -1
  151. data/smoke/hash/e.rb +0 -1
  152. data/smoke/hash/test_expectations.yml +81 -0
  153. data/smoke/hello/hello.rb +0 -2
  154. data/smoke/hello/test_expectations.yml +25 -0
  155. data/smoke/if/a.rb +0 -2
  156. data/smoke/if/test_expectations.yml +34 -0
  157. data/smoke/implements/a.rb +0 -2
  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/set_divide.rb +0 -4
  185. data/smoke/regression/test_expectations.yml +43 -0
  186. data/smoke/rescue/a.rb +0 -5
  187. data/smoke/rescue/test_expectations.yml +79 -0
  188. data/smoke/self/a.rb +0 -2
  189. data/smoke/self/test_expectations.yml +23 -0
  190. data/smoke/skip/skip.rb +0 -2
  191. data/smoke/skip/test_expectations.yml +23 -0
  192. data/smoke/stdout/test_expectations.yml +1 -0
  193. data/smoke/super/a.rb +0 -4
  194. data/smoke/super/test_expectations.yml +79 -0
  195. data/smoke/toplevel/a.rb +0 -1
  196. data/smoke/toplevel/test_expectations.yml +15 -0
  197. data/smoke/tsort/Steepfile +2 -0
  198. data/smoke/tsort/a.rb +0 -3
  199. data/smoke/tsort/test_expectations.yml +63 -0
  200. data/smoke/type_case/a.rb +0 -4
  201. data/smoke/type_case/test_expectations.yml +48 -0
  202. data/smoke/unexpected/Steepfile +5 -0
  203. data/smoke/unexpected/test_expectations.yml +25 -0
  204. data/smoke/unexpected/unexpected.rb +1 -0
  205. data/smoke/unexpected/unexpected.rbs +3 -0
  206. data/smoke/yield/a.rb +0 -3
  207. data/smoke/yield/b.rb +6 -0
  208. data/smoke/yield/test_expectations.yml +68 -0
  209. data/steep.gemspec +4 -3
  210. metadata +144 -29
  211. data/bin/smoke_runner.rb +0 -139
  212. data/lib/steep/drivers/signature_error_printer.rb +0 -25
  213. data/lib/steep/errors.rb +0 -565
  214. data/lib/steep/project/file_loader.rb +0 -68
  215. data/lib/steep/project/signature_file.rb +0 -33
  216. data/lib/steep/project/source_file.rb +0 -129
  217. data/lib/steep/server/code_worker.rb +0 -137
  218. data/lib/steep/server/signature_worker.rb +0 -152
  219. data/lib/steep/server/utils.rb +0 -69
  220. data/lib/steep/signature/errors.rb +0 -82
  221. data/lib/steep/type_assignability.rb +0 -367
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3d9186b6988081611f8bf060700ad97eb408ab605ab11ab32b717b9a0e9b8b9
4
- data.tar.gz: 6f308f7bd551472237d5857614b765468782290733514793b2dfe35a3ac232cf
3
+ metadata.gz: 3bed885aa8ba3f60076879eb1ca1572c56ae59aae2a9ee3745affbbd1f3f93d2
4
+ data.tar.gz: 344c77c6676f8c6772d28bab9598c8fa45835100f24603985750de076ebe57f3
5
5
  SHA512:
6
- metadata.gz: 1fee308a7783a6e54c974c71c78189492c0f557528bccb0da530927cfdb4e4a16f4ff6cd2ec9f8c3292dd9839bb1637f68fd3aff9da0fef6783e3f4b5d838984
7
- data.tar.gz: 7cd72caf879d339e5fec0bed219957befd40d5dc2466b345435f4b523c8028a9264404b1d9c695c11ca638b8e6bbeb1d1ad8f600367cd87bf9b3c4fade99eeaa
6
+ metadata.gz: dce04d256960ee738d029a9c66187a1ef5f11beb3fd0613cbb02dde6494eeafde8aa0bf12aadc02d07bb6a64a785444f18636df1eaa3f1be02bce1d24ad63385
7
+ data.tar.gz: df9772b46abe7c2acd10cf497ded086b3614016d74b26578d2da6720f26afa01a73a7b43c6a0170b67157e7615e2ec989597ed1081a3f6e4ac69553adc338589
@@ -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,40 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.42.0 (2021-03-08)
6
+
7
+ * 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))
8
+ * Let `watch` command support files ([\#323](https://github.com/soutaro/steep/pull/323))
9
+ * Validate _module-self-type_ constraints ([\#308](https://github.com/soutaro/steep/pull/308))
10
+ * 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))
11
+ * Fix `code` of RBS diagnostics ([\#306](https://github.com/soutaro/steep/pull/306))
12
+ * Skip printing source code from out of date _expectations_ file ([\#305](https://github.com/soutaro/steep/pull/305))
13
+
14
+ ## 0.41.0 (2021-02-07)
15
+
16
+ * Add `--with-expectations` and `--save-expectations` option ([#303](https://github.com/soutaro/steep/pull/303))
17
+
18
+ ## 0.40.0 (2021-01-31)
19
+
20
+ * Report progress with dots ([#287](https://github.com/soutaro/steep/pull/287))
21
+ * Diagnostics message improvements ([#297](https://github.com/soutaro/steep/pull/297), [#301](https://github.com/soutaro/steep/pull/301))
22
+ * Fix error on implicit `to_proc` syntax when `untyped` is yielded ([#291](https://github.com/soutaro/steep/pull/291))
23
+
24
+ ## 0.39.0 (2020-12-25)
25
+
26
+ * Update RBS to 1.0.0 ([#282](https://github.com/soutaro/steep/pull/282))
27
+ * Better `&&` and `||` typing ([#276](https://github.com/soutaro/steep/pull/276))
28
+ * Type case based on literals ([#277](https://github.com/soutaro/steep/pull/277))
29
+ * Type case improvements ([#279](https://github.com/soutaro/steep/pull/279), [#283](https://github.com/soutaro/steep/pull/283))
30
+ * Improvements on untyped classes/modules, unsupported syntax error handling, and argument types in untyped methods ([#280](https://github.com/soutaro/steep/pull/280))
31
+ * Fix `bot` and `top` type format ([#278](https://github.com/soutaro/steep/pull/278))
32
+ * Colorfull error messages ([#273](https://github.com/soutaro/steep/pull/273))
33
+
34
+ ## 0.38.0 (2020-12-10)
35
+
36
+ * Improve `break`/`next` typing ([#271](https://github.com/soutaro/steep/pull/271))
37
+ * Add LSP `workspace/symbol` feature ([#267](https://github.com/soutaro/steep/pull/267))
38
+
5
39
  ## 0.37.0 (2020-12-06)
6
40
 
7
41
  * Update to RBS 0.20.0 with _singleton attribute_ syntax and _proc types with blocks_. ([#264](https://github.com/soutaro/steep/pull/264))
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
@@ -4,6 +4,7 @@ require "pathname"
4
4
  require "parser/ruby27"
5
5
  require "ast_utils"
6
6
  require "active_support/core_ext/object/try"
7
+ require "active_support/core_ext/string/inflections"
7
8
  require "logger"
8
9
  require "active_support/tagged_logging"
9
10
  require "rainbow"
@@ -13,6 +14,9 @@ require "etc"
13
14
  require "open3"
14
15
  require "stringio"
15
16
  require 'uri'
17
+ require "yaml"
18
+
19
+ require "parallel/processor_count"
16
20
 
17
21
  require "rbs"
18
22
 
@@ -42,6 +46,8 @@ require "steep/ast/annotation/collection"
42
46
  require "steep/ast/builtin"
43
47
  require "steep/ast/types/factory"
44
48
 
49
+ require "steep/range_extension"
50
+
45
51
  require "steep/interface/function"
46
52
  require "steep/interface/block"
47
53
  require "steep/interface/method_type"
@@ -56,12 +62,14 @@ require "steep/subtyping/constraints"
56
62
  require "steep/subtyping/variable_variance"
57
63
  require "steep/subtyping/variable_occurrence"
58
64
 
59
- require "steep/signature/errors"
65
+ require "steep/diagnostic/helper"
66
+ require "steep/diagnostic/ruby"
67
+ require "steep/diagnostic/signature"
68
+ require "steep/diagnostic/lsp_formatter"
60
69
  require "steep/signature/validator"
61
70
  require "steep/source"
62
71
  require "steep/annotation_parser"
63
72
  require "steep/typing"
64
- require "steep/errors"
65
73
  require "steep/module_helper"
66
74
  require "steep/type_construction"
67
75
  require "steep/type_inference/context"
@@ -76,36 +84,47 @@ require "steep/type_inference/logic_type_interpreter"
76
84
  require "steep/type_inference/method_call"
77
85
  require "steep/ast/types"
78
86
 
79
- require "steep/server/utils"
87
+ require "steep/index/rbs_index"
88
+ require "steep/index/signature_symbol_provider"
89
+ require "steep/index/source_index"
90
+
91
+ require "steep/server/change_buffer"
80
92
  require "steep/server/base_worker"
81
- require "steep/server/code_worker"
82
- require "steep/server/signature_worker"
83
93
  require "steep/server/worker_process"
84
94
  require "steep/server/interaction_worker"
95
+ require "steep/server/type_check_worker"
85
96
  require "steep/server/master"
86
97
 
98
+ require "steep/services/content_change"
99
+ require "steep/services/path_assignment"
100
+ require "steep/services/signature_service"
101
+ require "steep/services/type_check_service"
102
+ require "steep/services/hover_content"
103
+ require "steep/services/completion_provider"
104
+ require "steep/services/stats_calculator"
105
+ require "steep/services/file_loader"
106
+
87
107
  require "steep/project"
88
- require "steep/project/signature_file"
89
- require "steep/project/source_file"
108
+ require "steep/project/pattern"
90
109
  require "steep/project/options"
91
110
  require "steep/project/target"
92
111
  require "steep/project/dsl"
93
- require "steep/project/file_loader"
94
- require "steep/project/hover_content"
95
- require "steep/project/completion_provider"
112
+
113
+ require "steep/expectations"
96
114
  require "steep/drivers/utils/driver_helper"
115
+ require "steep/drivers/utils/jobs_count"
97
116
  require "steep/drivers/check"
98
117
  require "steep/drivers/stats"
99
118
  require "steep/drivers/validate"
100
119
  require "steep/drivers/annotations"
101
120
  require "steep/drivers/watch"
102
121
  require "steep/drivers/langserver"
103
- require "steep/drivers/signature_error_printer"
104
122
  require "steep/drivers/trace_printer"
105
123
  require "steep/drivers/print_project"
106
124
  require "steep/drivers/init"
107
125
  require "steep/drivers/vendor"
108
126
  require "steep/drivers/worker"
127
+ require "steep/drivers/diagnostic_printer"
109
128
 
110
129
  if ENV["NO_COLOR"]
111
130
  Rainbow.enabled = false
@@ -121,7 +140,7 @@ module Steep
121
140
  def self.new_logger(output, prev_level)
122
141
  ActiveSupport::TaggedLogging.new(Logger.new(output)).tap do |logger|
123
142
  logger.push_tags "Steep #{VERSION}"
124
- logger.level = prev_level || Logger::WARN
143
+ logger.level = prev_level || Logger::ERROR
125
144
  end
126
145
  end
127
146
 
@@ -138,11 +157,14 @@ module Steep
138
157
  @logger = nil
139
158
  self.log_output = STDERR
140
159
 
141
- def self.measure(message)
160
+ def self.measure(message, level: :warn)
142
161
  start = Time.now
143
162
  yield.tap do
144
163
  time = Time.now - start
145
- self.logger.info "#{message} took #{time} seconds"
164
+ if level.is_a?(Symbol)
165
+ level = Logger.const_get(level.to_s.upcase)
166
+ end
167
+ self.logger.log(level) { "#{message} took #{time} seconds" }
146
168
  end
147
169
  end
148
170
 
@@ -152,4 +174,63 @@ module Steep
152
174
  Steep.logger.warn " #{loc}"
153
175
  end
154
176
  end
177
+
178
+ class Sampler
179
+ def initialize()
180
+ @samples = []
181
+ end
182
+
183
+ def sample(message)
184
+ start = Time.now
185
+ yield.tap do
186
+ time = Time.now - start
187
+ @samples << [message, time]
188
+ end
189
+ end
190
+
191
+ def count
192
+ @samples.count
193
+ end
194
+
195
+ def total
196
+ @samples.sum(&:last)
197
+ end
198
+
199
+ def slowests(num)
200
+ @samples.sort_by(&:last).reverse.take(num)
201
+ end
202
+
203
+ def average
204
+ if count > 0
205
+ total/count
206
+ else
207
+ 0
208
+ end
209
+ end
210
+
211
+ def percentile(p)
212
+ slowests(count - count * p / 100r).last&.last || 0
213
+ end
214
+ end
215
+
216
+ def self.measure2(message, level: :warn)
217
+ sampler = Sampler.new
218
+ result = yield(sampler)
219
+
220
+ if level.is_a?(Symbol)
221
+ level = Logger.const_get(level.to_s.upcase)
222
+ end
223
+ logger.log(level) { "#{sampler.total}secs for \"#{message}\"" }
224
+ logger.log(level) { " Average: #{sampler.average}secs"}
225
+ logger.log(level) { " Median: #{sampler.percentile(50)}secs"}
226
+ logger.log(level) { " Samples: #{sampler.count}"}
227
+ logger.log(level) { " 99 percentile: #{sampler.percentile(99)}secs"}
228
+ logger.log(level) { " 90 percentile: #{sampler.percentile(90)}secs"}
229
+ logger.log(level) { " 10 Slowests:"}
230
+ sampler.slowests(10).each do |message, time|
231
+ logger.log(level) { " #{message} (#{time}secs)"}
232
+ end
233
+
234
+ result
235
+ end
155
236
  end
@@ -23,7 +23,7 @@ module Steep
23
23
  end
24
24
 
25
25
  def to_s
26
- ""
26
+ "bot"
27
27
  end
28
28
 
29
29
  include Helper::NoFreeVariables
@@ -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
@@ -368,6 +368,8 @@ module Steep
368
368
  ]
369
369
  when AST::Types::Name::Alias
370
370
  unwrap_optional(expand_alias(type))
371
+ when AST::Types::Boolean
372
+ [AST::Builtin.true_type, AST::Builtin.false_type]
371
373
  else
372
374
  [type, nil]
373
375
  end
@@ -421,6 +423,14 @@ module Steep
421
423
  return_type: AST::Types::Logic::ArgIsReceiver.new(location: method_type.type.return_type.location)
422
424
  )
423
425
  )
426
+ when RBS::BuiltinNames::Object.name, RBS::BuiltinNames::String.name, RBS::BuiltinNames::Integer.name, RBS::BuiltinNames::Symbol.name,
427
+ RBS::BuiltinNames::TrueClass.name, RBS::BuiltinNames::FalseClass.name, TypeName("::NilClass")
428
+ # Value based type-case works on literal types which is available for String, Integer, Symbol, TrueClass, FalseClass, and NilClass
429
+ return method_type.with(
430
+ type: method_type.type.with(
431
+ return_type: AST::Types::Logic::ArgEqualsReceiver.new(location: method_type.type.return_type.location)
432
+ )
433
+ )
424
434
  end
425
435
  end
426
436
  end
@@ -58,16 +58,23 @@ module Steep
58
58
  end
59
59
  end
60
60
 
61
+ class ArgEqualsReceiver < Base
62
+ def initialize(location: nil)
63
+ @location = location
64
+ end
65
+ end
66
+
61
67
  class Env < Base
62
- attr_reader :truthy, :falsy
68
+ attr_reader :truthy, :falsy, :type
63
69
 
64
- def initialize(truthy:, falsy:, location: nil)
70
+ def initialize(truthy:, falsy:, type:, location: nil)
65
71
  @truthy = truthy
66
72
  @falsy = falsy
73
+ @type = type
67
74
  end
68
75
 
69
76
  def ==(other)
70
- other.is_a?(Env) && other.truthy == truthy && other.falsy == falsy
77
+ other.is_a?(Env) && other.truthy == truthy && other.falsy == falsy && other.type == type
71
78
  end
72
79
 
73
80
  alias eql? ==
@@ -75,6 +82,12 @@ module Steep
75
82
  def hash
76
83
  self.class.hash ^ truthy.hash ^ falsy.hash
77
84
  end
85
+
86
+ def inspect
87
+ "#<Steep::AST::Types::Env @type=#{type}, @truthy=..., @falsy=...>"
88
+ end
89
+
90
+ alias to_s inspect
78
91
  end
79
92
  end
80
93
  end
@@ -23,7 +23,7 @@ module Steep
23
23
  end
24
24
 
25
25
  def to_s
26
- ""
26
+ "top"
27
27
  end
28
28
 
29
29
  include Helper::NoFreeVariables