solargraph 0.58.1 → 0.59.0.dev.1
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/.envrc +3 -0
- data/.github/workflows/linting.yml +4 -5
- data/.github/workflows/plugins.yml +40 -36
- data/.github/workflows/rspec.yml +45 -13
- data/.github/workflows/typecheck.yml +2 -2
- data/.rubocop_todo.yml +27 -49
- data/README.md +3 -3
- data/Rakefile +1 -0
- data/lib/solargraph/api_map/cache.rb +110 -110
- data/lib/solargraph/api_map/constants.rb +289 -279
- data/lib/solargraph/api_map/index.rb +204 -193
- data/lib/solargraph/api_map/source_to_yard.rb +109 -97
- data/lib/solargraph/api_map/store.rb +387 -384
- data/lib/solargraph/api_map.rb +1000 -945
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +242 -228
- data/lib/solargraph/complex_type/unique_type.rb +632 -482
- data/lib/solargraph/complex_type.rb +549 -444
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +93 -91
- data/lib/solargraph/convention/data_definition.rb +108 -105
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +62 -61
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +103 -102
- data/lib/solargraph/convention/struct_definition.rb +168 -164
- data/lib/solargraph/diagnostics/require_not_found.rb +54 -53
- data/lib/solargraph/diagnostics/rubocop.rb +119 -118
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +70 -68
- data/lib/solargraph/diagnostics/type_check.rb +56 -55
- data/lib/solargraph/doc_map.rb +200 -439
- data/lib/solargraph/equality.rb +34 -34
- data/lib/solargraph/gem_pins.rb +97 -98
- data/lib/solargraph/language_server/host/dispatch.rb +131 -130
- data/lib/solargraph/language_server/host/message_worker.rb +113 -112
- data/lib/solargraph/language_server/host/sources.rb +100 -99
- data/lib/solargraph/language_server/host.rb +883 -878
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +109 -114
- data/lib/solargraph/language_server/message/extended/document.rb +24 -23
- data/lib/solargraph/language_server/message/text_document/completion.rb +58 -56
- data/lib/solargraph/language_server/message/text_document/definition.rb +42 -40
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +28 -26
- data/lib/solargraph/language_server/message/text_document/formatting.rb +150 -148
- data/lib/solargraph/language_server/message/text_document/hover.rb +60 -58
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +25 -24
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +27 -25
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +25 -23
- data/lib/solargraph/library.rb +729 -683
- data/lib/solargraph/location.rb +87 -82
- data/lib/solargraph/logging.rb +57 -37
- data/lib/solargraph/parser/comment_ripper.rb +76 -69
- data/lib/solargraph/parser/flow_sensitive_typing.rb +483 -255
- data/lib/solargraph/parser/node_processor/base.rb +122 -92
- data/lib/solargraph/parser/node_processor.rb +63 -62
- data/lib/solargraph/parser/parser_gem/class_methods.rb +167 -149
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +191 -166
- data/lib/solargraph/parser/parser_gem/node_methods.rb +506 -486
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -22
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +61 -59
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +24 -15
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +46 -46
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +60 -53
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +53 -23
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +41 -40
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +30 -29
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +61 -59
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -98
- data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -17
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +39 -38
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +53 -52
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +296 -291
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +33 -29
- data/lib/solargraph/parser/parser_gem/node_processors.rb +74 -70
- data/lib/solargraph/parser/region.rb +75 -69
- data/lib/solargraph/parser/snippet.rb +17 -17
- data/lib/solargraph/pin/base.rb +761 -729
- data/lib/solargraph/pin/base_variable.rb +418 -126
- data/lib/solargraph/pin/block.rb +126 -104
- data/lib/solargraph/pin/breakable.rb +13 -9
- data/lib/solargraph/pin/callable.rb +278 -231
- data/lib/solargraph/pin/closure.rb +68 -72
- data/lib/solargraph/pin/common.rb +94 -79
- data/lib/solargraph/pin/compound_statement.rb +55 -0
- data/lib/solargraph/pin/conversions.rb +124 -123
- data/lib/solargraph/pin/delegated_method.rb +131 -120
- data/lib/solargraph/pin/documenting.rb +115 -114
- data/lib/solargraph/pin/instance_variable.rb +38 -34
- data/lib/solargraph/pin/keyword.rb +16 -20
- data/lib/solargraph/pin/local_variable.rb +31 -75
- data/lib/solargraph/pin/method.rb +720 -672
- data/lib/solargraph/pin/method_alias.rb +42 -34
- data/lib/solargraph/pin/namespace.rb +121 -115
- data/lib/solargraph/pin/parameter.rb +338 -275
- data/lib/solargraph/pin/proxy_type.rb +40 -39
- data/lib/solargraph/pin/reference/override.rb +47 -47
- data/lib/solargraph/pin/reference/superclass.rb +17 -15
- data/lib/solargraph/pin/reference.rb +41 -39
- data/lib/solargraph/pin/search.rb +62 -61
- data/lib/solargraph/pin/signature.rb +69 -61
- data/lib/solargraph/pin/symbol.rb +53 -53
- data/lib/solargraph/pin/until.rb +18 -18
- data/lib/solargraph/pin/while.rb +18 -18
- data/lib/solargraph/pin.rb +46 -44
- data/lib/solargraph/pin_cache.rb +665 -245
- data/lib/solargraph/position.rb +118 -119
- data/lib/solargraph/range.rb +112 -112
- data/lib/solargraph/rbs_map/conversions.rb +846 -823
- data/lib/solargraph/rbs_map/core_map.rb +65 -58
- data/lib/solargraph/rbs_map/stdlib_map.rb +72 -43
- data/lib/solargraph/rbs_map.rb +217 -163
- data/lib/solargraph/shell.rb +397 -352
- data/lib/solargraph/source/chain/call.rb +372 -337
- data/lib/solargraph/source/chain/constant.rb +28 -26
- data/lib/solargraph/source/chain/hash.rb +35 -34
- data/lib/solargraph/source/chain/if.rb +29 -28
- data/lib/solargraph/source/chain/instance_variable.rb +34 -13
- data/lib/solargraph/source/chain/literal.rb +53 -48
- data/lib/solargraph/source/chain/or.rb +31 -23
- data/lib/solargraph/source/chain.rb +294 -291
- data/lib/solargraph/source/change.rb +89 -82
- data/lib/solargraph/source/cursor.rb +172 -166
- data/lib/solargraph/source/source_chainer.rb +204 -194
- data/lib/solargraph/source/updater.rb +59 -55
- data/lib/solargraph/source.rb +524 -498
- data/lib/solargraph/source_map/clip.rb +237 -226
- data/lib/solargraph/source_map/data.rb +37 -34
- data/lib/solargraph/source_map/mapper.rb +282 -259
- data/lib/solargraph/source_map.rb +220 -212
- data/lib/solargraph/type_checker/problem.rb +34 -32
- data/lib/solargraph/type_checker/rules.rb +157 -84
- data/lib/solargraph/type_checker.rb +895 -814
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +257 -255
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +98 -97
- data/lib/solargraph/workspace.rb +362 -220
- data/lib/solargraph/yard_map/helpers.rb +45 -44
- data/lib/solargraph/yard_map/mapper/to_method.rb +134 -130
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +32 -31
- data/lib/solargraph/yard_map/mapper.rb +84 -79
- data/lib/solargraph/yardoc.rb +97 -87
- data/lib/solargraph.rb +126 -105
- data/rbs/fills/rubygems/0/dependency.rbs +193 -0
- data/rbs/fills/tuple/tuple.rbs +28 -0
- data/rbs/shims/ast/0/node.rbs +5 -0
- data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
- data/rbs_collection.yaml +1 -1
- data/solargraph.gemspec +2 -1
- metadata +22 -17
- data/lib/solargraph/type_checker/checks.rb +0 -124
- data/lib/solargraph/type_checker/param_def.rb +0 -37
- data/lib/solargraph/yard_map/to_method.rb +0 -89
- data/sig/shims/ast/0/node.rbs +0 -5
- /data/{sig → rbs}/shims/ast/2.4/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/ast/2.4/ast.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/builders/default.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/parser.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/polyfill.rbs +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/thor.rbs +0 -0
data/lib/solargraph/shell.rb
CHANGED
|
@@ -1,352 +1,397 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'benchmark'
|
|
4
|
-
require 'thor'
|
|
5
|
-
require 'yard'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
option :
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
port =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Backport.prepare_tcp_server
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
Backport.prepare_stdio_server adapter
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
# @
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
map 'clear-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
# @
|
|
105
|
-
# @param
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
desc 'uncache GEM [...GEM]', "Delete specific cached gem documentation"
|
|
113
|
-
long_desc %(
|
|
114
|
-
Specify one or more gem names to clear. 'core' or 'stdlib' may
|
|
115
|
-
also be specified to clear cached system documentation.
|
|
116
|
-
Documentation will be regenerated as needed.
|
|
117
|
-
)
|
|
118
|
-
# @param gems [Array<String>]
|
|
119
|
-
# @return [void]
|
|
120
|
-
def uncache *gems
|
|
121
|
-
raise ArgumentError, 'No gems specified.' if gems.empty?
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
end
|
|
198
|
-
# "
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
checking
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
puts "#{
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
#
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'benchmark'
|
|
4
|
+
require 'thor'
|
|
5
|
+
require 'yard'
|
|
6
|
+
require 'yaml'
|
|
7
|
+
|
|
8
|
+
module Solargraph
|
|
9
|
+
class Shell < Thor
|
|
10
|
+
include Solargraph::ServerMethods
|
|
11
|
+
|
|
12
|
+
# Tell Thor to ensure the process exits with status 1 if any error happens.
|
|
13
|
+
def self.exit_on_failure?
|
|
14
|
+
true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
map %w[--version -v] => :version
|
|
18
|
+
|
|
19
|
+
desc "--version, -v", "Print the version"
|
|
20
|
+
# @return [void]
|
|
21
|
+
def version
|
|
22
|
+
puts Solargraph::VERSION
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc 'socket', 'Run a Solargraph socket server'
|
|
26
|
+
option :host, type: :string, aliases: :h, desc: 'The server host', default: '127.0.0.1'
|
|
27
|
+
option :port, type: :numeric, aliases: :p, desc: 'The server port', default: 7658
|
|
28
|
+
# @return [void]
|
|
29
|
+
def socket
|
|
30
|
+
require 'backport'
|
|
31
|
+
port = options[:port]
|
|
32
|
+
port = available_port if port.zero?
|
|
33
|
+
Backport.run do
|
|
34
|
+
Signal.trap("INT") do
|
|
35
|
+
Backport.stop
|
|
36
|
+
end
|
|
37
|
+
Signal.trap("TERM") do
|
|
38
|
+
Backport.stop
|
|
39
|
+
end
|
|
40
|
+
# @sg-ignore Wrong argument type for Backport.prepare_tcp_server: adapter expected Backport::Adapter, received Module<Solargraph::LanguageServer::Transport::Adapter>
|
|
41
|
+
Backport.prepare_tcp_server host: options[:host], port: port, adapter: Solargraph::LanguageServer::Transport::Adapter
|
|
42
|
+
STDERR.puts "Solargraph is listening PORT=#{port} PID=#{Process.pid}"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
desc 'stdio', 'Run a Solargraph stdio server'
|
|
47
|
+
# @return [void]
|
|
48
|
+
def stdio
|
|
49
|
+
require 'backport'
|
|
50
|
+
Backport.run do
|
|
51
|
+
Signal.trap("INT") do
|
|
52
|
+
Backport.stop
|
|
53
|
+
end
|
|
54
|
+
Signal.trap("TERM") do
|
|
55
|
+
Backport.stop
|
|
56
|
+
end
|
|
57
|
+
# @sg-ignore Wrong argument type for Backport.prepare_stdio_server: adapter expected Backport::Adapter, received Module<Solargraph::LanguageServer::Transport::Adapter>
|
|
58
|
+
Backport.prepare_stdio_server adapter: Solargraph::LanguageServer::Transport::Adapter
|
|
59
|
+
STDERR.puts "Solargraph is listening on stdio PID=#{Process.pid}"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
desc 'config [DIRECTORY]', 'Create or overwrite a default configuration file'
|
|
64
|
+
option :extensions, type: :boolean, aliases: :e, desc: 'Add installed extensions', default: true
|
|
65
|
+
# @param directory [String]
|
|
66
|
+
# @return [void]
|
|
67
|
+
def config(directory = '.')
|
|
68
|
+
matches = []
|
|
69
|
+
if options[:extensions]
|
|
70
|
+
Gem::Specification.each do |g|
|
|
71
|
+
if g.name.match(/^solargraph\-[A-Za-z0-9_\-]*?\-ext/)
|
|
72
|
+
require g.name
|
|
73
|
+
matches.push g.name
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
conf = Solargraph::Workspace::Config.new.raw_data
|
|
78
|
+
unless matches.empty?
|
|
79
|
+
matches.each do |m|
|
|
80
|
+
conf['extensions'].push m
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
# @param file [File]
|
|
84
|
+
File.open(File.join(directory, '.solargraph.yml'), 'w') do |file|
|
|
85
|
+
file.puts conf.to_yaml
|
|
86
|
+
end
|
|
87
|
+
STDOUT.puts "Configuration file initialized."
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
desc 'clear', 'Delete all cached documentation'
|
|
91
|
+
long_desc %(
|
|
92
|
+
This command will delete all core and gem documentation from the cache.
|
|
93
|
+
)
|
|
94
|
+
# @return [void]
|
|
95
|
+
def clear
|
|
96
|
+
puts "Deleting all cached documentation (gems, core and stdlib)"
|
|
97
|
+
Solargraph::PinCache.clear
|
|
98
|
+
end
|
|
99
|
+
map 'clear-cache' => :clear
|
|
100
|
+
map 'clear-cores' => :clear
|
|
101
|
+
|
|
102
|
+
desc 'cache', 'Cache a gem', hide: true
|
|
103
|
+
option :rebuild, type: :boolean, desc: 'Rebuild existing documentation', default: false
|
|
104
|
+
# @return [void]
|
|
105
|
+
# @param gem [String]
|
|
106
|
+
# @param version [String, nil]
|
|
107
|
+
def cache gem, version = nil
|
|
108
|
+
gems(gem + (version ? "=#{version}" : ''))
|
|
109
|
+
# '
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
desc 'uncache GEM [...GEM]', "Delete specific cached gem documentation"
|
|
113
|
+
long_desc %(
|
|
114
|
+
Specify one or more gem names to clear. 'core' or 'stdlib' may
|
|
115
|
+
also be specified to clear cached system documentation.
|
|
116
|
+
Documentation will be regenerated as needed.
|
|
117
|
+
)
|
|
118
|
+
# @param gems [Array<String>]
|
|
119
|
+
# @return [void]
|
|
120
|
+
def uncache *gems
|
|
121
|
+
raise ArgumentError, 'No gems specified.' if gems.empty?
|
|
122
|
+
workspace = Solargraph::Workspace.new(Dir.pwd)
|
|
123
|
+
|
|
124
|
+
gems.each do |gem|
|
|
125
|
+
if gem == 'core'
|
|
126
|
+
PinCache.uncache_core(out: $stdout)
|
|
127
|
+
next
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
if gem == 'stdlib'
|
|
131
|
+
PinCache.uncache_stdlib(out: $stdout)
|
|
132
|
+
next
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
spec = workspace.find_gem(gem)
|
|
136
|
+
raise Thor::InvocationError, "Gem '#{gem}' not found" if spec.nil?
|
|
137
|
+
|
|
138
|
+
# @sg-ignore flow sensitive typing needs to handle 'raise if'
|
|
139
|
+
workspace.uncache_gem(spec, out: $stdout)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
desc 'gems [GEM[=VERSION]...] [STDLIB...] [core]', 'Cache documentation for
|
|
144
|
+
installed libraries'
|
|
145
|
+
long_desc %( This command will cache the
|
|
146
|
+
generated type documentation for the specified libraries. While
|
|
147
|
+
Solargraph will generate this on the fly when needed, it takes
|
|
148
|
+
time. This command will generate it in advance, which can be
|
|
149
|
+
useful for CI scenarios.
|
|
150
|
+
|
|
151
|
+
With no arguments, it will cache all libraries in the current
|
|
152
|
+
workspace. If a gem or standard library name is specified, it
|
|
153
|
+
will cache that library's type documentation.
|
|
154
|
+
|
|
155
|
+
An equals sign after a gem will allow a specific gem version
|
|
156
|
+
to be cached.
|
|
157
|
+
|
|
158
|
+
The 'core' argument can be used to cache the type
|
|
159
|
+
documentation for the core Ruby libraries.
|
|
160
|
+
|
|
161
|
+
If the library is already cached, it will be rebuilt if the
|
|
162
|
+
--rebuild option is set.
|
|
163
|
+
|
|
164
|
+
Cached documentation is stored in #{PinCache.base_dir}, which
|
|
165
|
+
can be stored between CI runs.
|
|
166
|
+
)
|
|
167
|
+
option :rebuild, type: :boolean, desc: 'Rebuild existing documentation', default: false
|
|
168
|
+
# @param names [Array<String>]
|
|
169
|
+
# @return [void]
|
|
170
|
+
def gems *names
|
|
171
|
+
# print time with ms
|
|
172
|
+
workspace = Solargraph::Workspace.new('.')
|
|
173
|
+
|
|
174
|
+
if names.empty?
|
|
175
|
+
workspace.cache_all_for_workspace!($stdout, rebuild: options[:rebuild])
|
|
176
|
+
else
|
|
177
|
+
$stderr.puts("Caching these gems: #{names}")
|
|
178
|
+
names.each do |name|
|
|
179
|
+
if name == 'core'
|
|
180
|
+
PinCache.cache_core(out: $stdout) if !PinCache.core? || options[:rebuild]
|
|
181
|
+
next
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
gemspec = workspace.find_gem(*name.split('='))
|
|
185
|
+
if gemspec.nil?
|
|
186
|
+
warn "Gem '#{name}' not found"
|
|
187
|
+
else
|
|
188
|
+
workspace.cache_gem(gemspec, rebuild: options[:rebuild], out: $stdout)
|
|
189
|
+
end
|
|
190
|
+
rescue Gem::MissingSpecError
|
|
191
|
+
warn "Gem '#{name}' not found"
|
|
192
|
+
rescue Gem::Requirement::BadRequirementError => e
|
|
193
|
+
warn "Gem '#{name}' failed while loading"
|
|
194
|
+
warn e.message
|
|
195
|
+
# @sg-ignore Need to add nil check here
|
|
196
|
+
warn e.backtrace.join("\n")
|
|
197
|
+
end
|
|
198
|
+
$stderr.puts "Documentation cached for #{names.count} gems."
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
desc 'reporters', 'Get a list of diagnostics reporters'
|
|
203
|
+
# @return [void]
|
|
204
|
+
def reporters
|
|
205
|
+
puts Solargraph::Diagnostics.reporters
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
desc 'typecheck [FILE(s)]', 'Run the type checker'
|
|
209
|
+
long_desc %(
|
|
210
|
+
Perform type checking on one or more files in a workspace. Check the
|
|
211
|
+
entire workspace if no files are specified.
|
|
212
|
+
|
|
213
|
+
Type checking levels are normal, typed, strict, and strong.
|
|
214
|
+
)
|
|
215
|
+
option :level, type: :string, aliases: [:mode, :m, :l], desc: 'Type checking level', default: 'normal'
|
|
216
|
+
option :directory, type: :string, aliases: :d, desc: 'The workspace directory', default: '.'
|
|
217
|
+
# @return [void]
|
|
218
|
+
def typecheck *files
|
|
219
|
+
directory = File.realpath(options[:directory])
|
|
220
|
+
workspace = Solargraph::Workspace.new(directory)
|
|
221
|
+
level = options[:level].to_sym
|
|
222
|
+
rules = workspace.rules(level)
|
|
223
|
+
api_map =
|
|
224
|
+
Solargraph::ApiMap.load_with_cache(directory, $stdout,
|
|
225
|
+
loose_unions:
|
|
226
|
+
!rules.require_all_unique_types_support_call?)
|
|
227
|
+
probcount = 0
|
|
228
|
+
if files.empty?
|
|
229
|
+
files = api_map.source_maps.map(&:filename)
|
|
230
|
+
else
|
|
231
|
+
files.map! { |file| File.realpath(file) }
|
|
232
|
+
end
|
|
233
|
+
filecount = 0
|
|
234
|
+
time = Benchmark.measure {
|
|
235
|
+
files.each do |file|
|
|
236
|
+
checker = TypeChecker.new(file, api_map: api_map, rules: rules, level: options[:level].to_sym, workspace: workspace)
|
|
237
|
+
problems = checker.problems
|
|
238
|
+
next if problems.empty?
|
|
239
|
+
problems.sort! { |a, b| a.location.range.start.line <=> b.location.range.start.line }
|
|
240
|
+
puts problems.map { |prob| "#{prob.location.filename}:#{prob.location.range.start.line + 1} - #{prob.message}" }.join("\n")
|
|
241
|
+
filecount += 1
|
|
242
|
+
probcount += problems.length
|
|
243
|
+
end
|
|
244
|
+
}
|
|
245
|
+
puts "Typecheck finished in #{time.real} seconds."
|
|
246
|
+
puts "#{probcount} problem#{probcount != 1 ? 's' : ''} found#{files.length != 1 ? " in #{filecount} of #{files.length} files" : ''}."
|
|
247
|
+
# "
|
|
248
|
+
exit 1 if probcount > 0
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
desc 'scan', 'Test the workspace for problems'
|
|
252
|
+
long_desc %(
|
|
253
|
+
A scan loads the entire workspace to make sure that the ASTs and
|
|
254
|
+
maps do not raise errors during analysis. It does not perform any type
|
|
255
|
+
checking or validation; it only confirms that the analysis itself is
|
|
256
|
+
error-free.
|
|
257
|
+
)
|
|
258
|
+
option :directory, type: :string, aliases: :d, desc: 'The workspace directory', default: '.'
|
|
259
|
+
option :verbose, type: :boolean, aliases: :v, desc: 'Verbose output', default: false
|
|
260
|
+
# @return [void]
|
|
261
|
+
def scan
|
|
262
|
+
directory = File.realpath(options[:directory])
|
|
263
|
+
# @type [Solargraph::ApiMap, nil]
|
|
264
|
+
api_map = nil
|
|
265
|
+
time = Benchmark.measure {
|
|
266
|
+
api_map = Solargraph::ApiMap.load_with_cache(directory, $stdout)
|
|
267
|
+
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
268
|
+
api_map.pins.each do |pin|
|
|
269
|
+
begin
|
|
270
|
+
puts pin_description(pin) if options[:verbose]
|
|
271
|
+
pin.typify api_map
|
|
272
|
+
pin.probe api_map
|
|
273
|
+
rescue StandardError => e
|
|
274
|
+
# @todo to add nil check here
|
|
275
|
+
# @todo should warn on nil dereference below
|
|
276
|
+
STDERR.puts "Error testing #{pin_description(pin)} #{pin.location ? "at #{pin.location.filename}:#{pin.location.range.start.line + 1}" : ''}"
|
|
277
|
+
STDERR.puts "[#{e.class}]: #{e.message}"
|
|
278
|
+
# @todo Need to add nil check here
|
|
279
|
+
# @todo flow sensitive typing should be able to handle redefinition
|
|
280
|
+
STDERR.puts e.backtrace.join("\n")
|
|
281
|
+
exit 1
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
}
|
|
285
|
+
# @sg-ignore Need to add nil check here
|
|
286
|
+
puts "Scanned #{directory} (#{api_map.pins.length} pins) in #{time.real} seconds."
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
desc 'list', 'List the files in the workspace and the total count'
|
|
290
|
+
option :count, type: :boolean, aliases: :c, desc: 'Display the file count only', default: false
|
|
291
|
+
option :directory, type: :string, aliases: :d, desc: 'The directory to read', default: '.'
|
|
292
|
+
# @return [void]
|
|
293
|
+
def list
|
|
294
|
+
workspace = Solargraph::Workspace.new(options[:directory])
|
|
295
|
+
puts workspace.filenames unless options[:count]
|
|
296
|
+
puts "#{workspace.filenames.length} files total."
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
desc 'pin [PATH]', 'Describe a pin', hide: true
|
|
300
|
+
option :rbs, type: :boolean, desc: 'Output the pin as RBS', default: false
|
|
301
|
+
option :typify, type: :boolean, desc: 'Output the calculated return type of the pin from annotations', default: false
|
|
302
|
+
option :references, type: :boolean, desc: 'Show references', default: false
|
|
303
|
+
option :probe, type: :boolean, desc: 'Output the calculated return type of the pin from annotations and inference', default: false
|
|
304
|
+
option :stack, type: :boolean, desc: 'Show entire stack of a method pin by including definitions in superclasses', default: false
|
|
305
|
+
# @param path [String] The path to the method pin, e.g. 'Class#method' or 'Class.method'
|
|
306
|
+
# @return [void]
|
|
307
|
+
def pin path
|
|
308
|
+
api_map = Solargraph::ApiMap.load_with_cache('.', $stderr)
|
|
309
|
+
is_method = path.include?('#') || path.include?('.')
|
|
310
|
+
if is_method && options[:stack]
|
|
311
|
+
scope, ns, meth = if path.include? '#'
|
|
312
|
+
[:instance, *path.split('#', 2)]
|
|
313
|
+
else
|
|
314
|
+
[:class, *path.split('.', 2)]
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# @sg-ignore Wrong argument type for
|
|
318
|
+
# Solargraph::ApiMap#get_method_stack: rooted_tag
|
|
319
|
+
# expected String, received Array<String>
|
|
320
|
+
pins = api_map.get_method_stack(ns, meth, scope: scope)
|
|
321
|
+
else
|
|
322
|
+
pins = api_map.get_path_pins path
|
|
323
|
+
end
|
|
324
|
+
# @type [Hash{Symbol => Pin::Base}]
|
|
325
|
+
references = {}
|
|
326
|
+
pin = pins.first
|
|
327
|
+
case pin
|
|
328
|
+
when nil
|
|
329
|
+
$stderr.puts "Pin not found for path '#{path}'"
|
|
330
|
+
exit 1
|
|
331
|
+
when Pin::Namespace
|
|
332
|
+
if options[:references]
|
|
333
|
+
# @sg-ignore Need to add nil check here
|
|
334
|
+
superclass_tag = api_map.qualify_superclass(pin.return_type.tag)
|
|
335
|
+
superclass_pin = api_map.get_path_pins(superclass_tag).first if superclass_tag
|
|
336
|
+
references[:superclass] = superclass_pin if superclass_pin
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
pins.each do |pin|
|
|
341
|
+
if options[:typify] || options[:probe]
|
|
342
|
+
type = ComplexType::UNDEFINED
|
|
343
|
+
type = pin.typify(api_map) if options[:typify]
|
|
344
|
+
type = pin.probe(api_map) if options[:probe] && type.undefined?
|
|
345
|
+
print_type(type)
|
|
346
|
+
next
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
print_pin(pin)
|
|
350
|
+
end
|
|
351
|
+
references.each do |key, refpin|
|
|
352
|
+
puts "\n# #{key.to_s.capitalize}:\n\n"
|
|
353
|
+
print_pin(refpin)
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
private
|
|
358
|
+
|
|
359
|
+
# @param pin [Solargraph::Pin::Base]
|
|
360
|
+
# @return [String]
|
|
361
|
+
def pin_description pin
|
|
362
|
+
desc = if pin.path.nil? || pin.path.empty?
|
|
363
|
+
if pin.closure
|
|
364
|
+
# @sg-ignore Need to add nil check here
|
|
365
|
+
"#{pin.closure.path} | #{pin.name}"
|
|
366
|
+
else
|
|
367
|
+
"#{pin.context.namespace} | #{pin.name}"
|
|
368
|
+
end
|
|
369
|
+
else
|
|
370
|
+
pin.path
|
|
371
|
+
end
|
|
372
|
+
# @sg-ignore Need to add nil check here
|
|
373
|
+
desc += " (#{pin.location.filename} #{pin.location.range.start.line})" if pin.location
|
|
374
|
+
desc
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
# @param type [ComplexType, ComplexType::UniqueType]
|
|
378
|
+
# @return [void]
|
|
379
|
+
def print_type(type)
|
|
380
|
+
if options[:rbs]
|
|
381
|
+
puts type.to_rbs
|
|
382
|
+
else
|
|
383
|
+
puts type.rooted_tag
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
# @param pin [Solargraph::Pin::Base]
|
|
388
|
+
# @return [void]
|
|
389
|
+
def print_pin(pin)
|
|
390
|
+
if options[:rbs]
|
|
391
|
+
puts pin.to_rbs
|
|
392
|
+
else
|
|
393
|
+
puts pin.inspect
|
|
394
|
+
end
|
|
395
|
+
end
|
|
396
|
+
end
|
|
397
|
+
end
|