solargraph 0.59.0.dev.1 → 0.59.0.dev.2
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/.github/workflows/plugins.yml +4 -1
- data/.github/workflows/rspec.yml +3 -14
- data/.gitignore +1 -0
- data/.rubocop.yml +32 -5
- data/.rubocop_todo.yml +37 -931
- data/CHANGELOG.md +7 -1
- data/Gemfile +3 -1
- data/Rakefile +25 -23
- data/bin/solargraph +2 -1
- data/lib/solargraph/api_map/index.rb +5 -11
- data/lib/solargraph/api_map/source_to_yard.rb +9 -8
- data/lib/solargraph/api_map/store.rb +22 -20
- data/lib/solargraph/api_map.rb +50 -37
- data/lib/solargraph/bench.rb +44 -45
- data/lib/solargraph/complex_type/type_methods.rb +12 -15
- data/lib/solargraph/complex_type/unique_type.rb +54 -43
- data/lib/solargraph/complex_type.rb +69 -61
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +4 -4
- data/lib/solargraph/convention/data_definition.rb +1 -1
- data/lib/solargraph/convention/gemfile.rb +15 -15
- data/lib/solargraph/convention/gemspec.rb +23 -23
- data/lib/solargraph/convention/rakefile.rb +17 -17
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +1 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +3 -3
- data/lib/solargraph/convention/struct_definition.rb +3 -3
- data/lib/solargraph/convention.rb +78 -78
- data/lib/solargraph/converters/dd.rb +19 -17
- data/lib/solargraph/converters/dl.rb +17 -15
- data/lib/solargraph/converters/dt.rb +17 -15
- data/lib/solargraph/converters/misc.rb +3 -1
- data/lib/solargraph/diagnostics/rubocop.rb +10 -10
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +3 -3
- data/lib/solargraph/diagnostics/type_check.rb +10 -10
- data/lib/solargraph/diagnostics/update_errors.rb +37 -41
- data/lib/solargraph/doc_map.rb +9 -10
- data/lib/solargraph/equality.rb +3 -3
- data/lib/solargraph/gem_pins.rb +7 -5
- data/lib/solargraph/language_server/error_codes.rb +20 -20
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
- data/lib/solargraph/language_server/host/dispatch.rb +2 -3
- data/lib/solargraph/language_server/host/message_worker.rb +2 -2
- data/lib/solargraph/language_server/host/sources.rb +1 -1
- data/lib/solargraph/language_server/host.rb +24 -21
- data/lib/solargraph/language_server/message/base.rb +97 -97
- data/lib/solargraph/language_server/message/client/register_capability.rb +13 -15
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +58 -60
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +10 -11
- data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
- data/lib/solargraph/language_server/message/extended/download_core.rb +20 -19
- data/lib/solargraph/language_server/message/extended/search.rb +20 -20
- data/lib/solargraph/language_server/message/initialize.rb +197 -191
- data/lib/solargraph/language_server/message/text_document/completion.rb +8 -8
- data/lib/solargraph/language_server/message/text_document/definition.rb +41 -34
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +29 -21
- data/lib/solargraph/language_server/message/text_document/formatting.rb +6 -6
- data/lib/solargraph/language_server/message/text_document/hover.rb +3 -5
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +18 -11
- data/lib/solargraph/language_server/message/text_document/references.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/rename.rb +26 -19
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +2 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -19
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +41 -35
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +48 -40
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +32 -26
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -19
- data/lib/solargraph/language_server/message.rb +94 -94
- data/lib/solargraph/language_server/request.rb +29 -27
- data/lib/solargraph/language_server/transport/data_reader.rb +72 -74
- data/lib/solargraph/language_server/uri_helpers.rb +49 -49
- data/lib/solargraph/library.rb +28 -33
- data/lib/solargraph/location.rb +10 -12
- data/lib/solargraph/logging.rb +4 -4
- data/lib/solargraph/page.rb +92 -92
- data/lib/solargraph/parser/comment_ripper.rb +12 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +32 -42
- data/lib/solargraph/parser/node_processor/base.rb +4 -4
- data/lib/solargraph/parser/node_processor.rb +1 -1
- data/lib/solargraph/parser/parser_gem/class_methods.rb +4 -4
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +20 -20
- data/lib/solargraph/parser/parser_gem/node_methods.rb +66 -65
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +12 -12
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +38 -37
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +3 -5
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +118 -112
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem.rb +14 -12
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +25 -23
- data/lib/solargraph/pin/base.rb +78 -64
- data/lib/solargraph/pin/base_variable.rb +28 -71
- data/lib/solargraph/pin/block.rb +3 -2
- data/lib/solargraph/pin/breakable.rb +2 -0
- data/lib/solargraph/pin/callable.rb +23 -26
- data/lib/solargraph/pin/closure.rb +5 -4
- data/lib/solargraph/pin/common.rb +5 -2
- data/lib/solargraph/pin/compound_statement.rb +3 -3
- data/lib/solargraph/pin/constant.rb +43 -45
- data/lib/solargraph/pin/conversions.rb +9 -4
- data/lib/solargraph/pin/delegated_method.rb +4 -4
- data/lib/solargraph/pin/documenting.rb +3 -2
- data/lib/solargraph/pin/local_variable.rb +4 -4
- data/lib/solargraph/pin/method.rb +71 -70
- data/lib/solargraph/pin/namespace.rb +13 -12
- data/lib/solargraph/pin/parameter.rb +28 -27
- data/lib/solargraph/pin/proxy_type.rb +2 -0
- data/lib/solargraph/pin/reference.rb +17 -0
- data/lib/solargraph/pin/search.rb +2 -2
- data/lib/solargraph/pin/signature.rb +9 -14
- data/lib/solargraph/pin/symbol.rb +1 -0
- data/lib/solargraph/pin/until.rb +1 -3
- data/lib/solargraph/pin/while.rb +1 -3
- data/lib/solargraph/pin_cache.rb +16 -19
- data/lib/solargraph/position.rb +35 -17
- data/lib/solargraph/range.rb +10 -9
- data/lib/solargraph/rbs_map/conversions.rb +312 -206
- data/lib/solargraph/rbs_map/core_fills.rb +91 -84
- data/lib/solargraph/rbs_map/stdlib_map.rb +0 -1
- data/lib/solargraph/rbs_map.rb +3 -12
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +63 -53
- data/lib/solargraph/source/chain/array.rb +39 -37
- data/lib/solargraph/source/chain/call.rb +49 -44
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +3 -1
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +8 -6
- data/lib/solargraph/source/chain/if.rb +11 -10
- data/lib/solargraph/source/chain/instance_variable.rb +3 -1
- data/lib/solargraph/source/chain/link.rb +99 -109
- data/lib/solargraph/source/chain/literal.rb +4 -6
- data/lib/solargraph/source/chain/or.rb +2 -4
- data/lib/solargraph/source/chain/q_call.rb +13 -11
- data/lib/solargraph/source/chain/variable.rb +15 -13
- data/lib/solargraph/source/chain/z_super.rb +28 -30
- data/lib/solargraph/source/chain.rb +24 -16
- data/lib/solargraph/source/change.rb +3 -3
- data/lib/solargraph/source/cursor.rb +18 -18
- data/lib/solargraph/source/encoding_fixes.rb +6 -7
- data/lib/solargraph/source/source_chainer.rb +46 -32
- data/lib/solargraph/source/updater.rb +1 -1
- data/lib/solargraph/source.rb +27 -29
- data/lib/solargraph/source_map/clip.rb +38 -30
- data/lib/solargraph/source_map/mapper.rb +52 -46
- data/lib/solargraph/source_map.rb +8 -4
- data/lib/solargraph/type_checker/rules.rb +8 -8
- data/lib/solargraph/type_checker.rb +95 -101
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +10 -9
- data/lib/solargraph/workspace/gemspecs.rb +1 -1
- data/lib/solargraph/workspace.rb +21 -44
- data/lib/solargraph/yard_map/helpers.rb +6 -2
- data/lib/solargraph/yard_map/mapper/to_method.rb +8 -6
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -1
- data/lib/solargraph/yard_map/mapper.rb +12 -12
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph.rb +5 -5
- data/solargraph.gemspec +35 -34
- metadata +28 -28
|
@@ -23,6 +23,7 @@ module Solargraph
|
|
|
23
23
|
# @param signatures [::Array<Signature>, nil]
|
|
24
24
|
# @param anon_splat [Boolean]
|
|
25
25
|
# @param context [ComplexType, ComplexType::UniqueType, nil]
|
|
26
|
+
# @param [Hash{Symbol => Object}] splat
|
|
26
27
|
def initialize visibility: :public, explicit: true, block: :undefined, node: nil, attribute: false, signatures: nil, anon_splat: false,
|
|
27
28
|
context: nil, **splat
|
|
28
29
|
super(**splat)
|
|
@@ -38,7 +39,7 @@ module Solargraph
|
|
|
38
39
|
|
|
39
40
|
# @param other [Pin::Method]
|
|
40
41
|
# @return [::Symbol]
|
|
41
|
-
def combine_visibility
|
|
42
|
+
def combine_visibility other
|
|
42
43
|
if dodgy_visibility_source? && !other.dodgy_visibility_source?
|
|
43
44
|
other.visibility
|
|
44
45
|
elsif other.dodgy_visibility_source? && !dodgy_visibility_source?
|
|
@@ -48,16 +49,16 @@ module Solargraph
|
|
|
48
49
|
end
|
|
49
50
|
end
|
|
50
51
|
|
|
51
|
-
def combine_with
|
|
52
|
+
def combine_with other, attrs = {}
|
|
52
53
|
priority_choice = choose_priority(other)
|
|
53
54
|
return priority_choice unless priority_choice.nil?
|
|
54
55
|
|
|
55
56
|
sigs = combine_signatures(other)
|
|
56
|
-
parameters = if sigs.length
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
parameters = if sigs.length.positive?
|
|
58
|
+
[].freeze
|
|
59
|
+
else
|
|
60
|
+
choose(other, :parameters).clone.freeze
|
|
61
|
+
end
|
|
61
62
|
new_attrs = {
|
|
62
63
|
visibility: combine_visibility(other),
|
|
63
64
|
explicit: explicit? || other.explicit?,
|
|
@@ -77,7 +78,7 @@ module Solargraph
|
|
|
77
78
|
super && other.node == node
|
|
78
79
|
end
|
|
79
80
|
|
|
80
|
-
def transform_types
|
|
81
|
+
def transform_types &transform
|
|
81
82
|
# @todo 'super' alone should work here I think, but doesn't typecheck at level typed
|
|
82
83
|
m = super(&transform)
|
|
83
84
|
m.signatures = m.signatures.map do |sig|
|
|
@@ -92,14 +93,12 @@ module Solargraph
|
|
|
92
93
|
def reset_generated!
|
|
93
94
|
super
|
|
94
95
|
unless signatures.empty?
|
|
95
|
-
return_type = nil
|
|
96
96
|
@block = :undefined
|
|
97
|
-
|
|
97
|
+
[]
|
|
98
98
|
end
|
|
99
99
|
block&.reset_generated!
|
|
100
100
|
@signatures&.each(&:reset_generated!)
|
|
101
|
-
|
|
102
|
-
documentation = nil
|
|
101
|
+
nil
|
|
103
102
|
end
|
|
104
103
|
|
|
105
104
|
def all_rooted?
|
|
@@ -108,7 +107,7 @@ module Solargraph
|
|
|
108
107
|
|
|
109
108
|
# @param signature [Pin::Signature]
|
|
110
109
|
# @return [Pin::Method]
|
|
111
|
-
def with_single_signature
|
|
110
|
+
def with_single_signature signature
|
|
112
111
|
m = proxy signature.return_type
|
|
113
112
|
m.reset_generated!
|
|
114
113
|
# @todo populating the single parameters/return_type/block
|
|
@@ -150,7 +149,7 @@ module Solargraph
|
|
|
150
149
|
# @param parameters [::Array<Parameter>]
|
|
151
150
|
# @param return_type [ComplexType, nil]
|
|
152
151
|
# @return [Signature]
|
|
153
|
-
def generate_signature
|
|
152
|
+
def generate_signature parameters, return_type
|
|
154
153
|
# @type [Pin::Signature, nil]
|
|
155
154
|
block = nil
|
|
156
155
|
yieldparam_tags = docstring.tags(:yieldparam)
|
|
@@ -172,8 +171,7 @@ module Solargraph
|
|
|
172
171
|
comments: p.text,
|
|
173
172
|
name: name,
|
|
174
173
|
decl: decl,
|
|
175
|
-
|
|
176
|
-
presence: location ? location.range : nil,
|
|
174
|
+
presence: location&.range,
|
|
177
175
|
return_type: ComplexType.try_parse(*p.types),
|
|
178
176
|
source: source
|
|
179
177
|
)
|
|
@@ -194,7 +192,11 @@ module Solargraph
|
|
|
194
192
|
top_type = generate_complex_type
|
|
195
193
|
result = []
|
|
196
194
|
result.push generate_signature(parameters, top_type) if top_type.defined?
|
|
197
|
-
|
|
195
|
+
unless overloads.empty?
|
|
196
|
+
result.concat(overloads.map do |meth|
|
|
197
|
+
generate_signature(meth.parameters, meth.return_type)
|
|
198
|
+
end)
|
|
199
|
+
end
|
|
198
200
|
result.push generate_signature(parameters, @return_type || ComplexType::UNDEFINED) if result.empty?
|
|
199
201
|
result
|
|
200
202
|
end
|
|
@@ -214,12 +216,18 @@ module Solargraph
|
|
|
214
216
|
# change when pins get proxied.
|
|
215
217
|
detail = String.new
|
|
216
218
|
detail += if signatures.length > 1
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
219
|
+
'(*) '
|
|
220
|
+
else
|
|
221
|
+
"(#{signatures.first.parameters.map(&:full).join(', ')}) " unless signatures.first.parameters.empty?
|
|
222
|
+
end.to_s
|
|
221
223
|
# @sg-ignore Need to add nil check here
|
|
222
|
-
|
|
224
|
+
unless return_type.undefined?
|
|
225
|
+
detail += "=#{if probed?
|
|
226
|
+
'~'
|
|
227
|
+
else
|
|
228
|
+
(proxied? ? '^' : '>')
|
|
229
|
+
end} #{return_type}"
|
|
230
|
+
end
|
|
223
231
|
detail.strip!
|
|
224
232
|
return nil if detail.empty?
|
|
225
233
|
detail
|
|
@@ -229,7 +237,7 @@ module Solargraph
|
|
|
229
237
|
def signature_help
|
|
230
238
|
@signature_help ||= signatures.map do |sig|
|
|
231
239
|
{
|
|
232
|
-
label: name
|
|
240
|
+
label: "#{name}(#{sig.parameters.map(&:full).join(', ')})",
|
|
233
241
|
documentation: documentation
|
|
234
242
|
}
|
|
235
243
|
end
|
|
@@ -258,7 +266,7 @@ module Solargraph
|
|
|
258
266
|
end
|
|
259
267
|
|
|
260
268
|
def path
|
|
261
|
-
@path ||= "#{namespace}#{
|
|
269
|
+
@path ||= "#{namespace}#{scope == :instance ? '#' : '.'}#{name}"
|
|
262
270
|
end
|
|
263
271
|
|
|
264
272
|
# @return [String]
|
|
@@ -267,11 +275,15 @@ module Solargraph
|
|
|
267
275
|
end
|
|
268
276
|
|
|
269
277
|
def typify api_map
|
|
270
|
-
|
|
271
|
-
|
|
278
|
+
logger.debug do
|
|
279
|
+
# @sg-ignore Need to add nil check here
|
|
280
|
+
"Method#typify(self=#{self}, binder=#{binder}, closure=#{closure}, context=#{context.rooted_tags}, return_type=#{return_type.rooted_tags}) - starting"
|
|
281
|
+
end
|
|
272
282
|
decl = super
|
|
273
283
|
unless decl.undefined?
|
|
274
|
-
logger.debug
|
|
284
|
+
logger.debug do
|
|
285
|
+
"Method#typify(self=#{self}, binder=#{binder}, closure=#{closure}, context=#{context}) => #{decl.rooted_tags.inspect} - decl found"
|
|
286
|
+
end
|
|
275
287
|
return decl
|
|
276
288
|
end
|
|
277
289
|
type = see_reference(api_map) || typify_from_super(api_map)
|
|
@@ -289,26 +301,26 @@ module Solargraph
|
|
|
289
301
|
if @documentation.nil?
|
|
290
302
|
method_docs ||= super || ''
|
|
291
303
|
param_tags = docstring.tags(:param)
|
|
292
|
-
unless param_tags.nil?
|
|
304
|
+
unless param_tags.nil? || param_tags.empty?
|
|
293
305
|
method_docs += "\n\n" unless method_docs.empty?
|
|
294
306
|
method_docs += "Params:\n"
|
|
295
307
|
lines = []
|
|
296
308
|
param_tags.each do |p|
|
|
297
309
|
l = "* #{p.name}"
|
|
298
|
-
l += " [#{escape_brackets(p.types.join(', '))}]" unless p.types.nil?
|
|
310
|
+
l += " [#{escape_brackets(p.types.join(', '))}]" unless p.types.nil? || p.types.empty?
|
|
299
311
|
l += " #{p.text}"
|
|
300
312
|
lines.push l
|
|
301
313
|
end
|
|
302
314
|
method_docs += lines.join("\n")
|
|
303
315
|
end
|
|
304
316
|
yieldparam_tags = docstring.tags(:yieldparam)
|
|
305
|
-
unless yieldparam_tags.nil?
|
|
317
|
+
unless yieldparam_tags.nil? || yieldparam_tags.empty?
|
|
306
318
|
method_docs += "\n\n" unless method_docs.empty?
|
|
307
319
|
method_docs += "Block Params:\n"
|
|
308
320
|
lines = []
|
|
309
321
|
yieldparam_tags.each do |p|
|
|
310
322
|
l = "* #{p.name}"
|
|
311
|
-
l += " [#{escape_brackets(p.types.join(', '))}]" unless p.types.nil?
|
|
323
|
+
l += " [#{escape_brackets(p.types.join(', '))}]" unless p.types.nil? || p.types.empty?
|
|
312
324
|
l += " #{p.text}"
|
|
313
325
|
lines.push l
|
|
314
326
|
end
|
|
@@ -320,8 +332,8 @@ module Solargraph
|
|
|
320
332
|
method_docs += "Block Returns:\n"
|
|
321
333
|
lines = []
|
|
322
334
|
yieldreturn_tags.each do |r|
|
|
323
|
-
l =
|
|
324
|
-
l += " [#{escape_brackets(r.types.join(', '))}]" unless r.types.nil?
|
|
335
|
+
l = '*'
|
|
336
|
+
l += " [#{escape_brackets(r.types.join(', '))}]" unless r.types.nil? || r.types.empty?
|
|
325
337
|
l += " #{r.text}"
|
|
326
338
|
lines.push l
|
|
327
339
|
end
|
|
@@ -333,8 +345,8 @@ module Solargraph
|
|
|
333
345
|
method_docs += "Returns:\n"
|
|
334
346
|
lines = []
|
|
335
347
|
return_tags.each do |r|
|
|
336
|
-
l =
|
|
337
|
-
l += " [#{escape_brackets(r.types.join(', '))}]" unless r.types.nil?
|
|
348
|
+
l = '*'
|
|
349
|
+
l += " [#{escape_brackets(r.types.join(', '))}]" unless r.types.nil? || r.types.empty?
|
|
338
350
|
l += " #{r.text}"
|
|
339
351
|
lines.push l
|
|
340
352
|
end
|
|
@@ -389,15 +401,14 @@ module Solargraph
|
|
|
389
401
|
comments: tag.docstring.all.to_s,
|
|
390
402
|
name: name,
|
|
391
403
|
decl: decl,
|
|
392
|
-
|
|
393
|
-
presence: location ? location.range : nil,
|
|
404
|
+
presence: location&.range,
|
|
394
405
|
return_type: param_type_from_name(tag, src.first),
|
|
395
406
|
source: :overloads
|
|
396
407
|
)
|
|
397
408
|
end,
|
|
398
409
|
closure: self,
|
|
399
410
|
return_type: ComplexType.try_parse(*tag.docstring.tags(:return).flat_map(&:types)),
|
|
400
|
-
source: :overloads
|
|
411
|
+
source: :overloads
|
|
401
412
|
)
|
|
402
413
|
end
|
|
403
414
|
@overloads
|
|
@@ -416,13 +427,13 @@ module Solargraph
|
|
|
416
427
|
return self unless docstring.ref_tags.any?
|
|
417
428
|
docstring.ref_tags.each do |tag|
|
|
418
429
|
ref = if tag.owner.to_s.start_with?(/[#.]/)
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
430
|
+
api_map.get_methods(namespace)
|
|
431
|
+
.select { |pin| pin.path.end_with?(tag.owner.to_s) }
|
|
432
|
+
.first
|
|
433
|
+
else
|
|
434
|
+
# @todo Resolve relative namespaces
|
|
435
|
+
api_map.get_path_pins(tag.owner.to_s).first
|
|
436
|
+
end
|
|
426
437
|
next unless ref
|
|
427
438
|
|
|
428
439
|
docstring.add_tag(*ref.docstring.tags(:param))
|
|
@@ -438,11 +449,7 @@ module Solargraph
|
|
|
438
449
|
|
|
439
450
|
protected
|
|
440
451
|
|
|
441
|
-
attr_writer :block
|
|
442
|
-
|
|
443
|
-
attr_writer :signature_help
|
|
444
|
-
|
|
445
|
-
attr_writer :documentation
|
|
452
|
+
attr_writer :block, :signature_help, :documentation, :return_type
|
|
446
453
|
|
|
447
454
|
# @sg-ignore Need to add nil check here
|
|
448
455
|
def dodgy_visibility_source?
|
|
@@ -450,22 +457,22 @@ module Solargraph
|
|
|
450
457
|
# e.g. activesupport did not understand 'private' markings
|
|
451
458
|
# inside 'class << self' blocks, but YARD did OK at it
|
|
452
459
|
# @sg-ignore Need to add nil check here
|
|
453
|
-
source == :rbs && scope == :class && type_location&.filename&.include?('generated') && return_type.undefined? ||
|
|
460
|
+
(source == :rbs && scope == :class && type_location&.filename&.include?('generated') && return_type.undefined?) ||
|
|
454
461
|
# YARD's RBS generator seems to miss a lot of should-be protected instance methods
|
|
455
|
-
source == :rbs && scope == :instance && namespace.start_with?('YARD::') ||
|
|
462
|
+
(source == :rbs && scope == :instance && namespace.start_with?('YARD::')) ||
|
|
456
463
|
# private on attr_readers seems to be broken in Prism's auto-generator script
|
|
457
|
-
source == :rbs && scope == :instance && namespace.start_with?('Prism::') ||
|
|
464
|
+
(source == :rbs && scope == :instance && namespace.start_with?('Prism::')) ||
|
|
458
465
|
# The RBS for the RBS gem itself seems to use private as a
|
|
459
466
|
# 'is this a public API' concept, more aggressively than the
|
|
460
467
|
# actual code. Let's respect that and ignore the actual .rb file.
|
|
461
|
-
source == :yardoc && scope == :instance && namespace.start_with?('RBS::')
|
|
468
|
+
(source == :yardoc && scope == :instance && namespace.start_with?('RBS::'))
|
|
462
469
|
end
|
|
463
470
|
|
|
464
471
|
private
|
|
465
472
|
|
|
466
473
|
# @param other [Pin::Method]
|
|
467
474
|
# @return [Array<Pin::Signature>]
|
|
468
|
-
def combine_signatures
|
|
475
|
+
def combine_signatures other
|
|
469
476
|
all_undefined = signatures.all? { |sig| !sig.return_type&.defined? }
|
|
470
477
|
other_all_undefined = other.signatures.all? { |sig| !sig.return_type&.defined? }
|
|
471
478
|
if all_undefined && !other_all_undefined
|
|
@@ -497,16 +504,14 @@ module Solargraph
|
|
|
497
504
|
# @param same_type_arity_signatures [Array<Pin::Signature>]
|
|
498
505
|
#
|
|
499
506
|
# @return [Array<Pin::Signature>]
|
|
500
|
-
def combine_same_type_arity_signatures
|
|
507
|
+
def combine_same_type_arity_signatures same_type_arity_signatures
|
|
501
508
|
# This is an O(n^2) operation, so bail out if n is not small
|
|
502
509
|
return same_type_arity_signatures if same_type_arity_signatures.length > 10
|
|
503
510
|
|
|
504
511
|
# @param old_signatures [Array<Pin::Signature>]
|
|
505
512
|
# @param new_signature [Pin::Signature]
|
|
506
513
|
same_type_arity_signatures.reduce([]) do |old_signatures, new_signature|
|
|
507
|
-
next [new_signature] if old_signatures.empty?
|
|
508
|
-
|
|
509
|
-
found_merge = false
|
|
514
|
+
next old_signatures + [new_signature] if old_signatures.empty?
|
|
510
515
|
old_signatures.flat_map do |old_signature|
|
|
511
516
|
potential_new_signature = old_signature.combine_with(new_signature)
|
|
512
517
|
|
|
@@ -560,7 +565,7 @@ module Solargraph
|
|
|
560
565
|
# @param name [String]
|
|
561
566
|
#
|
|
562
567
|
# @return [ComplexType]
|
|
563
|
-
def param_type_from_name
|
|
568
|
+
def param_type_from_name tag, name
|
|
564
569
|
# @param t [YARD::Tags::Tag]
|
|
565
570
|
param = tag.tags(:param).select { |t| t.name == name }.first
|
|
566
571
|
return ComplexType::UNDEFINED unless param
|
|
@@ -571,7 +576,7 @@ module Solargraph
|
|
|
571
576
|
def generate_complex_type
|
|
572
577
|
tags = docstring.tags(:return).map(&:types).flatten.compact
|
|
573
578
|
return ComplexType::UNDEFINED if tags.empty?
|
|
574
|
-
ComplexType.try_parse
|
|
579
|
+
ComplexType.try_parse(*tags)
|
|
575
580
|
end
|
|
576
581
|
|
|
577
582
|
# @param api_map [ApiMap]
|
|
@@ -635,7 +640,7 @@ module Solargraph
|
|
|
635
640
|
return nil if node.nil?
|
|
636
641
|
return node.children[1].children.last if node.type == :DEFN
|
|
637
642
|
return node.children[2].children.last if node.type == :DEFS
|
|
638
|
-
return node.children[2] if
|
|
643
|
+
return node.children[2] if %i[def DEFS].include?(node.type)
|
|
639
644
|
return node.children[3] if node.type == :defs
|
|
640
645
|
nil
|
|
641
646
|
end
|
|
@@ -648,7 +653,7 @@ module Solargraph
|
|
|
648
653
|
has_nil = false
|
|
649
654
|
return ComplexType::NIL if method_body_node.nil?
|
|
650
655
|
returns_from_method_body(method_body_node).each do |n|
|
|
651
|
-
if n.nil? || [
|
|
656
|
+
if n.nil? || %i[NIL nil].include?(n.type)
|
|
652
657
|
has_nil = true
|
|
653
658
|
next
|
|
654
659
|
end
|
|
@@ -688,12 +693,12 @@ module Solargraph
|
|
|
688
693
|
#
|
|
689
694
|
# @param name [String]
|
|
690
695
|
# @return [::Array(String, ::Symbol)]
|
|
691
|
-
def parse_overload_param
|
|
696
|
+
def parse_overload_param name
|
|
692
697
|
# @todo this needs to handle mandatory vs not args, kwargs, blocks, etc
|
|
693
698
|
if name.start_with?('**')
|
|
694
|
-
[name[2
|
|
699
|
+
[name[2..], :kwrestarg]
|
|
695
700
|
elsif name.start_with?('*')
|
|
696
|
-
[name[1
|
|
701
|
+
[name[1..], :restarg]
|
|
697
702
|
else
|
|
698
703
|
[name, :arg]
|
|
699
704
|
end
|
|
@@ -711,10 +716,6 @@ module Solargraph
|
|
|
711
716
|
.join("\n")
|
|
712
717
|
.concat("```\n")
|
|
713
718
|
end
|
|
714
|
-
|
|
715
|
-
protected
|
|
716
|
-
|
|
717
|
-
attr_writer :return_type
|
|
718
719
|
end
|
|
719
720
|
end
|
|
720
721
|
end
|
|
@@ -20,13 +20,14 @@ module Solargraph
|
|
|
20
20
|
# @param visibility [::Symbol] :public or :private
|
|
21
21
|
# @param gates [::Array<String>]
|
|
22
22
|
# @param name [String]
|
|
23
|
+
# @param [Hash{Symbol => Object}] splat
|
|
23
24
|
def initialize type: :class, visibility: :public, gates: [''], name: '', **splat
|
|
24
25
|
# super(location, namespace, name, comments)
|
|
25
26
|
super(**splat, name: name)
|
|
26
27
|
@type = type
|
|
27
28
|
@visibility = visibility
|
|
28
29
|
if name.start_with?('::')
|
|
29
|
-
name = name[2
|
|
30
|
+
name = name[2..] || ''
|
|
30
31
|
@closure = Solargraph::Pin::ROOT_PIN
|
|
31
32
|
end
|
|
32
33
|
@open_gates = gates
|
|
@@ -36,11 +37,11 @@ module Solargraph
|
|
|
36
37
|
parts = name.split('::')
|
|
37
38
|
name = parts.pop
|
|
38
39
|
closure_name = if [Solargraph::Pin::ROOT_PIN, nil].include?(closure)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
''
|
|
41
|
+
else
|
|
42
|
+
# @sg-ignore Need to add nil check here
|
|
43
|
+
"#{closure.full_context.namespace}::"
|
|
44
|
+
end
|
|
44
45
|
closure_name += parts.join('::')
|
|
45
46
|
@closure = Pin::Namespace.new(name: closure_name, gates: [parts.join('::')], source: :namespace)
|
|
46
47
|
@context = nil
|
|
@@ -55,7 +56,7 @@ module Solargraph
|
|
|
55
56
|
end
|
|
56
57
|
|
|
57
58
|
def to_rbs
|
|
58
|
-
"#{@type
|
|
59
|
+
"#{@type} #{return_type.all_params.first.to_rbs}#{rbs_generics}".strip
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
def inner_desc
|
|
@@ -97,7 +98,7 @@ module Solargraph
|
|
|
97
98
|
end
|
|
98
99
|
|
|
99
100
|
def return_type
|
|
100
|
-
@return_type ||= ComplexType.try_parse(
|
|
101
|
+
@return_type ||= ComplexType.try_parse((type == :class ? '::Class' : '::Module') + "<::#{path}>")
|
|
101
102
|
end
|
|
102
103
|
|
|
103
104
|
# @return [Array<String>]
|
|
@@ -111,10 +112,10 @@ module Solargraph
|
|
|
111
112
|
|
|
112
113
|
def gates
|
|
113
114
|
@gates ||= if path.empty?
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
@open_gates
|
|
116
|
+
else
|
|
117
|
+
[path] + @open_gates
|
|
118
|
+
end
|
|
118
119
|
end
|
|
119
120
|
end
|
|
120
121
|
end
|
|
@@ -15,6 +15,7 @@ module Solargraph
|
|
|
15
15
|
|
|
16
16
|
# @param decl [::Symbol] :arg, :optarg, :kwarg, :kwoptarg, :restarg, :kwrestarg, :block, :blockarg
|
|
17
17
|
# @param asgn_code [String, nil]
|
|
18
|
+
# @param [Hash{Symbol => Object}] splat
|
|
18
19
|
def initialize decl: :arg, asgn_code: nil, **splat
|
|
19
20
|
super(**splat)
|
|
20
21
|
@asgn_code = asgn_code
|
|
@@ -29,7 +30,7 @@ module Solargraph
|
|
|
29
30
|
super || closure&.type_location
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
def combine_with
|
|
33
|
+
def combine_with other, attrs = {}
|
|
33
34
|
# Parameters can be combined with local variables
|
|
34
35
|
new_attrs = if other.is_a?(Parameter)
|
|
35
36
|
{
|
|
@@ -45,7 +46,7 @@ module Solargraph
|
|
|
45
46
|
super(other, new_attrs.merge(attrs))
|
|
46
47
|
end
|
|
47
48
|
|
|
48
|
-
def combine_return_type
|
|
49
|
+
def combine_return_type other
|
|
49
50
|
out = super
|
|
50
51
|
if out&.undefined?
|
|
51
52
|
# allow our return_type method to provide a better type
|
|
@@ -56,12 +57,12 @@ module Solargraph
|
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
def keyword?
|
|
59
|
-
[
|
|
60
|
+
%i[kwarg kwoptarg].include?(decl)
|
|
60
61
|
end
|
|
61
62
|
|
|
62
63
|
def kwrestarg?
|
|
63
64
|
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
64
|
-
decl == :kwrestarg || (assignment && [
|
|
65
|
+
decl == :kwrestarg || (assignment && %i[HASH hash].include?(assignment.type))
|
|
65
66
|
end
|
|
66
67
|
|
|
67
68
|
def needs_consistent_name?
|
|
@@ -70,21 +71,21 @@ module Solargraph
|
|
|
70
71
|
|
|
71
72
|
# @return [String]
|
|
72
73
|
def arity_decl
|
|
73
|
-
name =
|
|
74
|
-
|
|
74
|
+
name = self.name || '(anon)'
|
|
75
|
+
return_type&.to_rbs || 'untyped'
|
|
75
76
|
case decl
|
|
76
77
|
when :arg
|
|
77
|
-
|
|
78
|
+
''
|
|
78
79
|
when :optarg
|
|
79
|
-
|
|
80
|
+
'?'
|
|
80
81
|
when :kwarg
|
|
81
82
|
"#{name}:"
|
|
82
83
|
when :kwoptarg
|
|
83
84
|
"?#{name}:"
|
|
84
85
|
when :restarg
|
|
85
|
-
|
|
86
|
+
'*'
|
|
86
87
|
when :kwrestarg
|
|
87
|
-
|
|
88
|
+
'**'
|
|
88
89
|
else
|
|
89
90
|
"(unknown decl: #{decl})"
|
|
90
91
|
end
|
|
@@ -112,11 +113,11 @@ module Solargraph
|
|
|
112
113
|
end
|
|
113
114
|
|
|
114
115
|
def rest?
|
|
115
|
-
|
|
116
|
+
%i[restarg kwrestarg].include?(decl)
|
|
116
117
|
end
|
|
117
118
|
|
|
118
119
|
def block?
|
|
119
|
-
[
|
|
120
|
+
%i[block blockarg].include?(decl)
|
|
120
121
|
end
|
|
121
122
|
|
|
122
123
|
def to_rbs
|
|
@@ -177,14 +178,15 @@ module Solargraph
|
|
|
177
178
|
if @return_type.nil?
|
|
178
179
|
@return_type = ComplexType::UNDEFINED
|
|
179
180
|
found = param_tag
|
|
180
|
-
@return_type = ComplexType.try_parse(*found.types) unless found.nil?
|
|
181
|
+
@return_type = ComplexType.try_parse(*found.types) unless found.nil? || found.types.nil?
|
|
181
182
|
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
182
183
|
if @return_type.undefined?
|
|
183
|
-
|
|
184
|
+
case decl
|
|
185
|
+
when :restarg
|
|
184
186
|
@return_type = ComplexType.try_parse('::Array')
|
|
185
|
-
|
|
187
|
+
when :kwrestarg
|
|
186
188
|
@return_type = ComplexType.try_parse('::Hash')
|
|
187
|
-
|
|
189
|
+
when :blockarg
|
|
188
190
|
@return_type = ComplexType.try_parse('::Proc')
|
|
189
191
|
end
|
|
190
192
|
end
|
|
@@ -217,7 +219,7 @@ module Solargraph
|
|
|
217
219
|
|
|
218
220
|
# @param atype [ComplexType]
|
|
219
221
|
# @param api_map [ApiMap]
|
|
220
|
-
def compatible_arg?
|
|
222
|
+
def compatible_arg? atype, api_map
|
|
221
223
|
# make sure we get types from up the method
|
|
222
224
|
# inheritance chain if we don't have them on this pin
|
|
223
225
|
ptype = typify api_map
|
|
@@ -226,7 +228,7 @@ module Solargraph
|
|
|
226
228
|
return true if atype.conforms_to?(api_map,
|
|
227
229
|
ptype,
|
|
228
230
|
:method_call,
|
|
229
|
-
[
|
|
231
|
+
%i[allow_empty_params allow_undefined])
|
|
230
232
|
ptype.generic?
|
|
231
233
|
end
|
|
232
234
|
|
|
@@ -259,9 +261,7 @@ module Solargraph
|
|
|
259
261
|
# @return [ComplexType]
|
|
260
262
|
def typify_block_param api_map
|
|
261
263
|
block_pin = closure
|
|
262
|
-
if block_pin.is_a?(Pin::Block) && block_pin.receiver && index
|
|
263
|
-
return block_pin.typify_parameters(api_map)[index]
|
|
264
|
-
end
|
|
264
|
+
return block_pin.typify_parameters(api_map)[index] if block_pin.is_a?(Pin::Block) && block_pin.receiver && index
|
|
265
265
|
ComplexType::UNDEFINED
|
|
266
266
|
end
|
|
267
267
|
|
|
@@ -279,11 +279,14 @@ module Solargraph
|
|
|
279
279
|
found = p
|
|
280
280
|
break
|
|
281
281
|
end
|
|
282
|
-
if found.nil?
|
|
283
|
-
found = params[index]
|
|
282
|
+
if found.nil? && !index.nil? && params[index] && (params[index].name.nil? || params[index].name.empty?)
|
|
283
|
+
found = params[index]
|
|
284
|
+
end
|
|
285
|
+
unless found.nil? || found.types.nil?
|
|
286
|
+
return ComplexType.try_parse(*found.types).qualify(api_map,
|
|
287
|
+
# @sg-ignore Need to add nil check here
|
|
288
|
+
*meth.closure.gates)
|
|
284
289
|
end
|
|
285
|
-
# @sg-ignore Need to add nil check here
|
|
286
|
-
return ComplexType.try_parse(*found.types).qualify(api_map, *meth.closure.gates) unless found.nil? || found.types.nil?
|
|
287
290
|
end
|
|
288
291
|
ComplexType::UNDEFINED
|
|
289
292
|
end
|
|
@@ -326,8 +329,6 @@ module Solargraph
|
|
|
326
329
|
pins.each do |pin|
|
|
327
330
|
params = pin.docstring.tags(:param)
|
|
328
331
|
return params unless params.empty?
|
|
329
|
-
end
|
|
330
|
-
pins.each do |pin|
|
|
331
332
|
params = see_reference(pin.docstring, api_map, skip)
|
|
332
333
|
return params unless params.empty?
|
|
333
334
|
end
|
|
@@ -7,6 +7,7 @@ module Solargraph
|
|
|
7
7
|
# @param gates [Array<String>, nil] Namespaces to try while resolving non-rooted types
|
|
8
8
|
# @param binder [ComplexType, ComplexType::UniqueType, nil]
|
|
9
9
|
# @param gates [Array<String>, nil]
|
|
10
|
+
# @param [Hash{Symbol => Object}] splat
|
|
10
11
|
def initialize return_type: ComplexType::UNDEFINED, binder: nil, gates: nil, **splat
|
|
11
12
|
super(**splat)
|
|
12
13
|
@gates = gates
|
|
@@ -22,6 +23,7 @@ module Solargraph
|
|
|
22
23
|
# @param closure [Pin::Namespace, nil] Used as the closure for this pin
|
|
23
24
|
# @param binder [ComplexType, ComplexType::UniqueType, nil]
|
|
24
25
|
# @return [ProxyType]
|
|
26
|
+
# @param [Hash{Symbol => Object}] kwargs
|
|
25
27
|
def self.anonymous context, closure: nil, binder: nil, **kwargs
|
|
26
28
|
unless closure
|
|
27
29
|
parts = context.namespace.split('::')
|
|
@@ -12,7 +12,24 @@ module Solargraph
|
|
|
12
12
|
|
|
13
13
|
attr_reader :generic_values
|
|
14
14
|
|
|
15
|
+
# A Reference is a pin that associates a type with another type.
|
|
16
|
+
# The existing type is marked as the closure. The name of the
|
|
17
|
+
# type we're associating with it is the 'name' field, and
|
|
18
|
+
# subtypes are in the 'generic_values' field.
|
|
19
|
+
#
|
|
20
|
+
# These pins are a little different - the name is a rooted name,
|
|
21
|
+
# which may be relative or absolute, preceded with ::, not a
|
|
22
|
+
# fully qualified namespace, which is implicitly in the root
|
|
23
|
+
# namespace and is never preceded by ::.
|
|
24
|
+
#
|
|
25
|
+
# @todo can the above be represented in a less subtle way?
|
|
26
|
+
# @todo consider refactoring so that we can replicate more
|
|
27
|
+
# complex types like Hash{String => Integer} and has both key
|
|
28
|
+
# types and subtypes.
|
|
29
|
+
#
|
|
30
|
+
# @param name [String] rooted name of the referenced type
|
|
15
31
|
# @param generic_values [Array<String>]
|
|
32
|
+
# @param [Hash{Symbol => Object}] splat
|
|
16
33
|
def initialize generic_values: [], **splat
|
|
17
34
|
super(**splat)
|
|
18
35
|
@generic_values = generic_values
|
|
@@ -46,7 +46,7 @@ module Solargraph
|
|
|
46
46
|
# @param b [self]
|
|
47
47
|
# @sg-ignore https://github.com/castwide/solargraph/pull/1050
|
|
48
48
|
.sort { |a, b| b.match <=> a.match }
|
|
49
|
-
|
|
49
|
+
.map(&:pin)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
# @param str1 [String]
|
|
@@ -54,7 +54,7 @@ module Solargraph
|
|
|
54
54
|
#
|
|
55
55
|
# @return [Float]
|
|
56
56
|
def fuzzy_string_match str1, str2
|
|
57
|
-
return 1.0 + (str2.length.to_f / str1.length
|
|
57
|
+
return 1.0 + (str2.length.to_f / str1.length) if str1.downcase.include?(str2.downcase)
|
|
58
58
|
JaroWinkler.similarity(str1, str2, ignore_case: true)
|
|
59
59
|
end
|
|
60
60
|
end
|