steep 0.44.1 → 0.47.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +8 -0
  3. data/.github/workflows/ruby.yml +3 -2
  4. data/.gitignore +0 -1
  5. data/CHANGELOG.md +43 -0
  6. data/Gemfile +1 -4
  7. data/Gemfile.lock +73 -0
  8. data/README.md +2 -1
  9. data/lib/steep/annotation_parser.rb +1 -1
  10. data/lib/steep/ast/builtin.rb +7 -1
  11. data/lib/steep/ast/types/factory.rb +19 -25
  12. data/lib/steep/cli.rb +7 -1
  13. data/lib/steep/diagnostic/lsp_formatter.rb +59 -6
  14. data/lib/steep/diagnostic/ruby.rb +188 -60
  15. data/lib/steep/diagnostic/signature.rb +38 -15
  16. data/lib/steep/drivers/check.rb +3 -0
  17. data/lib/steep/drivers/init.rb +10 -3
  18. data/lib/steep/drivers/utils/driver_helper.rb +15 -0
  19. data/lib/steep/drivers/validate.rb +1 -1
  20. data/lib/steep/drivers/watch.rb +3 -0
  21. data/lib/steep/equatable.rb +21 -0
  22. data/lib/steep/interface/function.rb +798 -579
  23. data/lib/steep/project/dsl.rb +135 -36
  24. data/lib/steep/project/options.rb +13 -53
  25. data/lib/steep/project/target.rb +22 -8
  26. data/lib/steep/server/interaction_worker.rb +245 -26
  27. data/lib/steep/server/type_check_worker.rb +6 -9
  28. data/lib/steep/services/file_loader.rb +26 -19
  29. data/lib/steep/services/hover_content.rb +135 -80
  30. data/lib/steep/source.rb +12 -11
  31. data/lib/steep/type_construction.rb +435 -502
  32. data/lib/steep/type_inference/block_params.rb +3 -6
  33. data/lib/steep/type_inference/method_params.rb +483 -0
  34. data/lib/steep/type_inference/send_args.rb +599 -128
  35. data/lib/steep/typing.rb +46 -21
  36. data/lib/steep/version.rb +1 -1
  37. data/lib/steep.rb +5 -3
  38. data/sample/Steepfile +10 -3
  39. data/smoke/alias/Steepfile +2 -1
  40. data/smoke/and/Steepfile +2 -1
  41. data/smoke/array/Steepfile +2 -1
  42. data/smoke/array/test_expectations.yml +3 -3
  43. data/smoke/block/Steepfile +2 -2
  44. data/smoke/block/c.rb +0 -1
  45. data/smoke/case/Steepfile +2 -1
  46. data/smoke/class/Steepfile +2 -1
  47. data/smoke/class/test_expectations.yml +12 -15
  48. data/smoke/const/Steepfile +2 -1
  49. data/smoke/diagnostics/Steepfile +2 -1
  50. data/smoke/diagnostics/different_method_parameter_kind.rb +9 -0
  51. data/smoke/diagnostics/method_arity_mismatch.rb +2 -2
  52. data/smoke/diagnostics/method_parameter_mismatch.rb +10 -0
  53. data/smoke/diagnostics/test_expectations.yml +108 -31
  54. data/smoke/diagnostics-rbs/Steepfile +1 -1
  55. data/smoke/diagnostics-rbs/mixin-class-error.rbs +6 -0
  56. data/smoke/diagnostics-rbs/test_expectations.yml +12 -0
  57. data/smoke/diagnostics-rbs-duplicated/Steepfile +2 -1
  58. data/smoke/diagnostics-ruby-unsat/Steepfile +2 -1
  59. data/smoke/dstr/Steepfile +2 -1
  60. data/smoke/ensure/Steepfile +2 -1
  61. data/smoke/ensure/test_expectations.yml +3 -3
  62. data/smoke/enumerator/Steepfile +2 -1
  63. data/smoke/enumerator/test_expectations.yml +1 -1
  64. data/smoke/extension/Steepfile +2 -1
  65. data/smoke/extension/e.rbs +1 -1
  66. data/smoke/hash/Steepfile +2 -1
  67. data/smoke/hello/Steepfile +2 -1
  68. data/smoke/if/Steepfile +2 -1
  69. data/smoke/implements/Steepfile +2 -1
  70. data/smoke/initialize/Steepfile +2 -1
  71. data/smoke/integer/Steepfile +2 -1
  72. data/smoke/interface/Steepfile +2 -1
  73. data/smoke/kwbegin/Steepfile +2 -1
  74. data/smoke/lambda/Steepfile +2 -1
  75. data/smoke/literal/Steepfile +2 -1
  76. data/smoke/literal/test_expectations.yml +2 -2
  77. data/smoke/map/Steepfile +2 -1
  78. data/smoke/method/Steepfile +2 -1
  79. data/smoke/method/test_expectations.yml +11 -10
  80. data/smoke/module/Steepfile +2 -1
  81. data/smoke/regexp/Steepfile +2 -1
  82. data/smoke/regression/Steepfile +2 -1
  83. data/smoke/rescue/Steepfile +2 -1
  84. data/smoke/rescue/test_expectations.yml +3 -3
  85. data/smoke/self/Steepfile +2 -1
  86. data/smoke/skip/Steepfile +2 -1
  87. data/smoke/stdout/Steepfile +2 -1
  88. data/smoke/super/Steepfile +2 -1
  89. data/smoke/toplevel/Steepfile +2 -1
  90. data/smoke/toplevel/test_expectations.yml +3 -3
  91. data/smoke/tsort/Steepfile +4 -5
  92. data/smoke/tsort/test_expectations.yml +2 -2
  93. data/smoke/type_case/Steepfile +2 -1
  94. data/smoke/unexpected/Steepfile +2 -1
  95. data/smoke/yield/Steepfile +2 -1
  96. data/steep.gemspec +2 -2
  97. metadata +16 -10
  98. data/sig/project.rbi +0 -109
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c26760f5348c69f081ab2af0c680f6cbfb2e022c4bcd407a082c28fb818da46
4
- data.tar.gz: cda7a96c3f8aca4c1ab7bed5b016b470253669c26cdb6d943b3d3430091c707f
3
+ metadata.gz: f249f7e074584c271aace34633e7eebaf638c53faa821adc8ba20575c44781ac
4
+ data.tar.gz: 19630a5254b0b1d1a0f10dd2d2300111c47773ac5f615ccfe7d33f815edf38c2
5
5
  SHA512:
