steep 0.41.0 → 0.44.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/Gemfile +1 -0
  4. data/bin/output_test.rb +8 -2
  5. data/lib/steep.rb +85 -15
  6. data/lib/steep/annotation_parser.rb +10 -2
  7. data/lib/steep/ast/types/class.rb +4 -0
  8. data/lib/steep/cli.rb +22 -3
  9. data/lib/steep/diagnostic/ruby.rb +13 -8
  10. data/lib/steep/diagnostic/signature.rb +152 -2
  11. data/lib/steep/drivers/annotations.rb +18 -36
  12. data/lib/steep/drivers/check.rb +39 -22
  13. data/lib/steep/drivers/diagnostic_printer.rb +11 -2
  14. data/lib/steep/drivers/langserver.rb +4 -8
  15. data/lib/steep/drivers/print_project.rb +10 -9
  16. data/lib/steep/drivers/stats.rb +135 -119
  17. data/lib/steep/drivers/utils/driver_helper.rb +35 -0
  18. data/lib/steep/drivers/utils/jobs_count.rb +9 -0
  19. data/lib/steep/drivers/validate.rb +29 -18
  20. data/lib/steep/drivers/watch.rb +55 -49
  21. data/lib/steep/drivers/worker.rb +11 -8
  22. data/lib/steep/index/signature_symbol_provider.rb +23 -1
  23. data/lib/steep/index/source_index.rb +55 -5
  24. data/lib/steep/interface/block.rb +4 -0
  25. data/lib/steep/project.rb +0 -36
  26. data/lib/steep/project/dsl.rb +5 -3
  27. data/lib/steep/project/pattern.rb +56 -0
  28. data/lib/steep/project/target.rb +11 -227
  29. data/lib/steep/server/base_worker.rb +1 -3
  30. data/lib/steep/server/change_buffer.rb +63 -0
  31. data/lib/steep/server/interaction_worker.rb +72 -57
  32. data/lib/steep/server/master.rb +652 -234
  33. data/lib/steep/server/type_check_worker.rb +304 -0
  34. data/lib/steep/server/worker_process.rb +16 -11
  35. data/lib/steep/{project → services}/completion_provider.rb +5 -5
  36. data/lib/steep/services/content_change.rb +61 -0
  37. data/lib/steep/services/file_loader.rb +48 -0
  38. data/lib/steep/services/goto_service.rb +322 -0
  39. data/lib/steep/{project → services}/hover_content.rb +19 -20
  40. data/lib/steep/services/path_assignment.rb +27 -0
  41. data/lib/steep/services/signature_service.rb +403 -0
  42. data/lib/steep/services/stats_calculator.rb +69 -0
  43. data/lib/steep/services/type_check_service.rb +413 -0
  44. data/lib/steep/signature/validator.rb +187 -85
  45. data/lib/steep/source.rb +21 -18
  46. data/lib/steep/subtyping/check.rb +246 -45
  47. data/lib/steep/subtyping/constraints.rb +4 -4
  48. data/lib/steep/type_construction.rb +428 -193
  49. data/lib/steep/type_inference/block_params.rb +1 -1
  50. data/lib/steep/type_inference/context.rb +22 -0
  51. data/lib/steep/type_inference/local_variable_type_env.rb +26 -12
  52. data/lib/steep/type_inference/logic.rb +1 -1
  53. data/lib/steep/type_inference/logic_type_interpreter.rb +4 -4
  54. data/lib/steep/type_inference/type_env.rb +43 -17
  55. data/lib/steep/version.rb +1 -1
  56. data/smoke/const/test_expectations.yml +0 -10
  57. data/smoke/diagnostics-rbs-duplicated/test_expectations.yml +1 -1
  58. data/smoke/diagnostics-rbs/Steepfile +7 -4
  59. data/smoke/diagnostics-rbs/test_expectations.yml +23 -21
  60. data/smoke/diagnostics-rbs/unknown-type-name-2.rbs +5 -0
  61. data/smoke/diagnostics-ruby-unsat/Steepfile +5 -0
  62. data/smoke/diagnostics-ruby-unsat/a.rbs +3 -0
  63. data/smoke/diagnostics-ruby-unsat/test_expectations.yml +27 -0
  64. data/smoke/{diagnostics → diagnostics-ruby-unsat}/unsatisfiable_constraint.rb +0 -1
  65. data/smoke/diagnostics/a.rbs +0 -4
  66. data/smoke/diagnostics/test_expectations.yml +0 -26
  67. data/smoke/extension/f.rb +2 -0
  68. data/smoke/extension/f.rbs +3 -0
  69. data/smoke/extension/test_expectations.yml +12 -0
  70. data/smoke/implements/b.rb +13 -0
  71. data/smoke/implements/b.rbs +12 -0
  72. data/smoke/regression/issue_328.rb +1 -0
  73. data/smoke/regression/issue_328.rbs +0 -0
  74. data/smoke/regression/issue_332.rb +11 -0
  75. data/smoke/regression/issue_332.rbs +19 -0
  76. data/smoke/regression/issue_372.rb +8 -0
  77. data/smoke/regression/issue_372.rbs +4 -0
  78. data/smoke/regression/masgn.rb +4 -0
  79. data/smoke/regression/test_expectations.yml +17 -0
  80. data/smoke/regression/thread.rb +7 -0
  81. data/smoke/super/test_expectations.yml +2 -12
  82. data/smoke/tsort/Steepfile +2 -0
  83. data/smoke/tsort/test_expectations.yml +20 -0
  84. data/smoke/unexpected/Steepfile +5 -0
  85. data/smoke/unexpected/test_expectations.yml +25 -0
  86. data/smoke/unexpected/unexpected.rb +1 -0
  87. data/smoke/unexpected/unexpected.rbs +3 -0
  88. data/steep.gemspec +4 -3
  89. metadata +88 -38
  90. data/lib/steep/project/file_loader.rb +0 -68
  91. data/lib/steep/project/signature_file.rb +0 -39
  92. data/lib/steep/project/source_file.rb +0 -129
  93. data/lib/steep/project/stats_calculator.rb +0 -80
  94. data/lib/steep/server/code_worker.rb +0 -150
  95. data/lib/steep/server/signature_worker.rb +0 -157
  96. data/lib/steep/server/utils.rb +0 -69
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fe01659cf0cfc1c7063fede02ec238b5772bb6c6fdf44cf501ca555c719c47c
4
- data.tar.gz: d74ebe84a911514eef46cd92a14dfedc0b90e491aa9bf284f82325a9c4a9c2b4
3
+ metadata.gz: 3c26760f5348c69f081ab2af0c680f6cbfb2e022c4bcd407a082c28fb818da46
4
+ data.tar.gz: cda7a96c3f8aca4c1ab7bed5b016b470253669c26cdb6d943b3d3430091c707f
5
5
  SHA512:
6
- metadata.gz: cd2459353ab367c913f0308b1cb0dd95d297cce18ea3bb4ff537612edc0b8adc2ef4530d4bf8203c6c777fe57b8bccfbf8a8714ebc0ede67400a030e6ea1348f
7
- data.tar.gz: b3ee38f5e340f05420783dc3f8a31ac662f475ec7bcef82222e5f07360faac1235249fa903c721a1d322b7999034b74e7f812fa47c3d3dec8a9f5763fa2693fb
6
+ metadata.gz: 1a4d1739de1974adb441c5830396ff6e79e901d55eed3e486f3b4ab5c394aa23254ccac0d8a63a5f78084e1c8cecb10a1faaddd53b8c963c8bab2b19b9aad910
7
+ data.tar.gz: a6b2c6c29ebca50f812062a7f7cacaaa2e6304fbbff6ff71c5a9c3ddf3d0e95341ebee5b34df090b360dc64529763eda9a6ce3cf435481a50f0a28d6fd338853
data/CHANGELOG.md CHANGED
@@ -2,6 +2,45 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.44.1 (2021-04-23)
6
+
7
+ * Disable goto declaration and goto type declaration (because they are not implemented) ([#377](https://github.com/soutaro/steep/pull/377))
8
+ * Fix goto from block calls ([#378](https://github.com/soutaro/steep/pull/378))
9
+
10
+ ## 0.44.0 (2021-04-22)
11
+
12
+ * Implement LSP go to definition/implementation ([#371](https://github.com/soutaro/steep/pull/371), [#375](https://github.com/soutaro/steep/pull/375))
13
+ * Fix typing on passing optional block ([#373](https://github.com/soutaro/steep/pull/373))
14
+ * Do not crash when completion request `context` is missing ([#370](https://github.com/soutaro/steep/pull/370))
15
+ * Update RBS ([#376](https://github.com/soutaro/steep/pull/376))
16
+
17
+ ## 0.43.1 (2021-04-01)
18
+
19
+ * Fix LSP `textDocument/didSave` notification handling ([#368](https://github.com/soutaro/steep/issues/368))
20
+
21
+ ## 0.43.0 (2021-03-30)
22
+
23
+ * LSP responsiveness improvements ([\#352](https://github.com/soutaro/steep/issues/352))
24
+ * `@implements` annotation in blocks ([#338](https://github.com/soutaro/steep/issues/338))
25
+ * Better `steep stats` table formatting ([\#300](https://github.com/soutaro/steep/issues/300))
26
+ * Fix retry type checking ([\#293](https://github.com/soutaro/steep/issues/293))
27
+ * Better tuple type checking ([\#328](https://github.com/soutaro/steep/issues/328))
28
+ * Fix unexpected `add_call` error ([\#358](https://github.com/soutaro/steep/pull/358))
29
+ * Ignore passing nil as a block `&nil` ([\#356](https://github.com/soutaro/steep/pull/356))
30
+ * Better type checking for non-trivial block parameters ([\#354](https://github.com/soutaro/steep/pull/354))
31
+ * Avoid unexpected error on splat assignments ([\#330](https://github.com/soutaro/steep/pull/330))
32
+ * Fix constraint solver ([\#343](https://github.com/soutaro/steep/pull/343))
33
+ * Ruby 2.7 compatible private method call typing ([\#344](https://github.com/soutaro/steep/pull/344))
34
+
35
+ ## 0.42.0 (2021-03-08)
36
+
37
+ * 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))
38
+ * Let `watch` command support files ([\#323](https://github.com/soutaro/steep/pull/323))
39
+ * Validate _module-self-type_ constraints ([\#308](https://github.com/soutaro/steep/pull/308))
40
+ * 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))
41
+ * Fix `code` of RBS diagnostics ([\#306](https://github.com/soutaro/steep/pull/306))
42
+ * Skip printing source code from out of date _expectations_ file ([\#305](https://github.com/soutaro/steep/pull/305))
43
+
5
44
  ## 0.41.0 (2021-02-07)
6
45
 
7
46
  * Add `--with-expectations` and `--save-expectations` option ([#303](https://github.com/soutaro/steep/pull/303))
data/Gemfile CHANGED
@@ -12,3 +12,4 @@ gem "racc", "~> 1.4"
12
12
  gem "minitest-reporters"
13
13
  gem "minitest-hooks"
14
14
  gem "stackprof"
15
+ gem "rbs", git: "https://github.com/ruby/rbs.git"
data/bin/output_test.rb CHANGED
@@ -16,6 +16,8 @@ end
16
16
 
17
17
  failed_tests = []
18
18
 
19
+ ALLOW_FAILURE = ["diagnostics-ruby-unsat"]
20
+
19
21
  test_dirs.each do |dir|
20
22
  puts "Running test #{dir}..."
21
23
 
@@ -30,8 +32,12 @@ test_dirs.each do |dir|
30
32
  output, status = Open3.capture2(*command, chdir: dir.to_s)
31
33
 
32
34
  unless status.success?
33
- failed_tests << dir.basename
34
- puts " Failed! 🤕"
35
+ unless ALLOW_FAILURE.include?(dir.basename.to_s)
36
+ failed_tests << dir.basename
37
+ puts " Failed! 🤕"
38
+ else
39
+ puts " Failed! 🤕 (ALLOW_FAILURE)"
40
+ end
35
41
  else
36
42
  puts " Succeed! 👍"
37
43
  end
data/lib/steep.rb CHANGED
@@ -2,7 +2,6 @@ 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"
7
6
  require "active_support/core_ext/string/inflections"
8
7
  require "logger"
@@ -15,6 +14,10 @@ require "open3"
15
14
  require "stringio"
16
15
  require 'uri'
17
16
  require "yaml"
17
+ require "securerandom"
18
+
19
+ require "parallel/processor_count"
20
+ require "terminal-table"
18
21
 
19
22
  require "rbs"
20
23
 
@@ -86,27 +89,32 @@ require "steep/index/rbs_index"
86
89
  require "steep/index/signature_symbol_provider"
87
90
  require "steep/index/source_index"
88
91
 
89
- require "steep/server/utils"
92
+ require "steep/server/change_buffer"
90
93
  require "steep/server/base_worker"
91
- require "steep/server/code_worker"
92
- require "steep/server/signature_worker"
93
94
  require "steep/server/worker_process"
94
95
  require "steep/server/interaction_worker"
96
+ require "steep/server/type_check_worker"
95
97
  require "steep/server/master"
96
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
+ require "steep/services/goto_service"
108
+
97
109
  require "steep/project"
98
- require "steep/project/signature_file"
99
- require "steep/project/source_file"
110
+ require "steep/project/pattern"
100
111
  require "steep/project/options"
101
112
  require "steep/project/target"
102
113
  require "steep/project/dsl"
103
- require "steep/project/file_loader"
104
- require "steep/project/hover_content"
105
- require "steep/project/completion_provider"
106
- require "steep/project/stats_calculator"
107
114
 
108
115
  require "steep/expectations"
109
116
  require "steep/drivers/utils/driver_helper"
117
+ require "steep/drivers/utils/jobs_count"
110
118
  require "steep/drivers/check"
111
119
  require "steep/drivers/stats"
112
120
  require "steep/drivers/validate"
@@ -134,7 +142,7 @@ module Steep
134
142
  def self.new_logger(output, prev_level)
135
143
  ActiveSupport::TaggedLogging.new(Logger.new(output)).tap do |logger|
136
144
  logger.push_tags "Steep #{VERSION}"
137
- logger.level = prev_level || Logger::WARN
145
+ logger.level = prev_level || Logger::ERROR
138
146
  end
139
147
  end
140
148
 
@@ -151,18 +159,80 @@ module Steep
151
159
  @logger = nil
152
160
  self.log_output = STDERR
153
161
 
154
- def self.measure(message)
162
+ def self.measure(message, level: :warn)
155
163
  start = Time.now
156
164
  yield.tap do
157
165
  time = Time.now - start
158
- self.logger.info "#{message} took #{time} seconds"
166
+ if level.is_a?(Symbol)
167
+ level = Logger.const_get(level.to_s.upcase)
168
+ end
169
+ self.logger.log(level) { "#{message} took #{time} seconds" }
159
170
  end
160
171
  end
161
172
 
162
173
  def self.log_error(exn, message: "Unexpected error: #{exn.inspect}")
163
- Steep.logger.error message
174
+ Steep.logger.fatal message
164
175
  exn.backtrace.each do |loc|
165
- Steep.logger.warn " #{loc}"
176
+ Steep.logger.error " #{loc}"
177
+ end
178
+ end
179
+
180
+ class Sampler
181
+ def initialize()
182
+ @samples = []
183
+ end
184
+
185
+ def sample(message)
186
+ start = Time.now
187
+ yield.tap do
188
+ time = Time.now - start
189
+ @samples << [message, time]
190
+ end
191
+ end
192
+
193
+ def count
194
+ @samples.count
166
195
  end
196
+
197
+ def total
198
+ @samples.sum(&:last)
199
+ end
200
+
201
+ def slowests(num)
202
+ @samples.sort_by(&:last).reverse.take(num)
203
+ end
204
+
205
+ def average
206
+ if count > 0
207
+ total/count
208
+ else
209
+ 0
210
+ end
211
+ end
212
+
213
+ def percentile(p)
214
+ slowests(count - count * p / 100r).last&.last || 0
215
+ end
216
+ end
217
+
218
+ def self.measure2(message, level: :warn)
219
+ sampler = Sampler.new
220
+ result = yield(sampler)
221
+
222
+ if level.is_a?(Symbol)
223
+ level = Logger.const_get(level.to_s.upcase)
224
+ end
225
+ logger.log(level) { "#{sampler.total}secs for \"#{message}\"" }
226
+ logger.log(level) { " Average: #{sampler.average}secs"}
227
+ logger.log(level) { " Median: #{sampler.percentile(50)}secs"}
228
+ logger.log(level) { " Samples: #{sampler.count}"}
229
+ logger.log(level) { " 99 percentile: #{sampler.percentile(99)}secs"}
230
+ logger.log(level) { " 90 percentile: #{sampler.percentile(90)}secs"}
231
+ logger.log(level) { " 10 Slowests:"}
232
+ sampler.slowests(10).each do |message, time|
233
+ logger.log(level) { " #{message} (#{time}secs)"}
234
+ end
235
+
236
+ result
167
237
  end
168
238
  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
@@ -64,6 +66,14 @@ module Steep
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|
@@ -89,6 +99,7 @@ module Steep
89
99
  opts.on("--save-expectations[=PATH]", "Save expectations with current type check result to PATH (or steep_expectations.yml)") do |path|
90
100
  check.save_expectations_path = Pathname(path || "steep_expectations.yml")
91
101
  end
102
+ handle_jobs_option check, opts
92
103
  handle_logging_options opts
93
104
  end.parse!(argv)
94
105
 
@@ -102,6 +113,8 @@ module Steep
102
113
  opts.banner = "Usage: steep stats [options] [sources]"
103
114
 
104
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
105
118
  handle_logging_options opts
106
119
  end.parse!(argv)
107
120
 
@@ -142,10 +155,12 @@ module Steep
142
155
  Drivers::Watch.new(stdout: stdout, stderr: stderr).tap do |command|
143
156
  OptionParser.new do |opts|
144
157
  opts.banner = "Usage: steep watch [options] [dirs]"
158
+ handle_jobs_option command, opts
145
159
  handle_logging_options opts
146
160
  end.parse!(argv)
147
161
 
148
- command.dirs.push *argv
162
+ dirs = argv.map {|dir| Pathname(dir) }
163
+ command.dirs.push(*dirs)
149
164
  end.run
150
165
  end
151
166
 
@@ -153,6 +168,7 @@ module Steep
153
168
  Drivers::Langserver.new(stdout: stdout, stderr: stderr, stdin: stdin).tap do |command|
154
169
  OptionParser.new do |opts|
155
170
  opts.on("--steepfile=PATH") {|path| command.steepfile = Pathname(path) }
171
+ handle_jobs_option command, opts, -1
156
172
  handle_logging_options opts
157
173
  end.parse!(argv)
158
174
  end.run
@@ -185,12 +201,15 @@ module Steep
185
201
  handle_logging_options opts
186
202
 
187
203
  opts.on("--interaction") { command.worker_type = :interaction }
188
- opts.on("--code") { command.worker_type = :code }
189
- opts.on("--signature") { command.worker_type = :signature }
204
+ opts.on("--typecheck") { command.worker_type = :typecheck }
190
205
  opts.on("--steepfile=PATH") {|path| command.steepfile = Pathname(path) }
191
206
  opts.on("--name=NAME") {|name| command.worker_name = name }
192
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) }
193
210
  end.parse!(argv)
211
+
212
+ command.commandline_args.push(*argv)
194
213
  end.run
195
214
  end
196
215
  end
@@ -220,10 +220,6 @@ module Steep
220
220
  def header_line
221
221
  "The method cannot be called with a block"
222
222
  end
223
-
224
- def to_s
225
- format_message "method_type=#{method_type}"
226
- end
227
223
  end
228
224
 
229
225
  class RequiredBlockMissing < Base
@@ -395,8 +391,8 @@ module Steep
395
391
  @method = method
396
392
  end
397
393
 
398
- def to_s
399
- format_message "method=#{method}"
394
+ def header_line
395
+ "No superclass method `#{method}` defined"
400
396
  end
401
397
  end
402
398
 
@@ -613,9 +609,18 @@ module Steep
613
609
  def header_line
614
610
  "UnexpectedError: #{error.message}"
615
611
  end
612
+ end
616
613
 
617
- def detail_lines
618
- error.backtrace.join("\n")
614
+ class SyntaxError < Base
615
+ attr_reader :message
616
+
617
+ def initialize(message: ,location:)
618
+ super(node: nil, location: location)
619
+ @message = message
620
+ end
621
+
622
+ def header_line
623
+ "SyntaxError: #{message}"
619
624
  end
620
625
  end
621
626
  end
@@ -21,7 +21,7 @@ module Steep
21
21
  end
22
22
 
23
23
  def diagnostic_code
24
- "Ruby::#{error_name}"
24
+ "RBS::#{error_name}"
25
25
  end
26
26
 
27
27
  def path
@@ -37,8 +37,26 @@ module Steep
37
37
  @exception = exception
38
38
  end
39
39
 
40
+ def self.parser_syntax_error_message(exception)
41
+ value = if exception.error_value.is_a?(RBS::Parser::LocatedValue)
42
+ exception.error_value.value
43
+ else
44
+ exception.error_value
45
+ end
46
+ string = value.to_s
47
+ unless string.empty?
48
+ string = " (#{string})"
49
+ end
50
+
51
+ "Syntax error caused by token `#{exception.token_str}`#{string}"
52
+ end
53
+
40
54
  def header_line
41
- "Syntax error: #{exception.message}"
55
+ if exception.is_a?(RBS::Parser::SyntaxError)
56
+ SyntaxError.parser_syntax_error_message(exception)
57
+ else
58
+ exception.message
59
+ end
42
60
  end
43
61
  end
44
62
 
@@ -219,6 +237,138 @@ module Steep
219
237
  "The variance of type parameter `#{param.name}` is #{param.variance}, but used in incompatible position here"
220
238
  end
221
239
  end
240
+
241
+ class ModuleSelfTypeError < Base
242
+ attr_reader :name
243
+ attr_reader :ancestor
244
+ attr_reader :relation
245
+
246
+ def initialize(name:, ancestor:, relation:, location:)
247
+ super(location: location)
248
+
249
+ @name = name
250
+ @ancestor = ancestor
251
+ @relation = relation
252
+ end
253
+
254
+ def header_line
255
+ "Module self type constraint in type `#{name}` doesn't satisfy: `#{relation}`"
256
+ end
257
+ end
258
+
259
+ class InstanceVariableTypeError < Base
260
+ attr_reader :name
261
+ attr_reader :variable
262
+ attr_reader :var_type
263
+ attr_reader :parent_type
264
+
265
+ def initialize(name:, location:, var_type:, parent_type:)
266
+ super(location: location)
267
+
268
+ @name = name
269
+ @var_type = var_type
270
+ @parent_type = parent_type
271
+ end
272
+
273
+ def header_line
274
+ "Instance variable cannot have different type with parents: #{var_type} <=> #{parent_type}"
275
+ end
276
+ end
277
+
278
+ class UnexpectedError < Base
279
+ attr_reader :message
280
+
281
+ def initialize(message:, location:)
282
+ @message = message
283
+ @location = location
284
+ end
285
+
286
+ def header_line
287
+ "Unexpected error: #{message}"
288
+ end
289
+ end
290
+
291
+ def self.from_rbs_error(error, factory:)
292
+ case error
293
+ when RBS::Parser::SemanticsError, RBS::Parser::LexerError
294
+ Diagnostic::Signature::SyntaxError.new(error, location: error.location)
295
+ when RBS::Parser::SyntaxError
296
+ Diagnostic::Signature::SyntaxError.new(error, location: error.error_value.location)
297
+ when RBS::DuplicatedDeclarationError
298
+ Diagnostic::Signature::DuplicatedDeclaration.new(
299
+ type_name: error.name,
300
+ location: error.decls[0].location
301
+ )
302
+ when RBS::GenericParameterMismatchError
303
+ Diagnostic::Signature::GenericParameterMismatch.new(
304
+ name: error.name,
305
+ location: error.decl.location
306
+ )
307
+ when RBS::InvalidTypeApplicationError
308
+ Diagnostic::Signature::InvalidTypeApplication.new(
309
+ name: error.type_name,
310
+ args: error.args.map {|ty| factory.type(ty) },
311
+ params: error.params,
312
+ location: error.location
313
+ )
314
+ when RBS::NoTypeFoundError,
315
+ RBS::NoSuperclassFoundError,
316
+ RBS::NoMixinFoundError,
317
+ RBS::NoSelfTypeFoundError
318
+ Diagnostic::Signature::UnknownTypeName.new(
319
+ name: error.type_name,
320
+ location: error.location
321
+ )
322
+ when RBS::InvalidOverloadMethodError
323
+ Diagnostic::Signature::InvalidMethodOverload.new(
324
+ class_name: error.type_name,
325
+ method_name: error.method_name,
326
+ location: error.members[0].location
327
+ )
328
+ when RBS::DuplicatedMethodDefinitionError
329
+ Diagnostic::Signature::DuplicatedMethodDefinition.new(
330
+ class_name: error.type_name,
331
+ method_name: error.method_name,
332
+ location: error.location
333
+ )
334
+ when RBS::DuplicatedInterfaceMethodDefinitionError
335
+ Diagnostic::Signature::DuplicatedMethodDefinition.new(
336
+ class_name: error.type_name,
337
+ method_name: error.method_name,
338
+ location: error.member.location
339
+ )
340
+ when RBS::UnknownMethodAliasError
341
+ Diagnostic::Signature::UnknownMethodAlias.new(
342
+ class_name: error.type_name,
343
+ method_name: error.original_name,
344
+ location: error.location
345
+ )
346
+ when RBS::RecursiveAliasDefinitionError
347
+ Diagnostic::Signature::RecursiveAlias.new(
348
+ class_name: error.type.name,
349
+ names: error.defs.map(&:name),
350
+ location: error.defs[0].original.location
351
+ )
352
+ when RBS::RecursiveAncestorError
353
+ Diagnostic::Signature::RecursiveAncestor.new(
354
+ ancestors: error.ancestors,
355
+ location: error.location
356
+ )
357
+ when RBS::SuperclassMismatchError
358
+ Diagnostic::Signature::SuperclassMismatch.new(
359
+ name: error.name,
360
+ location: error.entry.primary.decl.location
361
+ )
362
+ when RBS::InvalidVarianceAnnotationError
363
+ Diagnostic::Signature::InvalidVarianceAnnotation.new(
364
+ name: error.type_name,
365
+ param: error.param,
366
+ location: error.location
367
+ )
368
+ else
369
+ raise error
370
+ end
371
+ end
222
372
  end
223
373
  end
224
374
  end