steep 0.25.0 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -0
  3. data/bin/smoke_runner.rb +3 -4
  4. data/bin/steep-prof +1 -2
  5. data/lib/steep.rb +6 -4
  6. data/lib/steep/annotation_parser.rb +2 -4
  7. data/lib/steep/ast/builtin.rb +11 -21
  8. data/lib/steep/ast/types.rb +5 -3
  9. data/lib/steep/ast/types/any.rb +1 -3
  10. data/lib/steep/ast/types/boolean.rb +1 -3
  11. data/lib/steep/ast/types/bot.rb +1 -3
  12. data/lib/steep/ast/types/class.rb +2 -2
  13. data/lib/steep/ast/types/factory.rb +265 -90
  14. data/lib/steep/ast/types/helper.rb +6 -0
  15. data/lib/steep/ast/types/instance.rb +2 -2
  16. data/lib/steep/ast/types/intersection.rb +20 -13
  17. data/lib/steep/ast/types/literal.rb +1 -3
  18. data/lib/steep/ast/types/logic.rb +63 -0
  19. data/lib/steep/ast/types/name.rb +15 -67
  20. data/lib/steep/ast/types/nil.rb +1 -3
  21. data/lib/steep/ast/types/proc.rb +5 -2
  22. data/lib/steep/ast/types/record.rb +9 -4
  23. data/lib/steep/ast/types/self.rb +1 -1
  24. data/lib/steep/ast/types/top.rb +1 -3
  25. data/lib/steep/ast/types/tuple.rb +5 -3
  26. data/lib/steep/ast/types/union.rb +13 -9
  27. data/lib/steep/ast/types/var.rb +2 -2
  28. data/lib/steep/ast/types/void.rb +1 -3
  29. data/lib/steep/errors.rb +14 -0
  30. data/lib/steep/interface/interface.rb +5 -62
  31. data/lib/steep/interface/method_type.rb +394 -93
  32. data/lib/steep/interface/substitution.rb +48 -6
  33. data/lib/steep/module_helper.rb +25 -0
  34. data/lib/steep/project.rb +25 -0
  35. data/lib/steep/project/completion_provider.rb +57 -58
  36. data/lib/steep/project/file_loader.rb +7 -2
  37. data/lib/steep/project/hover_content.rb +92 -83
  38. data/lib/steep/project/signature_file.rb +33 -0
  39. data/lib/steep/project/{file.rb → source_file.rb} +24 -54
  40. data/lib/steep/project/target.rb +31 -12
  41. data/lib/steep/server/base_worker.rb +5 -3
  42. data/lib/steep/server/code_worker.rb +31 -45
  43. data/lib/steep/server/interaction_worker.rb +42 -38
  44. data/lib/steep/server/master.rb +23 -31
  45. data/lib/steep/server/utils.rb +46 -13
  46. data/lib/steep/server/worker_process.rb +4 -2
  47. data/lib/steep/signature/validator.rb +3 -3
  48. data/lib/steep/source.rb +59 -2
  49. data/lib/steep/subtyping/check.rb +36 -50
  50. data/lib/steep/subtyping/constraints.rb +8 -0
  51. data/lib/steep/type_construction.rb +388 -366
  52. data/lib/steep/type_inference/block_params.rb +5 -0
  53. data/lib/steep/type_inference/constant_env.rb +2 -5
  54. data/lib/steep/type_inference/logic_type_interpreter.rb +219 -0
  55. data/lib/steep/type_inference/type_env.rb +2 -2
  56. data/lib/steep/version.rb +1 -1
  57. data/smoke/alias/a.rb +1 -1
  58. data/smoke/case/a.rb +1 -1
  59. data/smoke/hash/d.rb +1 -1
  60. data/smoke/if/a.rb +1 -1
  61. data/smoke/module/a.rb +1 -1
  62. data/smoke/rescue/a.rb +4 -13
  63. data/smoke/toplevel/Steepfile +5 -0
  64. data/smoke/toplevel/a.rb +4 -0
  65. data/smoke/toplevel/a.rbs +3 -0
  66. data/smoke/type_case/a.rb +0 -7
  67. data/steep.gemspec +3 -3
  68. metadata +17 -13
  69. data/lib/steep/ast/method_type.rb +0 -126
  70. data/lib/steep/ast/namespace.rb +0 -80
  71. data/lib/steep/names.rb +0 -86
