steep 1.8.2 → 1.9.0.dev.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +0 -12
  3. data/Steepfile +0 -14
  4. data/lib/steep/cli.rb +47 -5
  5. data/lib/steep/diagnostic/ruby.rb +1 -58
  6. data/lib/steep/drivers/annotations.rb +1 -1
  7. data/lib/steep/drivers/check.rb +107 -1
  8. data/lib/steep/drivers/checkfile.rb +10 -8
  9. data/lib/steep/drivers/print_project.rb +83 -40
  10. data/lib/steep/drivers/utils/driver_helper.rb +5 -3
  11. data/lib/steep/drivers/watch.rb +24 -2
  12. data/lib/steep/index/signature_symbol_provider.rb +8 -8
  13. data/lib/steep/interface/builder.rb +14 -1
  14. data/lib/steep/interface/function.rb +2 -2
  15. data/lib/steep/path_helper.rb +4 -2
  16. data/lib/steep/project/dsl.rb +176 -151
  17. data/lib/steep/project/group.rb +31 -0
  18. data/lib/steep/project/target.rb +32 -6
  19. data/lib/steep/project.rb +38 -10
  20. data/lib/steep/server/delay_queue.rb +0 -3
  21. data/lib/steep/server/interaction_worker.rb +2 -11
  22. data/lib/steep/server/master.rb +95 -281
  23. data/lib/steep/server/target_group_files.rb +205 -0
  24. data/lib/steep/server/type_check_controller.rb +322 -0
  25. data/lib/steep/server/type_check_worker.rb +60 -86
  26. data/lib/steep/services/file_loader.rb +23 -0
  27. data/lib/steep/services/goto_service.rb +40 -31
  28. data/lib/steep/services/hover_provider/singleton_methods.rb +4 -4
  29. data/lib/steep/services/path_assignment.rb +23 -4
  30. data/lib/steep/services/type_check_service.rb +76 -159
  31. data/lib/steep/signature/validator.rb +4 -4
  32. data/lib/steep/subtyping/check.rb +2 -2
  33. data/lib/steep/thread_waiter.rb +24 -16
  34. data/lib/steep/type_construction.rb +5 -5
  35. data/lib/steep/type_inference/block_params.rb +1 -2
  36. data/lib/steep/type_inference/context.rb +1 -1
  37. data/lib/steep/type_inference/type_env.rb +4 -4
  38. data/lib/steep/type_inference/type_env_builder.rb +1 -1
  39. data/lib/steep/version.rb +1 -1
  40. data/lib/steep.rb +6 -4
  41. data/sample/Steepfile +6 -0
  42. data/sample/lib/conference.rb +1 -5
  43. data/steep.gemspec +7 -1
  44. metadata +8 -6
  45. data/lib/steep/drivers/validate.rb +0 -65
