steep 0.12.0 → 0.13.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +8 -0
- data/lib/steep.rb +2 -0
- data/lib/steep/drivers/langserver.rb +61 -10
- data/lib/steep/interface/substitution.rb +13 -1
- data/lib/steep/project.rb +1 -0
- data/lib/steep/project/file.rb +18 -13
- data/lib/steep/project/hover_content.rb +128 -0
- data/lib/steep/source.rb +5 -7
- data/lib/steep/type_construction.rb +161 -216
- data/lib/steep/type_inference/context.rb +107 -0
- data/lib/steep/typing.rb +25 -15
- data/lib/steep/version.rb +1 -1
- metadata +4 -2
@@ -0,0 +1,107 @@
|
|
1
|
+
module Steep
|
2
|
+
module TypeInference
|
3
|
+
class Context
|
4
|
+
class MethodContext
|
5
|
+
attr_reader :name
|
6
|
+
attr_reader :method
|
7
|
+
attr_reader :method_type
|
8
|
+
attr_reader :return_type
|
9
|
+
attr_reader :constructor
|
10
|
+
attr_reader :super_method
|
11
|
+
|
12
|
+
def initialize(name:, method:, method_type:, return_type:, constructor:, super_method:)
|
13
|
+
@name = name
|
14
|
+
@method = method
|
15
|
+
@return_type = return_type
|
16
|
+
@method_type = method_type
|
17
|
+
@constructor = constructor
|
18
|
+
@super_method = super_method
|
19
|
+
end
|
20
|
+
|
21
|
+
def block_type
|
22
|
+
method_type&.block
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class BlockContext
|
27
|
+
attr_reader :body_type
|
28
|
+
|
29
|
+
def initialize(body_type:)
|
30
|
+
@body_type = body_type
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class BreakContext
|
35
|
+
attr_reader :break_type
|
36
|
+
attr_reader :next_type
|
37
|
+
|
38
|
+
def initialize(break_type:, next_type:)
|
39
|
+
@break_type = break_type
|
40
|
+
@next_type = next_type
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class ModuleContext
|
45
|
+
attr_reader :instance_type
|
46
|
+
attr_reader :module_type
|
47
|
+
attr_reader :defined_instance_methods
|
48
|
+
attr_reader :defined_module_methods
|
49
|
+
attr_reader :const_env
|
50
|
+
attr_reader :implement_name
|
51
|
+
attr_reader :current_namespace
|
52
|
+
attr_reader :class_name
|
53
|
+
attr_reader :instance_definition
|
54
|
+
attr_reader :module_definition
|
55
|
+
|
56
|
+
def initialize(instance_type:, module_type:, implement_name:, current_namespace:, const_env:, class_name:, instance_definition: nil, module_definition: nil)
|
57
|
+
@instance_type = instance_type
|
58
|
+
@module_type = module_type
|
59
|
+
@defined_instance_methods = Set.new
|
60
|
+
@defined_module_methods = Set.new
|
61
|
+
@implement_name = implement_name
|
62
|
+
@current_namespace = current_namespace
|
63
|
+
@const_env = const_env
|
64
|
+
@class_name = class_name
|
65
|
+
@instance_definition = instance_definition
|
66
|
+
@module_definition = module_definition
|
67
|
+
end
|
68
|
+
|
69
|
+
def const_context
|
70
|
+
const_env.context
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
attr_reader :method_context
|
75
|
+
attr_reader :block_context
|
76
|
+
attr_reader :break_context
|
77
|
+
attr_reader :module_context
|
78
|
+
attr_reader :self_type
|
79
|
+
attr_reader :type_env
|
80
|
+
|
81
|
+
def initialize(method_context:, block_context:, break_context:, module_context:, self_type:, type_env:)
|
82
|
+
@method_context = method_context
|
83
|
+
@block_context = block_context
|
84
|
+
@break_context = break_context
|
85
|
+
@module_context = module_context
|
86
|
+
@self_type = self_type
|
87
|
+
@type_env = type_env
|
88
|
+
end
|
89
|
+
|
90
|
+
def with(method_context: self.method_context,
|
91
|
+
block_context: self.block_context,
|
92
|
+
break_context: self.break_context,
|
93
|
+
module_context: self.module_context,
|
94
|
+
self_type: self.self_type,
|
95
|
+
type_env: self.type_env)
|
96
|
+
self.class.new(
|
97
|
+
method_context: method_context,
|
98
|
+
block_context: block_context,
|
99
|
+
break_context: break_context,
|
100
|
+
module_context: module_context,
|
101
|
+
self_type: self_type,
|
102
|
+
type_env: type_env
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/lib/steep/typing.rb
CHANGED
@@ -2,12 +2,11 @@ module Steep
|
|
2
2
|
class Typing
|
3
3
|
attr_reader :errors
|
4
4
|
attr_reader :typing
|
5
|
-
attr_reader :nodes
|
6
|
-
attr_reader :var_typing
|
7
5
|
attr_reader :parent
|
8
6
|
attr_reader :parent_last_update
|
9
7
|
attr_reader :last_update
|
10
8
|
attr_reader :should_update
|
9
|
+
attr_reader :contexts
|
11
10
|
|
12
11
|
def initialize(parent: nil, parent_last_update: parent&.last_update)
|
13
12
|
@parent = parent
|
@@ -16,18 +15,17 @@ module Steep
|
|
16
15
|
@should_update = false
|
17
16
|
|
18
17
|
@errors = []
|
19
|
-
@
|
20
|
-
@
|
21
|
-
@typing = {}
|
18
|
+
@typing = {}.compare_by_identity
|
19
|
+
@contexts = {}.compare_by_identity
|
22
20
|
end
|
23
21
|
|
24
22
|
def add_error(error)
|
25
23
|
errors << error
|
26
24
|
end
|
27
25
|
|
28
|
-
def add_typing(node, type)
|
29
|
-
typing[node
|
30
|
-
|
26
|
+
def add_typing(node, type, context)
|
27
|
+
typing[node] = type
|
28
|
+
contexts[node] = context
|
31
29
|
|
32
30
|
if should_update
|
33
31
|
@last_update += 1
|
@@ -38,11 +36,11 @@ module Steep
|
|
38
36
|
end
|
39
37
|
|
40
38
|
def has_type?(node)
|
41
|
-
typing.key?(node
|
39
|
+
typing.key?(node)
|
42
40
|
end
|
43
41
|
|
44
42
|
def type_of(node:)
|
45
|
-
type = typing[node
|
43
|
+
type = typing[node]
|
46
44
|
|
47
45
|
if type
|
48
46
|
type
|
@@ -55,6 +53,20 @@ module Steep
|
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
56
|
+
def context_of(node:)
|
57
|
+
ctx = contexts[node]
|
58
|
+
|
59
|
+
if ctx
|
60
|
+
ctx
|
61
|
+
else
|
62
|
+
if parent
|
63
|
+
parent.context_of(node: node)
|
64
|
+
else
|
65
|
+
raise "Unknown node for context: #{node.inspect}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
58
70
|
def dump(io)
|
59
71
|
io.puts "Typing: "
|
60
72
|
nodes.each_value do |node|
|
@@ -86,10 +98,8 @@ module Steep
|
|
86
98
|
end
|
87
99
|
end
|
88
100
|
|
89
|
-
def each_typing
|
90
|
-
|
91
|
-
yield node, typing[id]
|
92
|
-
end
|
101
|
+
def each_typing(&block)
|
102
|
+
typing.each(&block)
|
93
103
|
end
|
94
104
|
|
95
105
|
def save!
|
@@ -97,7 +107,7 @@ module Steep
|
|
97
107
|
raise "Parent modified since new_child" unless parent.last_update == parent_last_update
|
98
108
|
|
99
109
|
each_typing do |node, type|
|
100
|
-
parent.add_typing(node, type)
|
110
|
+
parent.add_typing(node, type, contexts[node])
|
101
111
|
end
|
102
112
|
|
103
113
|
errors.each do |error|
|
data/lib/steep/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: steep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Soutaro Matsumoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -275,6 +275,7 @@ files:
|
|
275
275
|
- lib/steep/project/dsl.rb
|
276
276
|
- lib/steep/project/file.rb
|
277
277
|
- lib/steep/project/file_loader.rb
|
278
|
+
- lib/steep/project/hover_content.rb
|
278
279
|
- lib/steep/project/options.rb
|
279
280
|
- lib/steep/project/target.rb
|
280
281
|
- lib/steep/signature/errors.rb
|
@@ -291,6 +292,7 @@ files:
|
|
291
292
|
- lib/steep/type_construction.rb
|
292
293
|
- lib/steep/type_inference/block_params.rb
|
293
294
|
- lib/steep/type_inference/constant_env.rb
|
295
|
+
- lib/steep/type_inference/context.rb
|
294
296
|
- lib/steep/type_inference/send_args.rb
|
295
297
|
- lib/steep/type_inference/type_env.rb
|
296
298
|
- lib/steep/typing.rb
|