@@ -1,126 +0,0 @@
1
- module Steep
2
- module AST
3
- class MethodType
4
- module Params
5
- class Base
6
- attr_reader :location
7
-
8
- def initialize(location:)
9
- @location = location
10
- end
11
-
12
- def update_location(location)
13
- dup.instance_eval do
14
- @location = location
15
- self
16
- end
17
- end
18
- end
19
-
20
- class Required < Base
21
- attr_reader :type
22
- attr_reader :next_params
23
-
24
- def initialize(location:, type:, next_params: nil)
25
- super(location: location)
26
- @type = type
27
- @next_params = next_params
28
- end
29
- end
30
-
31
- class Optional < Base
32
- attr_reader :type
33
- attr_reader :next_params
34
-
35
- def initialize(location:, type:, next_params: nil)
36
- super(location: location)
37
- @type = type
38
- @next_params = next_params
39
- end
40
- end
41
-
42
- class Rest < Base
43
- attr_reader :type
44
- attr_reader :next_params
45
-
46
- def initialize(location:, type:, next_params: nil)
47
- super(location: location)
48
- @type = type
49
- @next_params = next_params
50
- end
51
- end
52
-
53
- class RequiredKeyword < Base
54
- attr_reader :name
55
- attr_reader :type
56
- attr_reader :next_params
57
-
58
- def initialize(location:, name:, type:, next_params: nil)
59
- super(location: location)
60
- @name = name
61
- @type = type
62
- @next_params = next_params
63
- end
64
- end
65
-
66
- class OptionalKeyword < Base
67
- attr_reader :name
68
- attr_reader :type
69
- attr_reader :next_params
70
-
71
- def initialize(location:, name:, type:, next_params: nil)
72
- super(location: location)
73
- @name = name
74
- @type = type
75
- @next_params = next_params
76
- end
77
- end
78
-
79
- class RestKeyword < Base
80
- attr_reader :type
81
-
82
- def initialize(location:, type:)
83
- super(location: location)
84
- @type = type
85
- end
86
- end
87
- end
88
-
89
- class Block
90
- attr_reader :location
91
- attr_reader :params
92
- attr_reader :return_type
93
- attr_reader :optional
94
-
95
- def initialize(location:, params:, return_type:, optional:)
96
- @location = location
97
- @params = params
98
- @return_type = return_type
99
- @optional = optional
100
- end
101
- end
102
-
103
- attr_reader :location
104
- attr_reader :type_params
105
- attr_reader :params
106
- attr_reader :block
107
- attr_reader :return_type
108
-
109
- def initialize(location:, type_params:, params:, block:, return_type:)
110
- @location = location
111
- @type_params = type_params
112
- @params = params
113
- @block = block
114
- @return_type = return_type
115
- end
116
-
117
- class Super
118
- attr_reader :location
119
-
120
- def initialize(location:)
121
- @location = location
122
- end
123
- end
124
- end
125
- end
126
- end
@@ -1,80 +0,0 @@
1
- module Steep
2
- module AST
3
- class Namespace
4
- attr_reader :path
5
-
6
- def initialize(path:, absolute:)
7
- @path = path
8
- @absolute = absolute
9
- end
10
-
11
- def self.empty
12
- new(path: [], absolute: false)
13
- end
14
-
15
- def self.root
16
- new(path: [], absolute: true)
17
- end
18
-
19
- def +(other)
20
- if other.absolute?
21
- other
22
- else
23
- self.class.new(path: path + other.path, absolute: absolute?)
24
- end
25
- end
26
-
27
- def append(component)
28
- self.class.new(path: path + [component], absolute: absolute?)
29
- end
30
-
31
- def parent
32
- raise "Parent with empty namespace" if empty?
33
- self.class.new(path: path.take(path.size - 1), absolute: absolute?)
34
- end
35
-
36
- def absolute?
37
- @absolute
38
- end
39
-
40
- def relative?
41
- !absolute?
42
- end
43
-
44
- def absolute!
45
- self.class.new(path: path, absolute: true)
46
- end
47
-
48
- def empty?
49
- path.empty?
50
- end
51
-
52
- def ==(other)
53
- other.is_a?(Namespace) && other.path == path && other.absolute? == absolute?
54
- end
55
-
56
- alias eql? ==
57
-
58
- def hash
59
- self.class.hash ^ path.hash ^ absolute?.hash
60
- end
61
-
62
- def to_s
63
- if empty?
64
- absolute? ? "::" : ""
65
- else
66
- s = path.join("::")
67
- absolute? ? "::#{s}::" : "#{s}::"
68
- end
69
- end
70
-
71
- def self.parse(string)
72
- if string.start_with?("::")
73
- new(path: string.split("::").drop(1).map(&:to_sym), absolute: true)
74
- else
75
- new(path: string.split("::").map(&:to_sym), absolute: false)
76
- end
77
- end
78
- end
79
- end
80
- end
@@ -1,86 +0,0 @@
1
- module Steep
2
- module Names
3
- class Base
4
- attr_reader :namespace
5
- attr_reader :name
6
- attr_reader :location
7
-
8
- def initialize(namespace:, name:, location: nil)
9
- @namespace = namespace
10
- @name = name
11
- @location = location
12
- end
13
-
14
- def absolute?
15
- namespace.absolute?
16
- end
17
-
18
- def relative?
19
- !absolute?
20
- end
21
-
22
- def ==(other)
23
- other.is_a?(self.class) && other.name == name && other.namespace == namespace
24
- end
25
-
26
- def hash
27
- self.class.hash ^ name.hash ^ namespace.hash
28
- end
29
-
30
- alias eql? ==
31
-
32
- def self.parse(string)
33
- namespace = AST::Namespace.parse(string.to_s)
34
- *_, name = namespace.path
35
- new(namespace: namespace.parent, name: name)
36
- end
37
-
38
- def absolute!
39
- self.class.new(namespace: namespace.absolute!,
40
- name: name)
41
- end
42
-
43
- def in_namespace(namespace)
44
- if absolute?
45
- self
46
- else
47
- self.class.new(namespace: namespace + self.namespace, name: name)
48
- end
49
- end
50
-
51
- def to_s
52
- "#{namespace}#{name}"
53
- end
54
- end
55
-
56
- class Module < Base
57
- def self.from_node(node)
58
- case node.type
59
- when :const, :casgn
60
- namespace = namespace_from_node(node.children[0]) or return
61
- name = node.children[1]
62
- new(namespace: namespace, name: name)
63
- end
64
- end
65
-
66
- def self.namespace_from_node(node)
67
- case node&.type
68
- when nil
69
- AST::Namespace.empty
70
- when :cbase
71
- AST::Namespace.root
72
- when :const
73
- namespace_from_node(node.children[0])&.yield_self do |parent|
74
- parent.append(node.children[1])
75
- end
76
- end
77
- end
78
- end
79
-
80
- class Interface < Base
81
- end
82
-
83
- class Alias < Base
84
- end
85
- end
86
- end