@@ -0,0 +1,205 @@
1
+ module Steep
2
+ module Server
3
+ class TargetGroupFiles
4
+ attr_reader :project
5
+
6
+ attr_reader :source_paths, :signature_paths
7
+
8
+ attr_reader :library_paths
9
+
10
+ def initialize(project)
11
+ @project = project
12
+ @source_paths = {}
13
+ @signature_paths = {}
14
+ @library_paths = {}
15
+ end
16
+
17
+ def add_path(path)
18
+ if target_group = project.group_for_signature_path(path)
19
+ signature_paths[path] = target_group
20
+ return true
21
+ end
22
+ if target_group = project.group_for_source_path(path)
23
+ source_paths[path] = target_group
24
+ return true
25
+ end
26
+
27
+ false
28
+ end
29
+
30
+ def add_library_path(target, *paths)
31
+ (library_paths[target.name] ||= Set[]).merge(paths)
32
+ end
33
+
34
+ def each_library_path(target, &block)
35
+ if block
36
+ library_paths.fetch(target.name).each(&block)
37
+ else
38
+ enum_for(_ = __method__, target)
39
+ end
40
+ end
41
+
42
+ def library_path?(path)
43
+ library_paths.each_value.any? { _1.include?(path) }
44
+ end
45
+
46
+ def signature_path_target(path)
47
+ case target_group = signature_paths.fetch(path, nil)
48
+ when Project::Target
49
+ target_group
50
+ when Project::Group
51
+ target_group.target
52
+ end
53
+ end
54
+
55
+ def source_path_target(path)
56
+ case target_group = source_paths.fetch(path, nil)
57
+ when Project::Target
58
+ target_group
59
+ when Project::Group
60
+ target_group.target
61
+ end
62
+ end
63
+
64
+ def target_group_for_source_path(path)
65
+ ret = source_paths.fetch(path, nil)
66
+ case ret
67
+ when Project::Group
68
+ [ret.target, ret]
69
+ when Project::Target
70
+ [ret, nil]
71
+ end
72
+ end
73
+
74
+ def target_group_for_signature_path(path)
75
+ ret = signature_paths.fetch(path, nil)
76
+ case ret
77
+ when Project::Group
78
+ [ret.target, ret]
79
+ when Project::Target
80
+ [ret, nil]
81
+ end
82
+ end
83
+
84
+ def each_group_signature_path(target, no_group = false, &block)
85
+ if block
86
+ signature_paths.each_key do |path|
87
+ t, g = target_group_for_signature_path(path)
88
+
89
+ if target.is_a?(Project::Target)
90
+ if no_group
91
+ yield path if t == target && g == nil
92
+ else
93
+ yield path if t == target
94
+ end
95
+ else
96
+ yield path if g == target
97
+ end
98
+ end
99
+ else
100
+ enum_for(_ = __method__, target, no_group)
101
+ end
102
+ end
103
+
104
+ def each_target_signature_path(target, group, &block)
105
+ raise unless group.target == target if group
106
+
107
+ if block
108
+ signature_paths.each_key do |path|
109
+ t, g = target_group_for_signature_path(path)
110
+
111
+ next unless target == t
112
+ next if group && group == g
113
+
114
+ yield path
115
+ end
116
+ else
117
+ enum_for(_ = __method__, target, group)
118
+ end
119
+ end
120
+
121
+ def each_project_signature_path(target, &block)
122
+ if block
123
+ signature_paths.each do |path, target_group|
124
+ t =
125
+ case target_group
126
+ when Project::Target
127
+ target_group
128
+ when Project::Group
129
+ target_group.target
130
+ end
131
+
132
+ if target
133
+ next if t.unreferenced
134
+ next if t == target
135
+ end
136
+
137
+ yield path
138
+ end
139
+ else
140
+ enum_for(_ = __method__, target)
141
+ end
142
+ end
143
+
144
+ def each_group_source_path(target, no_group = false, &block)
145
+ if block
146
+ source_paths.each_key do |path|
147
+ t, g = target_group_for_source_path(path)
148
+
149
+ if target.is_a?(Project::Target)
150
+ if no_group
151
+ yield path if t == target && g == nil
152
+ else
153
+ yield path if t == target
154
+ end
155
+ else
156
+ yield path if g == target
157
+ end
158
+ end
159
+ else
160
+ enum_for(_ = __method__, target, no_group)
161
+ end
162
+ end
163
+
164
+ def each_target_source_path(target, group, &block)
165
+ raise unless group.target == target if group
166
+
167
+ if block
168
+ source_paths.each_key do |path|
169
+ t, g = target_group_for_source_path(path)
170
+
171
+ next unless target == t
172
+ next if group && group == g
173
+
174
+ yield path
175
+ end
176
+ else
177
+ enum_for(_ = __method__, target, group)
178
+ end
179
+ end
180
+
181
+ def each_project_source_path(target, &block)
182
+ if block
183
+ source_paths.each do |path, target_group|
184
+ t =
185
+ case target_group
186
+ when Project::Target
187
+ target_group
188
+ when Project::Group
189
+ target_group.target
190
+ end
191
+
192
+ if target
193
+ next if t.unreferenced
194
+ next if t == target
195
+ end
196
+
197
+ yield path
198
+ end
199
+ else
200
+ enum_for(_ = __method__, target)
201
+ end
202
+ end
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,322 @@
1
+ module Steep
2
+ module Server
3
+ class TypeCheckController
4
+ class Request
5
+ attr_reader :guid
6
+ attr_reader :library_paths
7
+ attr_reader :signature_paths
8
+ attr_reader :code_paths
9
+ attr_reader :priority_paths
10
+ attr_reader :checked_paths
11
+ attr_reader :work_done_progress
12
+ attr_reader :started_at
13
+ attr_accessor :needs_response
14
+ attr_reader :report_progress
15
+
16
+ def initialize(guid:, progress:)
17
+ @guid = guid
18
+ @library_paths = Set[]
19
+ @signature_paths = Set[]
20
+ @code_paths = Set[]
21
+ @priority_paths = Set[]
22
+ @checked_paths = Set[]
23
+ @work_done_progress = progress
24
+ @started_at = Time.now
25
+ @needs_response = false
26
+ @report_progress = false
27
+ end
28
+
29
+ def report_progress!(value = true)
30
+ @report_progress = value
31
+ self
32
+ end
33
+
34
+ def uri(path)
35
+ Steep::PathHelper.to_uri(path)
36
+ end
37
+
38
+ def as_json(assignment:)
39
+ {
40
+ guid: guid,
41
+ library_uris: assigned_uris(assignment, library_paths),
42
+ signature_uris: assigned_uris(assignment, signature_paths),
43
+ code_uris: assigned_uris(assignment, code_paths),
44
+ priority_uris: priority_paths.map {|path| uri(path).to_s }
45
+ }
46
+ end
47
+
48
+ def assigned_uris(assignment, paths)
49
+ paths.filter_map do |target_path|
50
+ if assignment =~ target_path
51
+ [target_path[0].to_s, uri(target_path[1]).to_s]
52
+ end
53
+ end
54
+ end
55
+
56
+ def total
57
+ library_paths.size + signature_paths.size + code_paths.size
58
+ end
59
+
60
+ def empty?
61
+ total == 0
62
+ end
63
+
64
+ def percentage
65
+ checked_paths.size * 100 / total
66
+ end
67
+
68
+ def each_path(&block)
69
+ if block
70
+ each_target_path do |_target, path|
71
+ yield path
72
+ end
73
+ else
74
+ enum_for :each_path
75
+ end
76
+ end
77
+
78
+ def each_target_path(&block)
79
+ if block
80
+ library_paths.each(&block)
81
+ signature_paths.each(&block)
82
+ code_paths.each(&block)
83
+ else
84
+ enum_for :each_target_path
85
+ end
86
+ end
87
+
88
+ def checking_path?(target_path)
89
+ [library_paths, signature_paths, code_paths].any? do |paths|
90
+ paths.include?(target_path)
91
+ end
92
+ end
93
+
94
+ def checked(path, target)
95
+ target_path = [target.name, path] #: target_and_path
96
+
97
+ raise unless checking_path?(target_path)
98
+ checked_paths << target_path
99
+ end
100
+
101
+ def finished?
102
+ total <= checked_paths.size
103
+ end
104
+
105
+ def each_unchecked_path(&block)
106
+ if block
107
+ each_unchecked_target_path do |_target, path|
108
+ yield path
109
+ end
110
+ else
111
+ enum_for :each_unchecked_path
112
+ end
113
+ end
114
+
115
+ def each_unchecked_target_path(&block)
116
+ if block
117
+ each_target_path do |target_path|
118
+ unless checked_paths.include?(target_path)
119
+ yield target_path
120
+ end
121
+ end
122
+ else
123
+ enum_for :each_unchecked_target_path
124
+ end
125
+ end
126
+
127
+ def each_unchecked_code_target_path(&block)
128
+ if block
129
+ code_paths.each do |target_path|
130
+ unless checked_paths.include?(target_path)
131
+ yield target_path
132
+ end
133
+ end
134
+ else
135
+ enum_for :each_unchecked_code_target_path
136
+ end
137
+ end
138
+
139
+ def each_unchecked_library_target_path(&block)
140
+ if block
141
+ library_paths.each do |target_path|
142
+ unless checked_paths.include?(target_path)
143
+ yield target_path
144
+ end
145
+ end
146
+ else
147
+ enum_for :each_unchecked_library_target_path
148
+ end
149
+ end
150
+
151
+ def each_unchecked_signature_target_path(&block)
152
+ if block
153
+ signature_paths.each do |target_path|
154
+ unless checked_paths.include?(target_path)
155
+ yield target_path
156
+ end
157
+ end
158
+ else
159
+ enum_for :each_unchecked_signature_target_path
160
+ end
161
+ end
162
+
163
+ def merge!(request)
164
+ library_paths.merge(request.each_unchecked_library_target_path)
165
+ signature_paths.merge(request.each_unchecked_signature_target_path)
166
+ code_paths.merge(request.each_unchecked_code_target_path)
167
+
168
+ self
169
+ end
170
+ end
171
+
172
+ attr_reader :project
173
+ attr_reader :priority_paths
174
+ attr_reader :changed_paths
175
+ attr_reader :files
176
+
177
+ def initialize(project:)
178
+ @project = project
179
+ @priority_paths = Set[]
180
+ @changed_paths = Set[]
181
+ @files = TargetGroupFiles.new(project)
182
+ end
183
+
184
+ def load(command_line_args:)
185
+ loader = Services::FileLoader.new(base_dir: project.base_dir)
186
+
187
+ project.targets.each do |target|
188
+ signature_service = Services::SignatureService.load_from(target.new_env_loader())
189
+ files.add_library_path(target, *signature_service.env_rbs_paths.to_a)
190
+ end
191
+
192
+ files = {} #: Hash[String, String]
193
+
194
+ project.targets.each do |target|
195
+ loader.each_path_in_target(target, command_line_args) do |path|
196
+ path = project.absolute_path(path)
197
+ self.files.add_path(path)
198
+ files[project.relative_path(path).to_s] = path.read
199
+ if files.size > 1000
200
+ yield files.dup
201
+ files.clear
202
+ end
203
+ end
204
+ end
205
+
206
+ changed_paths.merge(self.files.each_project_signature_path(nil))
207
+ changed_paths.merge(self.files.each_project_source_path(nil))
208
+
209
+ yield files.dup unless files.empty?
210
+ end
211
+
212
+ def push_changes(path)
213
+ return if files.library_path?(path)
214
+
215
+ if files.add_path(path)
216
+ changed_paths << path
217
+ end
218
+ end
219
+
220
+ def active_target?(target_group)
221
+ priority_paths.any? do |path|
222
+ if open_target = files.signature_paths.fetch(path, nil) || files.source_paths.fetch(path, nil)
223
+ open_target == target_group
224
+ end
225
+ end
226
+ end
227
+
228
+ def push_changes_for_target(target_group)
229
+ files.each_group_signature_path(target_group) do |path|
230
+ push_changes path
231
+ end
232
+
233
+ files.each_group_source_path(target_group) do |path|
234
+ push_changes path
235
+ end
236
+ end
237
+
238
+ def update_priority(open: nil, close: nil)
239
+ path = open || close or raise
240
+
241
+ return if files.library_path?(path)
242
+ files.add_path(path)
243
+
244
+ case
245
+ when open
246
+ target_group = files.signature_paths.fetch(path, nil) || files.source_paths.fetch(path, nil) or return
247
+
248
+ unless active_target?(target_group)
249
+ push_changes_for_target(target_group)
250
+ end
251
+ priority_paths << path
252
+ when close
253
+ priority_paths.delete path
254
+ end
255
+ end
256
+
257
+ def make_request(guid: SecureRandom.uuid, include_unchanged: false, progress:)
258
+ TypeCheckController::Request.new(guid: guid, progress: progress).tap do |request|
259
+ if include_unchanged
260
+ files.signature_paths.each do |path, target_group|
261
+ target_group = target_group.target if target_group.is_a?(Project::Group)
262
+ request.signature_paths << [target_group.name, path]
263
+ end
264
+ files.source_paths.each do |path, target_group|
265
+ target_group = target_group.target if target_group.is_a?(Project::Group)
266
+ request.code_paths << [target_group.name, path]
267
+ end
268
+ else
269
+ changed_paths.each do |path|
270
+ if target_group = files.signature_paths.fetch(path, nil)
271
+ case target_group
272
+ when Project::Group
273
+ target = target_group.target
274
+
275
+ files.each_group_signature_path(target_group) do |path|
276
+ request.signature_paths << [target.name, path]
277
+ end
278
+
279
+ files.each_group_source_path(target_group) do |path|
280
+ request.code_paths << [target.name, path]
281
+ end
282
+ when Project::Target
283
+ files.each_target_signature_path(target_group, nil) do |path|
284
+ request.signature_paths << [target_group.name, path]
285
+ end
286
+
287
+ files.each_target_source_path(target_group, nil) do |path|
288
+ request.code_paths << [target_group.name, path]
289
+ end
290
+ end
291
+ end
292
+
293
+ if target = files.source_path_target(path)
294
+ request.code_paths << [target.name, path]
295
+ end
296
+ end
297
+
298
+ unless request.signature_paths.empty?
299
+ non_unref_targets = project.targets.reject { _1.unreferenced }.map(&:name).to_set
300
+ if request.signature_paths.any? {|target_name, _| non_unref_targets.include?(target_name) }
301
+ priority_paths.each do |path|
302
+ if target = files.signature_path_target(path)
303
+ request.signature_paths << [target.name, path]
304
+ request.priority_paths << path
305
+ end
306
+ if target = files.source_path_target(path)
307
+ request.code_paths << [target.name, path]
308
+ request.priority_paths << path
309
+ end
310
+ end
311
+ end
312
+ end
313
+ end
314
+
315
+ changed_paths.clear()
316
+
317
+ return nil if request.empty?
318
+ end
319
+ end
320
+ end
321
+ end
322
+ end