6
- metadata.gz: 1a4d1739de1974adb441c5830396ff6e79e901d55eed3e486f3b4ab5c394aa23254ccac0d8a63a5f78084e1c8cecb10a1faaddd53b8c963c8bab2b19b9aad910
7
- data.tar.gz: a6b2c6c29ebca50f812062a7f7cacaaa2e6304fbbff6ff71c5a9c3ddf3d0e95341ebee5b34df090b360dc64529763eda9a6ce3cf435481a50f0a28d6fd338853
6
+ metadata.gz: d29cf28bca4f9235a7036e966edb7747872ebcd0a49bec3d6d21dcad73dc2f21cec05819b05b4df52b150bd24f998d533fd63b827f439462f3ce4b7173041ecd
7
+ data.tar.gz: 49f76f139a14b94449a19f1c26847b320fc104ce292eb6f9824bac58b99b0f7b1997c0daf405cb37e58a5ec42d011daa221431d0f7056a326dba5922a72f096e
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "20:00"
8
+ open-pull-requests-limit: 10
@@ -12,8 +12,9 @@ jobs:
12
12
  strategy:
13
13
  matrix:
14
14
  container_tag:
15
- - 2.6.5-bionic
16
- - 2.7.0-bionic
15
+ - "2.7"
16
+ - "3.0"
17
+ - "master-nightly-focal"
17
18
  task:
18
19
  - test
19
20
  - test:output
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
data/CHANGELOG.md CHANGED
@@ -2,6 +2,49 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.47.1 (2022-02-17)
6
+
7
+ This update lets Steep run with Active Support 7.
8
+
9
+ * Fix ActiveSupport requirement in `lib/steep.rb` ([#484](https://github.com/soutaro/steep/pull/484))
10
+
11
+ ## 0.47.0 (2021-11-30)
12
+
13
+ This update contains update for RBS 1.7.
14
+
15
+ * RBS 1.7 ([#455](https://github.com/soutaro/steep/pull/455))
16
+ * Bug fixes related to `SendArgs` ([#444](https://github.com/soutaro/steep/pull/444), [#449](https://github.com/soutaro/steep/pull/449), [#451](https://github.com/soutaro/steep/pull/451))
17
+ * LSP completion item formatting improvement ([#442](https://github.com/soutaro/steep/pull/442))
18
+
19
+ ## 0.46.0 (2021-08-30)
20
+
21
+ This release updates Steepfile DSL syntax, introducing `stdlib_path` and `configure_code_diagnostics` syntax (methods).
22
+
23
+ * `stdlib_path` allows configuring core/stdlib RBS file locations.
24
+ * `configure_code_diagnostics` allows configuring _severity_ of each type errors.
25
+
26
+ See the PRs for the explanation of these methods.
27
+ You can try `steep init` to generate updated `Steepfile` template.
28
+
29
+ * Flexible diagnostics configuration ([\#422](https://github.com/soutaro/steep/pull/422), [\#423](https://github.com/soutaro/steep/pull/423))
30
+ * Revise Steepfile _path_ DSL ([\#421](https://github.com/soutaro/steep/pull/421))
31
+ * Avoid to stop process by invalid jobs_count ([\#419](https://github.com/soutaro/steep/pull/419))
32
+ * Fix `Steep::Typing::UnknownNodeError` when hover method with numblock ([\#415](https://github.com/soutaro/steep/pull/415))
33
+
34
+ ## 0.45.0 (2021-08-22)
35
+
36
+ * Fix error reporting on `RBS::MixinClassError` ([\#411](https://github.com/soutaro/steep/pull/411))
37
+ * Compact error reporting for method body type mismatch ([\#414](https://github.com/soutaro/steep/pull/414))
38
+ * Fix NoMethodError with csend/numblock ([\#412](https://github.com/soutaro/steep/pull/412))
39
+ * LSP completion for RBS files ([\#404](https://github.com/soutaro/steep/pull/404))
40
+ * Allow break without value from bot methods ([\#398](https://github.com/soutaro/steep/pull/398))
41
+ * Type check on lvar assignments ([\#390](https://github.com/soutaro/steep/pull/390))
42
+ * Assign different error code to break without value ([\#387](https://github.com/soutaro/steep/pull/387))
43
+ * Support Ruby3 Keyword Arguments ([\#386](https://github.com/soutaro/steep/pull/386))
44
+ * LSP hover for RBS files ([\#385](https://github.com/soutaro/steep/pull/385), [\#397](https://github.com/soutaro/steep/pull/397))
45
+ * Fix FileLoader to skip files not matching to the given pattern ([\#382](https://github.com/soutaro/steep/pull/382))
46
+ * Ruby3 support for numbered block parameters and end-less def ([\#381](https://github.com/soutaro/steep/pull/381))
47
+
5
48
  ## 0.44.1 (2021-04-23)
6
49
 
7
50
  * Disable goto declaration and goto type declaration (because they are not implemented) ([#377](https://github.com/soutaro/steep/pull/377))
data/Gemfile CHANGED
@@ -7,9 +7,6 @@ gem "with_steep_types", path: "test/gems/with_steep_types"
7
7
  gem "without_steep_types", path: "test/gems/without_steep_types"
8
8
 
9
9
  gem "rake"
10
- gem "minitest", "~> 5.0"
11
- gem "racc", "~> 1.4"
12
- gem "minitest-reporters"
10
+ gem "minitest", "~> 5.15"
13
11
  gem "minitest-hooks"
14
12
  gem "stackprof"
15
- gem "rbs", git: "https://github.com/ruby/rbs.git"
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ steep (0.47.1)
5
+ activesupport (>= 5.1)
6
+ language_server-protocol (>= 3.15, < 4.0)
7
+ listen (~> 3.0)
8
+ parallel (>= 1.0.0)
9
+ parser (>= 3.0)
10
+ rainbow (>= 2.2.2, < 4.0)
11
+ rbs (~> 1.7.0)
12
+ terminal-table (>= 2, < 4)
13
+
14
+ PATH
15
+ remote: test/gems/with_steep_types
16
+ specs:
17
+ with_steep_types (1.0.0)
18
+
19
+ PATH
20
+ remote: test/gems/without_steep_types
21
+ specs:
22
+ without_steep_types (1.0.0)
23
+
24
+ GEM
25
+ remote: https://rubygems.org/
26
+ specs:
27
+ activesupport (7.0.2.2)
28
+ concurrent-ruby (~> 1.0, >= 1.0.2)
29
+ i18n (>= 1.6, < 2)
30
+ minitest (>= 5.1)
31
+ tzinfo (~> 2.0)
32
+ ast (2.4.2)
33
+ concurrent-ruby (1.1.9)
34
+ ffi (1.15.5)
35
+ i18n (1.10.0)
36
+ concurrent-ruby (~> 1.0)
37
+ language_server-protocol (3.16.0.3)
38
+ listen (3.7.1)
39
+ rb-fsevent (~> 0.10, >= 0.10.3)
40
+ rb-inotify (~> 0.9, >= 0.9.10)
41
+ minitest (5.15.0)
42
+ minitest-hooks (1.5.0)
43
+ minitest (> 5.3)
44
+ parallel (1.21.0)
45
+ parser (3.1.0.0)
46
+ ast (~> 2.4.1)
47
+ rainbow (3.1.1)
48
+ rake (13.0.6)
49
+ rb-fsevent (0.11.1)
50
+ rb-inotify (0.10.1)
51
+ ffi (~> 1.0)
52
+ rbs (1.7.1)
53
+ stackprof (0.2.17)
54
+ terminal-table (3.0.2)
55
+ unicode-display_width (>= 1.1.1, < 3)
56
+ tzinfo (2.0.4)
57
+ concurrent-ruby (~> 1.0)
58
+ unicode-display_width (2.1.0)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ minitest (~> 5.15)
65
+ minitest-hooks
66
+ rake
67
+ stackprof
68
+ steep!
69
+ with_steep_types!
70
+ without_steep_types!
71
+
72
+ BUNDLED WITH
73
+ 2.2.27
data/README.md CHANGED
@@ -8,7 +8,7 @@ Install via RubyGems.
8
8
 
9
9
  ### Requirements
10
10
 
11
- Steep requires Ruby 2.6.
11
+ Steep requires Ruby 2.6 or later.
12
12
 
13
13
  ## Usage
14
14
 
@@ -126,6 +126,7 @@ end
126
126
 
127
127
  class Phone
128
128
  # @dynamic country, number
129
+ attr_reader :country, :number
129
130
 
130
131
  def initialize(country:, number:)
131
132
  @country = country
@@ -25,7 +25,7 @@ module Steep
25
25
  @location = location
26
26
 
27
27
  message = case exn
28
- when RBS::Parser::SyntaxError
28
+ when RBS::ParsingError
29
29
  Diagnostic::Signature::SyntaxError.parser_syntax_error_message(exn)
30
30
  else
31
31
  exn.message
@@ -10,8 +10,14 @@ module Steep
10
10
  @arity = arity
11
11
  end
12
12
 
13
- def instance_type(*args)
13
+ def instance_type(*args, fill_untyped: false)
14
+ if fill_untyped
15
+ (arity - args.size).times do
16
+ args << Builtin.any_type
17
+ end
18
+ end
14
19
  arity == args.size or raise "Mulformed instance type: name=#{module_name}, args=#{args}"
20
+
15
21
  Types::Name::Instance.new(name: module_name, args: args)
16
22
  end
17
23
 
@@ -194,7 +194,7 @@ module Steep
194
194
  end
195
195
 
196
196
  def params(type)
197
- Interface::Function::Params.new(
197
+ Interface::Function::Params.build(
198
198
  required: type.required_positionals.map {|param| type(param.type) },
199
199
  optional: type.optional_positionals.map {|param| type(param.type) },
200
200
  rest: type.rest_positionals&.yield_self {|param| type(param.type) },
@@ -621,12 +621,7 @@ module Steep
621
621
  Interface::MethodType.new(
622
622
  type_params: [],
623
623
  type: Interface::Function.new(
624
- params: Interface::Function::Params.new(required: [AST::Types::Literal.new(value: index)],
625
- optional: [],
626
- rest: nil,
627
- required_keywords: {},
628
- optional_keywords: {},
629
- rest_keywords: nil),
624
+ params: Interface::Function::Params.build(required: [AST::Types::Literal.new(value: index)]),
630
625
  return_type: elem_type,
631
626
  location: nil
632
627
  ),
@@ -643,12 +638,7 @@ module Steep
643
638
  Interface::MethodType.new(
644
639
  type_params: [],
645
640
  type: Interface::Function.new(
646
- params: Interface::Function::Params.new(required: [AST::Types::Literal.new(value: index), elem_type],
647
- optional: [],
648
- rest: nil,
649
- required_keywords: {},
650
- optional_keywords: {},
651
- rest_keywords: nil),
641
+ params: Interface::Function::Params.build(required: [AST::Types::Literal.new(value: index), elem_type]),
652
642
  return_type: elem_type,
653
643
  location: nil
654
644
  ),
@@ -712,12 +702,14 @@ module Steep
712
702
  Interface::MethodType.new(
713
703
  type_params: [],
714
704
  type: Interface::Function.new(
715
- params: Interface::Function::Params.new(required: [key_type],
716
- optional: [],
717
- rest: nil,
718
- required_keywords: {},
719
- optional_keywords: {},
720
- rest_keywords: nil),
705
+ params: Interface::Function::Params.build(
706
+ required: [key_type],
707
+ optional: [],
708
+ rest: nil,
709
+ required_keywords: {},
710
+ optional_keywords: {},
711
+ rest_keywords: nil
712
+ ),
721
713
  return_type: value_type,
722
714
  location: nil
723
715
  ),
@@ -735,12 +727,14 @@ module Steep
735
727
  Interface::MethodType.new(
736
728
  type_params: [],
737
729
  type: Interface::Function.new(
738
- params: Interface::Function::Params.new(required: [key_type, value_type],
739
- optional: [],
740
- rest: nil,
741
- required_keywords: {},
742
- optional_keywords: {},
743
- rest_keywords: nil),
730
+ params: Interface::Function::Params.build(
731
+ required: [key_type, value_type],
732
+ optional: [],
733
+ rest: nil,
734
+ required_keywords: {},
735
+ optional_keywords: {},
736
+ rest_keywords: nil
737
+ ),
744
738
  return_type: value_type,
745
739
  location: nil),
746
740
  block: nil,
data/lib/steep/cli.rb CHANGED
@@ -70,7 +70,7 @@ module Steep
70
70
  default = physical_processor_count + modifier
71
71
  command.jobs_count = default
72
72
  opts.on("-j N", "--jobs=N", "Specify the number of type check workers (defaults: #{default})") do |count|
73
- command.jobs_count = Integer(count)
73
+ command.jobs_count = Integer(count) if Integer(count) > 0
74
74
  end
75
75
  end
76
76
 
@@ -99,6 +99,9 @@ module Steep
99
99
  opts.on("--save-expectations[=PATH]", "Save expectations with current type check result to PATH (or steep_expectations.yml)") do |path|
100
100
  check.save_expectations_path = Pathname(path || "steep_expectations.yml")
101
101
  end
102
+ opts.on("--severity-level=LEVEL", /^error|warning|information|hint$/, "Specify the minimum diagnostic severity to be recognized as an error (defaults: warning): error, warning, information, or hint") do |level|
103
+ check.severity_level = level.to_sym
104
+ end
102
105
  handle_jobs_option check, opts
103
106
  handle_logging_options opts
104
107
  end.parse!(argv)
@@ -155,6 +158,9 @@ module Steep
155
158
  Drivers::Watch.new(stdout: stdout, stderr: stderr).tap do |command|
156
159
  OptionParser.new do |opts|
157
160
  opts.banner = "Usage: steep watch [options] [dirs]"
161
+ opts.on("--severity-level=LEVEL", /^error|warning|information|hint$/, "Specify the minimum diagnostic severity to be recognized as an error (defaults: warning): error, warning, information, or hint") do |level|
162
+ command.severity_level = level.to_sym
163
+ end
158
164
  handle_jobs_option command, opts
159
165
  handle_logging_options opts
160
166
  end.parse!(argv)
@@ -3,13 +3,66 @@ module Steep
3
3
  class LSPFormatter
4
4
  LSP = LanguageServer::Protocol
5
5
 
6
+ attr_reader :config
7
+ attr_reader :default_severity
8
+
9
+ ERROR = :error
10
+ WARNING = :warning
11
+ INFORMATION = :information
12
+ HINT = :hint
13
+
14
+ def initialize(config = {}, default_severity: ERROR)
15
+ @config = config
16
+ @default_severity = default_severity
17
+
18
+ config.each do |klass, severity|
19
+ validate_severity(klass, severity)
20
+ validate_class(klass)
21
+ end
22
+ validate_severity(:default, default_severity)
23
+ end
24
+
25
+ def validate_class(klass)
26
+ unless klass < Diagnostic::Ruby::Base
27
+ raise "Unexpected diagnostics class `#{klass}` given"
28
+ end
29
+ end
30
+
31
+ def validate_severity(klass, severity)
32
+ case severity
33
+ when ERROR, WARNING, INFORMATION, HINT, nil
34
+ # ok
35
+ else
36
+ raise "Unexpected severity `#{severity}` is specified for #{klass}"
37
+ end
38
+ end
39
+
6
40
  def format(diagnostic)
7
- LSP::Interface::Diagnostic.new(
8
- message: diagnostic.full_message,
9
- code: diagnostic.diagnostic_code,
10
- severity: LSP::Constant::DiagnosticSeverity::ERROR,
11
- range: diagnostic.location.as_lsp_range
12
- ).to_hash
41
+ severity = severity_for(diagnostic)
42
+
43
+ if severity
44
+ LSP::Interface::Diagnostic.new(
45
+ message: diagnostic.full_message,
46
+ code: diagnostic.diagnostic_code,
47
+ severity: severity,
48
+ range: diagnostic.location.as_lsp_range
49
+ ).to_hash
50
+ end
51
+ end
52
+
53
+ def severity_for(diagnostic)
54
+ case config.fetch(diagnostic.class, default_severity)
55
+ when ERROR
56
+ LSP::Constant::DiagnosticSeverity::ERROR
57
+ when WARNING
58
+ LSP::Constant::DiagnosticSeverity::WARNING
59
+ when INFORMATION
60
+ LSP::Constant::DiagnosticSeverity::INFORMATION
61
+ when HINT
62
+ LSP::Constant::DiagnosticSeverity::HINT
63
+ when nil
64
+ nil
65
+ end
13
66
  end
14
67
  end
15
68
  end