solargraph 0.56.0 → 0.58.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/.gitattributes +2 -0
- data/.github/workflows/linting.yml +127 -0
- data/.github/workflows/plugins.yml +183 -7
- data/.github/workflows/rspec.yml +55 -5
- data/.github/workflows/typecheck.yml +6 -3
- data/.gitignore +5 -0
- data/.overcommit.yml +72 -0
- data/.rspec +1 -0
- data/.rubocop.yml +66 -0
- data/.rubocop_todo.yml +1279 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +86 -1
- data/README.md +8 -4
- data/Rakefile +125 -13
- data/bin/solargraph +3 -0
- data/lib/solargraph/api_map/cache.rb +3 -2
- data/lib/solargraph/api_map/constants.rb +279 -0
- data/lib/solargraph/api_map/index.rb +49 -31
- data/lib/solargraph/api_map/source_to_yard.rb +13 -4
- data/lib/solargraph/api_map/store.rb +144 -26
- data/lib/solargraph/api_map.rb +217 -245
- data/lib/solargraph/bench.rb +1 -0
- data/lib/solargraph/complex_type/type_methods.rb +6 -0
- data/lib/solargraph/complex_type/unique_type.rb +19 -12
- data/lib/solargraph/complex_type.rb +24 -3
- data/lib/solargraph/convention/active_support_concern.rb +111 -0
- data/lib/solargraph/convention/base.rb +17 -0
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -0
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +91 -0
- data/lib/solargraph/convention/data_definition.rb +105 -0
- data/lib/solargraph/convention/gemspec.rb +3 -2
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +2 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +4 -2
- data/lib/solargraph/convention/struct_definition.rb +87 -24
- data/lib/solargraph/convention.rb +32 -2
- data/lib/solargraph/diagnostics/rubocop.rb +6 -1
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +5 -3
- data/lib/solargraph/doc_map.rb +52 -18
- data/lib/solargraph/environ.rb +9 -2
- data/lib/solargraph/equality.rb +1 -0
- data/lib/solargraph/gem_pins.rb +21 -11
- data/lib/solargraph/language_server/host/dispatch.rb +2 -0
- data/lib/solargraph/language_server/host/message_worker.rb +3 -0
- data/lib/solargraph/language_server/host.rb +12 -5
- data/lib/solargraph/language_server/message/base.rb +2 -1
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +1 -1
- data/lib/solargraph/language_server/message/text_document/definition.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/formatting.rb +19 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +1 -0
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +2 -0
- data/lib/solargraph/language_server/progress.rb +8 -0
- data/lib/solargraph/language_server/request.rb +4 -1
- data/lib/solargraph/library.rb +50 -33
- data/lib/solargraph/location.rb +3 -0
- data/lib/solargraph/logging.rb +11 -2
- data/lib/solargraph/page.rb +3 -0
- data/lib/solargraph/parser/comment_ripper.rb +8 -1
- data/lib/solargraph/parser/flow_sensitive_typing.rb +33 -5
- data/lib/solargraph/parser/node_processor/base.rb +10 -5
- data/lib/solargraph/parser/node_processor.rb +24 -8
- data/lib/solargraph/parser/parser_gem/class_methods.rb +3 -13
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_methods.rb +5 -16
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +3 -2
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +1 -21
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +2 -0
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +7 -1
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +0 -22
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +65 -8
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +12 -3
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +36 -16
- data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors.rb +4 -0
- data/lib/solargraph/parser/region.rb +3 -0
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/pin/base.rb +92 -14
- data/lib/solargraph/pin/base_variable.rb +6 -5
- data/lib/solargraph/pin/block.rb +3 -2
- data/lib/solargraph/pin/callable.rb +14 -1
- data/lib/solargraph/pin/closure.rb +5 -7
- data/lib/solargraph/pin/common.rb +6 -2
- data/lib/solargraph/pin/constant.rb +2 -0
- data/lib/solargraph/pin/local_variable.rb +1 -2
- data/lib/solargraph/pin/method.rb +32 -11
- data/lib/solargraph/pin/method_alias.rb +3 -0
- data/lib/solargraph/pin/parameter.rb +24 -10
- data/lib/solargraph/pin/proxy_type.rb +5 -1
- data/lib/solargraph/pin/reference/override.rb +15 -1
- data/lib/solargraph/pin/reference/superclass.rb +5 -0
- data/lib/solargraph/pin/reference.rb +17 -0
- data/lib/solargraph/pin/search.rb +6 -1
- data/lib/solargraph/pin/signature.rb +2 -0
- data/lib/solargraph/pin/symbol.rb +5 -0
- data/lib/solargraph/pin_cache.rb +64 -4
- data/lib/solargraph/position.rb +3 -0
- data/lib/solargraph/range.rb +5 -0
- data/lib/solargraph/rbs_map/conversions.rb +68 -18
- data/lib/solargraph/rbs_map/core_fills.rb +18 -0
- data/lib/solargraph/rbs_map/core_map.rb +14 -7
- data/lib/solargraph/rbs_map.rb +14 -1
- data/lib/solargraph/shell.rb +85 -1
- data/lib/solargraph/source/chain/call.rb +7 -3
- data/lib/solargraph/source/chain/constant.rb +3 -66
- data/lib/solargraph/source/chain/if.rb +1 -1
- data/lib/solargraph/source/chain/link.rb +11 -2
- data/lib/solargraph/source/chain/or.rb +1 -1
- data/lib/solargraph/source/chain.rb +11 -2
- data/lib/solargraph/source/change.rb +2 -2
- data/lib/solargraph/source/cursor.rb +2 -3
- data/lib/solargraph/source/encoding_fixes.rb +23 -23
- data/lib/solargraph/source/source_chainer.rb +1 -1
- data/lib/solargraph/source.rb +6 -3
- data/lib/solargraph/source_map/clip.rb +18 -26
- data/lib/solargraph/source_map/data.rb +4 -0
- data/lib/solargraph/source_map/mapper.rb +2 -2
- data/lib/solargraph/source_map.rb +28 -16
- data/lib/solargraph/type_checker/param_def.rb +2 -0
- data/lib/solargraph/type_checker/rules.rb +30 -8
- data/lib/solargraph/type_checker.rb +301 -186
- data/lib/solargraph/version.rb +5 -5
- data/lib/solargraph/workspace/config.rb +22 -6
- data/lib/solargraph/workspace/require_paths.rb +97 -0
- data/lib/solargraph/workspace.rb +38 -67
- data/lib/solargraph/yard_map/helpers.rb +29 -1
- data/lib/solargraph/yard_map/mapper/to_constant.rb +5 -5
- data/lib/solargraph/yard_map/mapper/to_method.rb +5 -9
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +8 -7
- data/lib/solargraph/yard_map/to_method.rb +2 -1
- data/lib/solargraph/yardoc.rb +41 -3
- data/lib/solargraph.rb +15 -0
- data/rbs/fills/bundler/0/bundler.rbs +4271 -0
- data/rbs/fills/open3/0/open3.rbs +172 -0
- data/rbs/fills/rubygems/0/basic_specification.rbs +326 -0
- data/rbs/fills/rubygems/0/errors.rbs +364 -0
- data/rbs/fills/rubygems/0/spec_fetcher.rbs +107 -0
- data/rbs/fills/rubygems/0/specification.rbs +1753 -0
- data/rbs/fills/{tuple.rbs → tuple/tuple.rbs} +2 -3
- data/rbs_collection.yaml +4 -4
- data/sig/shims/ast/0/node.rbs +5 -0
- data/sig/shims/ast/2.4/.rbs_meta.yaml +9 -0
- data/sig/shims/ast/2.4/ast.rbs +73 -0
- data/sig/shims/parser/3.2.0.1/builders/default.rbs +195 -0
- data/sig/shims/parser/3.2.0.1/manifest.yaml +7 -0
- data/sig/shims/parser/3.2.0.1/parser.rbs +201 -0
- data/sig/shims/parser/3.2.0.1/polyfill.rbs +4 -0
- data/sig/shims/thor/1.2.0.1/.rbs_meta.yaml +9 -0
- data/sig/shims/thor/1.2.0.1/manifest.yaml +7 -0
- data/sig/shims/thor/1.2.0.1/thor.rbs +17 -0
- data/solargraph.gemspec +26 -5
- metadata +187 -15
- data/lib/.rubocop.yml +0 -22
- data/lib/solargraph/parser/node_methods.rb +0 -97
|
@@ -23,8 +23,10 @@ module Solargraph
|
|
|
23
23
|
|
|
24
24
|
# @param source [Source]
|
|
25
25
|
# @param namespace [String]
|
|
26
|
+
# @param closure [Pin::Closure, nil]
|
|
26
27
|
# @param scope [Symbol, nil]
|
|
27
28
|
# @param visibility [Symbol]
|
|
29
|
+
# @param lvars [Array<Symbol>]
|
|
28
30
|
def initialize source: Solargraph::Source.load_string(''), closure: nil,
|
|
29
31
|
scope: nil, visibility: :public, lvars: []
|
|
30
32
|
@source = source
|
|
@@ -45,6 +47,7 @@ module Solargraph
|
|
|
45
47
|
# @param closure [Pin::Closure, nil]
|
|
46
48
|
# @param scope [Symbol, nil]
|
|
47
49
|
# @param visibility [Symbol, nil]
|
|
50
|
+
# @param lvars [Array<Symbol>, nil]
|
|
48
51
|
# @return [Region]
|
|
49
52
|
def update closure: nil, scope: nil, visibility: nil, lvars: nil
|
|
50
53
|
Region.new(
|
data/lib/solargraph/pin/base.rb
CHANGED
|
@@ -13,10 +13,10 @@ module Solargraph
|
|
|
13
13
|
# @return [YARD::CodeObjects::Base]
|
|
14
14
|
attr_reader :code_object
|
|
15
15
|
|
|
16
|
-
# @return [Solargraph::Location]
|
|
16
|
+
# @return [Solargraph::Location, nil]
|
|
17
17
|
attr_reader :location
|
|
18
18
|
|
|
19
|
-
# @return [Solargraph::Location]
|
|
19
|
+
# @return [Solargraph::Location, nil]
|
|
20
20
|
attr_reader :type_location
|
|
21
21
|
|
|
22
22
|
# @return [String]
|
|
@@ -28,6 +28,11 @@ module Solargraph
|
|
|
28
28
|
# @return [::Symbol]
|
|
29
29
|
attr_accessor :source
|
|
30
30
|
|
|
31
|
+
# @type [::Numeric, nil] A priority for determining if pins should be combined or not
|
|
32
|
+
# A nil priority is considered the be the lowest. All code, yard & rbs pins have nil priority
|
|
33
|
+
# Between 2 pins, the one with the higher priority gets chosen. If the priorities are equal, they are combined.
|
|
34
|
+
attr_reader :combine_priority
|
|
35
|
+
|
|
31
36
|
def presence_certain?
|
|
32
37
|
true
|
|
33
38
|
end
|
|
@@ -40,7 +45,8 @@ module Solargraph
|
|
|
40
45
|
# @param source [Symbol, nil]
|
|
41
46
|
# @param docstring [YARD::Docstring, nil]
|
|
42
47
|
# @param directives [::Array<YARD::Tags::Directive>, nil]
|
|
43
|
-
|
|
48
|
+
# @param combine_priority [::Numeric, nil] See attr_reader for combine_priority
|
|
49
|
+
def initialize location: nil, type_location: nil, closure: nil, source: nil, name: '', comments: '', docstring: nil, directives: nil, combine_priority: nil
|
|
44
50
|
@location = location
|
|
45
51
|
@type_location = type_location
|
|
46
52
|
@closure = closure
|
|
@@ -50,15 +56,35 @@ module Solargraph
|
|
|
50
56
|
@identity = nil
|
|
51
57
|
@docstring = docstring
|
|
52
58
|
@directives = directives
|
|
59
|
+
@combine_priority = combine_priority
|
|
60
|
+
|
|
53
61
|
assert_source_provided
|
|
62
|
+
assert_location_provided
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# @return [void]
|
|
66
|
+
def assert_location_provided
|
|
67
|
+
return unless best_location.nil? && %i[yardoc source rbs].include?(source)
|
|
68
|
+
|
|
69
|
+
Solargraph.assert_or_log(:best_location, "Neither location nor type_location provided - #{path} #{source} #{self.class}")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# @return [Pin::Closure, nil]
|
|
73
|
+
def closure
|
|
74
|
+
Solargraph.assert_or_log(:closure, "Closure not set on #{self.class} #{name.inspect} from #{source.inspect}") unless @closure
|
|
75
|
+
# @type [Pin::Closure, nil]
|
|
76
|
+
@closure
|
|
54
77
|
end
|
|
55
78
|
|
|
56
79
|
# @param other [self]
|
|
57
|
-
# @param attrs [Hash{Symbol => Object}]
|
|
80
|
+
# @param attrs [Hash{::Symbol => Object}]
|
|
58
81
|
#
|
|
59
82
|
# @return [self]
|
|
60
83
|
def combine_with(other, attrs={})
|
|
61
84
|
raise "tried to combine #{other.class} with #{self.class}" unless other.class == self.class
|
|
85
|
+
priority_choice = choose_priority(other)
|
|
86
|
+
return priority_choice unless priority_choice.nil?
|
|
87
|
+
|
|
62
88
|
type_location = choose(other, :type_location)
|
|
63
89
|
location = choose(other, :location)
|
|
64
90
|
combined_name = combine_name(other)
|
|
@@ -71,6 +97,7 @@ module Solargraph
|
|
|
71
97
|
source: :combined,
|
|
72
98
|
docstring: choose(other, :docstring),
|
|
73
99
|
directives: combine_directives(other),
|
|
100
|
+
combine_priority: combine_priority
|
|
74
101
|
}.merge(attrs)
|
|
75
102
|
assert_same_macros(other)
|
|
76
103
|
logger.debug { "Base#combine_with(path=#{path}) - other.comments=#{other.comments.inspect}, self.comments = #{self.comments}" }
|
|
@@ -79,6 +106,25 @@ module Solargraph
|
|
|
79
106
|
out
|
|
80
107
|
end
|
|
81
108
|
|
|
109
|
+
# @param other [self]
|
|
110
|
+
# @return [self, nil] Returns either the pin chosen based on priority or nil
|
|
111
|
+
# A nil return means that the combination process must proceed
|
|
112
|
+
def choose_priority(other)
|
|
113
|
+
if combine_priority.nil? && !other.combine_priority.nil?
|
|
114
|
+
return other
|
|
115
|
+
elsif other.combine_priority.nil? && !combine_priority.nil?
|
|
116
|
+
return self
|
|
117
|
+
elsif !combine_priority.nil? && !other.combine_priority.nil?
|
|
118
|
+
if combine_priority > other.combine_priority
|
|
119
|
+
return self
|
|
120
|
+
elsif combine_priority < other.combine_priority
|
|
121
|
+
return other
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
nil
|
|
126
|
+
end
|
|
127
|
+
|
|
82
128
|
# @param other [self]
|
|
83
129
|
# @param attr [::Symbol]
|
|
84
130
|
# @sg-ignore
|
|
@@ -90,7 +136,6 @@ module Solargraph
|
|
|
90
136
|
val2 = other.send(attr)
|
|
91
137
|
return val1 if val1 == val2
|
|
92
138
|
return val2 if val1.nil?
|
|
93
|
-
# @sg-ignore
|
|
94
139
|
val1.length > val2.length ? val1 : val2
|
|
95
140
|
end
|
|
96
141
|
|
|
@@ -150,9 +195,9 @@ module Solargraph
|
|
|
150
195
|
return_type
|
|
151
196
|
else
|
|
152
197
|
all_items = return_type.items + other.return_type.items
|
|
153
|
-
if all_items.any? { |item| item.selfy? } && all_items.any? { |item| item.rooted_tag == context.rooted_tag }
|
|
198
|
+
if all_items.any? { |item| item.selfy? } && all_items.any? { |item| item.rooted_tag == context.reduce_class_type.rooted_tag }
|
|
154
199
|
# assume this was a declaration that should have said 'self'
|
|
155
|
-
all_items.delete_if { |item| item.rooted_tag == context.rooted_tag }
|
|
200
|
+
all_items.delete_if { |item| item.rooted_tag == context.reduce_class_type.rooted_tag }
|
|
156
201
|
end
|
|
157
202
|
ComplexType.new(all_items)
|
|
158
203
|
end
|
|
@@ -180,7 +225,7 @@ module Solargraph
|
|
|
180
225
|
end
|
|
181
226
|
|
|
182
227
|
# @param other [self]
|
|
183
|
-
# @param attr [Symbol]
|
|
228
|
+
# @param attr [::Symbol]
|
|
184
229
|
# @sg-ignore
|
|
185
230
|
# @return [undefined]
|
|
186
231
|
def choose_node(other, attr)
|
|
@@ -214,6 +259,7 @@ module Solargraph
|
|
|
214
259
|
def assert_same_macros(other)
|
|
215
260
|
return unless self.source == :yardoc && other.source == :yardoc
|
|
216
261
|
assert_same_count(other, :macros)
|
|
262
|
+
# @param [YARD::Tags::MacroDirective]
|
|
217
263
|
assert_same_array_content(other, :macros) { |macro| macro.tag.name }
|
|
218
264
|
end
|
|
219
265
|
|
|
@@ -229,7 +275,6 @@ module Solargraph
|
|
|
229
275
|
raise "Expected #{attr} on #{other} to be an Enumerable, got #{arr2.class}" unless arr2.is_a?(::Enumerable)
|
|
230
276
|
# @type arr2 [::Enumerable]
|
|
231
277
|
|
|
232
|
-
# @sg-ignore
|
|
233
278
|
# @type [undefined]
|
|
234
279
|
values1 = arr1.map(&block)
|
|
235
280
|
# @type [undefined]
|
|
@@ -261,7 +306,8 @@ module Solargraph
|
|
|
261
306
|
# @param other [self]
|
|
262
307
|
# @param attr [::Symbol]
|
|
263
308
|
#
|
|
264
|
-
# @
|
|
309
|
+
# @sg-ignore
|
|
310
|
+
# @return [undefined]
|
|
265
311
|
def assert_same(other, attr)
|
|
266
312
|
return false if other.nil?
|
|
267
313
|
val1 = send(attr)
|
|
@@ -290,20 +336,36 @@ module Solargraph
|
|
|
290
336
|
choose_pin_attr(other, attr)
|
|
291
337
|
end
|
|
292
338
|
|
|
339
|
+
# @param other [self]
|
|
340
|
+
# @param attr [::Symbol]
|
|
341
|
+
#
|
|
342
|
+
# @sg-ignore Missing @return tag for Solargraph::Pin::Base#choose_pin_attr
|
|
343
|
+
# @return [undefined]
|
|
293
344
|
def choose_pin_attr(other, attr)
|
|
294
345
|
# @type [Pin::Base, nil]
|
|
295
346
|
val1 = send(attr)
|
|
296
347
|
# @type [Pin::Base, nil]
|
|
297
348
|
val2 = other.send(attr)
|
|
298
349
|
if val1.class != val2.class
|
|
350
|
+
# :nocov:
|
|
299
351
|
Solargraph.assert_or_log("combine_with_#{attr}_class".to_sym,
|
|
300
352
|
"Inconsistent #{attr.inspect} class values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
301
353
|
return val1
|
|
354
|
+
# :nocov:
|
|
302
355
|
end
|
|
303
356
|
# arbitrary way of choosing a pin
|
|
304
|
-
[val1, val2].compact.
|
|
357
|
+
[val1, val2].compact.max_by do |closure|
|
|
358
|
+
[
|
|
359
|
+
# maximize number of gates, as types in other combined pins may
|
|
360
|
+
# depend on those gates
|
|
361
|
+
closure.gates.length,
|
|
362
|
+
# use basename so that results don't vary system to system
|
|
363
|
+
File.basename(closure.best_location.to_s)
|
|
364
|
+
]
|
|
365
|
+
end
|
|
305
366
|
end
|
|
306
367
|
|
|
368
|
+
# @return [void]
|
|
307
369
|
def assert_source_provided
|
|
308
370
|
Solargraph.assert_or_log(:source, "source not provided - #{@path} #{@source} #{self.class}") if source.nil?
|
|
309
371
|
end
|
|
@@ -402,9 +464,10 @@ module Solargraph
|
|
|
402
464
|
# Pin equality is determined using the #nearly? method and also
|
|
403
465
|
# requiring both pins to have the same location.
|
|
404
466
|
#
|
|
405
|
-
# @param other [
|
|
467
|
+
# @param other [Object]
|
|
406
468
|
def == other
|
|
407
469
|
return false unless nearly? other
|
|
470
|
+
# @sg-ignore Should add more explicit type check on other
|
|
408
471
|
comments == other.comments && location == other.location
|
|
409
472
|
end
|
|
410
473
|
|
|
@@ -459,7 +522,7 @@ module Solargraph
|
|
|
459
522
|
# @param api_map [ApiMap]
|
|
460
523
|
# @return [ComplexType]
|
|
461
524
|
def typify api_map
|
|
462
|
-
return_type.qualify(api_map,
|
|
525
|
+
return_type.qualify(api_map, *(closure&.gates || ['']))
|
|
463
526
|
end
|
|
464
527
|
|
|
465
528
|
# Infer the pin's return type via static code analysis.
|
|
@@ -520,12 +583,24 @@ module Solargraph
|
|
|
520
583
|
@identity ||= "#{closure&.path}|#{name}|#{location}"
|
|
521
584
|
end
|
|
522
585
|
|
|
586
|
+
# The namespaces available for resolving the current namespace. Each gate
|
|
587
|
+
# should be a fully qualified namespace or the root namespace (i.e., an
|
|
588
|
+
# empty string.)
|
|
589
|
+
#
|
|
590
|
+
# Example: Given the name 'Bar' and the gates ['Foo', ''],
|
|
591
|
+
# the fully qualified namespace should be 'Foo::Bar' or 'Bar'.
|
|
592
|
+
#
|
|
593
|
+
# @return [Array<String>]
|
|
594
|
+
def gates
|
|
595
|
+
@gates ||= closure&.gates || ['']
|
|
596
|
+
end
|
|
597
|
+
|
|
523
598
|
# @return [String, nil]
|
|
524
599
|
def to_rbs
|
|
525
600
|
return_type.to_rbs
|
|
526
601
|
end
|
|
527
602
|
|
|
528
|
-
# @return [String]
|
|
603
|
+
# @return [String, nil]
|
|
529
604
|
def type_desc
|
|
530
605
|
rbs = to_rbs
|
|
531
606
|
# RBS doesn't have a way to represent a Class<x> type
|
|
@@ -548,6 +623,7 @@ module Solargraph
|
|
|
548
623
|
"name=#{name.inspect} return_type=#{type_desc}, context=#{context.rooted_tags}, closure=#{closure_info}, binder=#{binder_info}"
|
|
549
624
|
end
|
|
550
625
|
|
|
626
|
+
# @return [String]
|
|
551
627
|
def desc
|
|
552
628
|
"[#{inner_desc}]"
|
|
553
629
|
end
|
|
@@ -557,6 +633,7 @@ module Solargraph
|
|
|
557
633
|
"#<#{self.class} `#{self.inner_desc}`#{all_location_text} via #{source.inspect}>"
|
|
558
634
|
end
|
|
559
635
|
|
|
636
|
+
# @return [String]
|
|
560
637
|
def all_location_text
|
|
561
638
|
if location.nil? && type_location.nil?
|
|
562
639
|
''
|
|
@@ -569,6 +646,7 @@ module Solargraph
|
|
|
569
646
|
end
|
|
570
647
|
end
|
|
571
648
|
|
|
649
|
+
# @return [void]
|
|
572
650
|
def reset_generated!
|
|
573
651
|
end
|
|
574
652
|
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
module Solargraph
|
|
4
4
|
module Pin
|
|
5
5
|
class BaseVariable < Base
|
|
6
|
-
include Solargraph::Parser::NodeMethods
|
|
7
6
|
# include Solargraph::Source::NodeMethods
|
|
7
|
+
include Solargraph::Parser::NodeMethods
|
|
8
8
|
|
|
9
9
|
# @return [Parser::AST::Node, nil]
|
|
10
10
|
attr_reader :assignment
|
|
@@ -12,8 +12,9 @@ module Solargraph
|
|
|
12
12
|
attr_accessor :mass_assignment
|
|
13
13
|
|
|
14
14
|
# @param return_type [ComplexType, nil]
|
|
15
|
+
# @param mass_assignment [::Array(Parser::AST::Node, Integer), nil]
|
|
15
16
|
# @param assignment [Parser::AST::Node, nil]
|
|
16
|
-
def initialize assignment: nil, return_type: nil, **splat
|
|
17
|
+
def initialize assignment: nil, return_type: nil, mass_assignment: nil, **splat
|
|
17
18
|
super(**splat)
|
|
18
19
|
@assignment = assignment
|
|
19
20
|
# @type [nil, ::Array(Parser::AST::Node, Integer)]
|
|
@@ -22,12 +23,12 @@ module Solargraph
|
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def combine_with(other, attrs={})
|
|
25
|
-
attrs.merge({
|
|
26
|
+
new_attrs = attrs.merge({
|
|
26
27
|
assignment: assert_same(other, :assignment),
|
|
27
28
|
mass_assignment: assert_same(other, :mass_assignment),
|
|
28
29
|
return_type: combine_return_type(other),
|
|
29
30
|
})
|
|
30
|
-
super(other,
|
|
31
|
+
super(other, new_attrs)
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
def completion_item_kind
|
|
@@ -43,7 +44,6 @@ module Solargraph
|
|
|
43
44
|
@return_type ||= generate_complex_type
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
# @sg-ignore
|
|
47
47
|
def nil_assignment?
|
|
48
48
|
# this will always be false - should it be return_type ==
|
|
49
49
|
# ComplexType::NIL or somesuch?
|
|
@@ -105,6 +105,7 @@ module Solargraph
|
|
|
105
105
|
# @param other [Object]
|
|
106
106
|
def == other
|
|
107
107
|
return false unless super
|
|
108
|
+
# @sg-ignore Should add type check on other
|
|
108
109
|
assignment == other.assignment
|
|
109
110
|
end
|
|
110
111
|
|
data/lib/solargraph/pin/block.rb
CHANGED
|
@@ -54,6 +54,7 @@ module Solargraph
|
|
|
54
54
|
locals = clip.locals - [self]
|
|
55
55
|
meths = chain.define(api_map, closure, locals)
|
|
56
56
|
# @todo Convert logic to use signatures
|
|
57
|
+
# @param meth [Pin::Method]
|
|
57
58
|
meths.each do |meth|
|
|
58
59
|
next if meth.block.nil?
|
|
59
60
|
|
|
@@ -69,7 +70,7 @@ module Solargraph
|
|
|
69
70
|
namespace_pin = api_map.get_namespace_pins(meth.namespace, closure.namespace).first
|
|
70
71
|
arg_type.resolve_generics(namespace_pin, param_type)
|
|
71
72
|
else
|
|
72
|
-
arg_type.self_to_type(chain.base.infer(api_map, self, locals)).qualify(api_map, meth.
|
|
73
|
+
arg_type.self_to_type(chain.base.infer(api_map, self, locals)).qualify(api_map, *meth.gates)
|
|
73
74
|
end
|
|
74
75
|
end
|
|
75
76
|
end
|
|
@@ -96,7 +97,7 @@ module Solargraph
|
|
|
96
97
|
target = chain.base.infer(api_map, receiver_pin, locals)
|
|
97
98
|
target = full_context unless target.defined?
|
|
98
99
|
|
|
99
|
-
ComplexType.try_parse(*types).qualify(api_map, receiver_pin.
|
|
100
|
+
ComplexType.try_parse(*types).qualify(api_map, *receiver_pin.gates).self_to_type(target)
|
|
100
101
|
end
|
|
101
102
|
end
|
|
102
103
|
end
|
|
@@ -21,16 +21,21 @@ module Solargraph
|
|
|
21
21
|
@parameters = parameters
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
# @return [String]
|
|
24
25
|
def method_namespace
|
|
25
26
|
closure.namespace
|
|
26
27
|
end
|
|
27
28
|
|
|
29
|
+
# @param other [self]
|
|
30
|
+
#
|
|
31
|
+
# @return [Pin::Signature, nil]
|
|
28
32
|
def combine_blocks(other)
|
|
29
33
|
if block.nil?
|
|
30
34
|
other.block
|
|
31
35
|
elsif other.block.nil?
|
|
32
36
|
block
|
|
33
37
|
else
|
|
38
|
+
# @type [Pin::Signature, nil]
|
|
34
39
|
choose_pin_attr(other, :block)
|
|
35
40
|
end
|
|
36
41
|
end
|
|
@@ -57,8 +62,13 @@ module Solargraph
|
|
|
57
62
|
[]
|
|
58
63
|
end
|
|
59
64
|
|
|
65
|
+
# @param other [self]
|
|
66
|
+
#
|
|
67
|
+
# @return [Array<Pin::Parameter>]
|
|
60
68
|
def choose_parameters(other)
|
|
61
69
|
raise "Trying to combine two pins with different arities - \nself =#{inspect}, \nother=#{other.inspect}, \n\n self.arity=#{self.arity}, \nother.arity=#{other.arity}" if other.arity != arity
|
|
70
|
+
# @param param [Pin::Parameter]
|
|
71
|
+
# @param other_param [Pin::Parameter]
|
|
62
72
|
parameters.zip(other.parameters).map do |param, other_param|
|
|
63
73
|
if param.nil? && other_param.block?
|
|
64
74
|
other_param
|
|
@@ -70,6 +80,7 @@ module Solargraph
|
|
|
70
80
|
end
|
|
71
81
|
end
|
|
72
82
|
|
|
83
|
+
# @return [Array<Pin::Parameter>]
|
|
73
84
|
def blockless_parameters
|
|
74
85
|
if parameters.last&.block?
|
|
75
86
|
parameters[0..-2]
|
|
@@ -78,6 +89,7 @@ module Solargraph
|
|
|
78
89
|
end
|
|
79
90
|
end
|
|
80
91
|
|
|
92
|
+
# @return [Array]
|
|
81
93
|
def arity
|
|
82
94
|
[generics, blockless_parameters.map(&:arity_decl), block&.arity]
|
|
83
95
|
end
|
|
@@ -125,6 +137,7 @@ module Solargraph
|
|
|
125
137
|
end
|
|
126
138
|
end
|
|
127
139
|
|
|
140
|
+
# @return [String]
|
|
128
141
|
def method_name
|
|
129
142
|
raise "closure was nil in #{self.inspect}" if closure.nil?
|
|
130
143
|
@method_name ||= closure.name
|
|
@@ -197,11 +210,11 @@ module Solargraph
|
|
|
197
210
|
true
|
|
198
211
|
end
|
|
199
212
|
|
|
213
|
+
# @return [Integer]
|
|
200
214
|
def mandatory_positional_param_count
|
|
201
215
|
parameters.count(&:arg?)
|
|
202
216
|
end
|
|
203
217
|
|
|
204
|
-
# @return [String]
|
|
205
218
|
def to_rbs
|
|
206
219
|
rbs_generics + '(' + parameters.map { |param| param.to_rbs }.join(', ') + ') ' + (block.nil? ? '' : '{ ' + block.to_rbs + ' } ') + '-> ' + return_type.to_rbs
|
|
207
220
|
end
|
|
@@ -8,6 +8,7 @@ module Solargraph
|
|
|
8
8
|
|
|
9
9
|
# @param scope [::Symbol] :class or :instance
|
|
10
10
|
# @param generics [::Array<Pin::Parameter>, nil]
|
|
11
|
+
# @param generic_defaults [Hash{String => ComplexType}]
|
|
11
12
|
def initialize scope: :class, generics: nil, generic_defaults: {}, **splat
|
|
12
13
|
super(**splat)
|
|
13
14
|
@scope = scope
|
|
@@ -15,6 +16,7 @@ module Solargraph
|
|
|
15
16
|
@generic_defaults = generic_defaults
|
|
16
17
|
end
|
|
17
18
|
|
|
19
|
+
# @return [Hash{String => ComplexType}]
|
|
18
20
|
def generic_defaults
|
|
19
21
|
@generic_defaults ||= {}
|
|
20
22
|
end
|
|
@@ -46,19 +48,15 @@ module Solargraph
|
|
|
46
48
|
@binder || context
|
|
47
49
|
end
|
|
48
50
|
|
|
49
|
-
# @
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
# root pin
|
|
53
|
-
closure ? closure.gates : ['']
|
|
54
|
-
end
|
|
51
|
+
# @param api_map [Solargraph::ApiMap]
|
|
52
|
+
# @return [void]
|
|
53
|
+
def rebind api_map; end
|
|
55
54
|
|
|
56
55
|
# @return [::Array<String>]
|
|
57
56
|
def generics
|
|
58
57
|
@generics ||= docstring.tags(:generic).map(&:name)
|
|
59
58
|
end
|
|
60
59
|
|
|
61
|
-
# @return [String]
|
|
62
60
|
def to_rbs
|
|
63
61
|
rbs_generics + return_type.to_rbs
|
|
64
62
|
end
|
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
module Solargraph
|
|
4
4
|
module Pin
|
|
5
5
|
module Common
|
|
6
|
+
# @!method source
|
|
7
|
+
# @abstract
|
|
8
|
+
# @return [Source, nil]
|
|
9
|
+
# @type @closure [Pin::Closure, nil]
|
|
10
|
+
|
|
6
11
|
# @return [Location]
|
|
7
12
|
attr_reader :location
|
|
8
13
|
|
|
14
|
+
# @sg-ignore Solargraph::Pin::Common#closure return type could not be inferred
|
|
9
15
|
# @return [Pin::Closure, nil]
|
|
10
|
-
attr_reader :closure
|
|
11
|
-
|
|
12
16
|
def closure
|
|
13
17
|
Solargraph.assert_or_log(:closure, "Closure not set on #{self.class} #{name.inspect} from #{source.inspect}") unless @closure
|
|
14
18
|
@closure
|
|
@@ -5,6 +5,8 @@ module Solargraph
|
|
|
5
5
|
class Constant < BaseVariable
|
|
6
6
|
attr_reader :visibility
|
|
7
7
|
|
|
8
|
+
# @param visibility [::Symbol] The visibility of the constant (:public, :protected, or :private)
|
|
9
|
+
# @param splat [Hash] Additional options supported by superclasses
|
|
8
10
|
def initialize visibility: :public, **splat
|
|
9
11
|
super(**splat)
|
|
10
12
|
@visibility = visibility
|
|
@@ -26,7 +26,7 @@ module Solargraph
|
|
|
26
26
|
assignment: assert_same(other, :assignment),
|
|
27
27
|
presence_certain: assert_same(other, :presence_certain?),
|
|
28
28
|
}.merge(attrs)
|
|
29
|
-
new_attrs[:presence] =
|
|
29
|
+
new_attrs[:presence] = assert_same(other, :presence) unless attrs.key?(:presence)
|
|
30
30
|
|
|
31
31
|
super(other, new_attrs)
|
|
32
32
|
end
|
|
@@ -39,7 +39,6 @@ module Solargraph
|
|
|
39
39
|
match_named_closure(other_closure, closure)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
# @return [String]
|
|
43
42
|
def to_rbs
|
|
44
43
|
(name || '(anon)') + ' ' + (return_type&.to_rbs || 'untyped')
|
|
45
44
|
end
|
|
@@ -17,12 +17,13 @@ module Solargraph
|
|
|
17
17
|
|
|
18
18
|
# @param visibility [::Symbol] :public, :protected, or :private
|
|
19
19
|
# @param explicit [Boolean]
|
|
20
|
-
# @param block [Pin::Signature, nil,
|
|
20
|
+
# @param block [Pin::Signature, nil, :undefined]
|
|
21
21
|
# @param node [Parser::AST::Node, nil]
|
|
22
22
|
# @param attribute [Boolean]
|
|
23
23
|
# @param signatures [::Array<Signature>, nil]
|
|
24
24
|
# @param anon_splat [Boolean]
|
|
25
|
-
def initialize visibility: :public, explicit: true, block: :undefined, node: nil, attribute: false, signatures: nil, anon_splat: false,
|
|
25
|
+
def initialize visibility: :public, explicit: true, block: :undefined, node: nil, attribute: false, signatures: nil, anon_splat: false,
|
|
26
|
+
**splat
|
|
26
27
|
super(**splat)
|
|
27
28
|
@visibility = visibility
|
|
28
29
|
@explicit = explicit
|
|
@@ -33,14 +34,18 @@ module Solargraph
|
|
|
33
34
|
@anon_splat = anon_splat
|
|
34
35
|
end
|
|
35
36
|
|
|
37
|
+
# @param signature_pins [Array<Pin::Signature>]
|
|
36
38
|
# @return [Array<Pin::Signature>]
|
|
37
39
|
def combine_all_signature_pins(*signature_pins)
|
|
40
|
+
# @type [Hash{Array => Array<Pin::Signature>}]
|
|
38
41
|
by_arity = {}
|
|
39
42
|
signature_pins.each do |signature_pin|
|
|
40
43
|
by_arity[signature_pin.arity] ||= []
|
|
41
44
|
by_arity[signature_pin.arity] << signature_pin
|
|
42
45
|
end
|
|
43
46
|
by_arity.transform_values! do |same_arity_pins|
|
|
47
|
+
# @param memo [Pin::Signature, nil]
|
|
48
|
+
# @param signature [Pin::Signature]
|
|
44
49
|
same_arity_pins.reduce(nil) do |memo, signature|
|
|
45
50
|
next signature if memo.nil?
|
|
46
51
|
memo.combine_with(signature)
|
|
@@ -50,7 +55,7 @@ module Solargraph
|
|
|
50
55
|
end
|
|
51
56
|
|
|
52
57
|
# @param other [Pin::Method]
|
|
53
|
-
# @return [Symbol]
|
|
58
|
+
# @return [::Symbol]
|
|
54
59
|
def combine_visibility(other)
|
|
55
60
|
if dodgy_visibility_source? && !other.dodgy_visibility_source?
|
|
56
61
|
other.visibility
|
|
@@ -76,6 +81,9 @@ module Solargraph
|
|
|
76
81
|
end
|
|
77
82
|
|
|
78
83
|
def combine_with(other, attrs = {})
|
|
84
|
+
priority_choice = choose_priority(other)
|
|
85
|
+
return priority_choice unless priority_choice.nil?
|
|
86
|
+
|
|
79
87
|
sigs = combine_signatures(other)
|
|
80
88
|
parameters = if sigs.length > 0
|
|
81
89
|
[].freeze
|
|
@@ -84,6 +92,7 @@ module Solargraph
|
|
|
84
92
|
end
|
|
85
93
|
new_attrs = {
|
|
86
94
|
visibility: combine_visibility(other),
|
|
95
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1050
|
|
87
96
|
explicit: explicit? || other.explicit?,
|
|
88
97
|
block: combine_blocks(other),
|
|
89
98
|
node: choose_node(other, :node),
|
|
@@ -199,9 +208,11 @@ module Solargraph
|
|
|
199
208
|
)
|
|
200
209
|
end
|
|
201
210
|
yield_return_type = ComplexType.try_parse(*yieldreturn_tags.flat_map(&:types))
|
|
202
|
-
block = Signature.new(generics: generics, parameters: yield_parameters, return_type: yield_return_type, source: source,
|
|
211
|
+
block = Signature.new(generics: generics, parameters: yield_parameters, return_type: yield_return_type, source: source,
|
|
212
|
+
closure: self, location: location, type_location: type_location)
|
|
203
213
|
end
|
|
204
|
-
signature = Signature.new(generics: generics, parameters: parameters, return_type: return_type, block: block, closure: self, source: source
|
|
214
|
+
signature = Signature.new(generics: generics, parameters: parameters, return_type: return_type, block: block, closure: self, source: source,
|
|
215
|
+
location: location, type_location: type_location)
|
|
205
216
|
block.closure = signature if block
|
|
206
217
|
signature
|
|
207
218
|
end
|
|
@@ -292,14 +303,13 @@ module Solargraph
|
|
|
292
303
|
type = see_reference(api_map) || typify_from_super(api_map)
|
|
293
304
|
logger.debug { "Method#typify(self=#{self}) - type=#{type&.rooted_tags.inspect}" }
|
|
294
305
|
unless type.nil?
|
|
295
|
-
qualified = type.qualify(api_map,
|
|
306
|
+
qualified = type.qualify(api_map, *closure.gates)
|
|
296
307
|
logger.debug { "Method#typify(self=#{self}) => #{qualified.rooted_tags.inspect}" }
|
|
297
308
|
return qualified
|
|
298
309
|
end
|
|
299
310
|
super
|
|
300
311
|
end
|
|
301
312
|
|
|
302
|
-
# @sg-ignore
|
|
303
313
|
def documentation
|
|
304
314
|
if @documentation.nil?
|
|
305
315
|
method_docs ||= super || ''
|
|
@@ -371,11 +381,14 @@ module Solargraph
|
|
|
371
381
|
@attribute
|
|
372
382
|
end
|
|
373
383
|
|
|
374
|
-
# @parm other [
|
|
384
|
+
# @parm other [self]
|
|
375
385
|
def nearly? other
|
|
376
386
|
super &&
|
|
387
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1050
|
|
377
388
|
parameters == other.parameters &&
|
|
389
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1050
|
|
378
390
|
scope == other.scope &&
|
|
391
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1050
|
|
379
392
|
visibility == other.visibility
|
|
380
393
|
end
|
|
381
394
|
|
|
@@ -387,9 +400,12 @@ module Solargraph
|
|
|
387
400
|
def overloads
|
|
388
401
|
# Ignore overload tags with nil parameters. If it's not an array, the
|
|
389
402
|
# tag's source is likely malformed.
|
|
403
|
+
|
|
404
|
+
# @param tag [YARD::Tags::OverloadTag]
|
|
390
405
|
@overloads ||= docstring.tags(:overload).select(&:parameters).map do |tag|
|
|
391
406
|
Pin::Signature.new(
|
|
392
407
|
generics: generics,
|
|
408
|
+
# @param src [Array(String, String)]
|
|
393
409
|
parameters: tag.parameters.map do |src|
|
|
394
410
|
name, decl = parse_overload_param(src.first)
|
|
395
411
|
Pin::Parameter.new(
|
|
@@ -423,7 +439,7 @@ module Solargraph
|
|
|
423
439
|
@resolved_ref_tag = true
|
|
424
440
|
return self unless docstring.ref_tags.any?
|
|
425
441
|
docstring.ref_tags.each do |tag|
|
|
426
|
-
ref = if tag.owner.to_s.start_with?(/[
|
|
442
|
+
ref = if tag.owner.to_s.start_with?(/[#.]/)
|
|
427
443
|
api_map.get_methods(namespace)
|
|
428
444
|
.select { |pin| pin.path.end_with?(tag.owner.to_s) }
|
|
429
445
|
.first
|
|
@@ -502,6 +518,7 @@ module Solargraph
|
|
|
502
518
|
#
|
|
503
519
|
# @return [ComplexType]
|
|
504
520
|
def param_type_from_name(tag, name)
|
|
521
|
+
# @param t [YARD::Tags::Tag]
|
|
505
522
|
param = tag.tags(:param).select { |t| t.name == name }.first
|
|
506
523
|
return ComplexType::UNDEFINED unless param
|
|
507
524
|
ComplexType.try_parse(*param.types)
|
|
@@ -517,8 +534,12 @@ module Solargraph
|
|
|
517
534
|
# @param api_map [ApiMap]
|
|
518
535
|
# @return [ComplexType, nil]
|
|
519
536
|
def see_reference api_map
|
|
537
|
+
# This should actually be an intersection type
|
|
538
|
+
# @param ref [YARD::Tags::Tag, Solargraph::Yard::Tags::RefTag]
|
|
520
539
|
docstring.ref_tags.each do |ref|
|
|
540
|
+
# @sg-ignore ref should actually be an intersection type
|
|
521
541
|
next unless ref.tag_name == 'return' && ref.owner
|
|
542
|
+
# @sg-ignore ref should actually be an intersection type
|
|
522
543
|
result = resolve_reference(ref.owner.to_s, api_map)
|
|
523
544
|
return result unless result.nil?
|
|
524
545
|
end
|
|
@@ -547,11 +568,11 @@ module Solargraph
|
|
|
547
568
|
# @param api_map [ApiMap]
|
|
548
569
|
# @return [ComplexType, nil]
|
|
549
570
|
def resolve_reference ref, api_map
|
|
550
|
-
parts = ref.split(/[
|
|
571
|
+
parts = ref.split(/[.#]/)
|
|
551
572
|
if parts.first.empty? || parts.one?
|
|
552
573
|
path = "#{namespace}#{ref}"
|
|
553
574
|
else
|
|
554
|
-
fqns = api_map.qualify(parts.first,
|
|
575
|
+
fqns = api_map.qualify(parts.first, *gates)
|
|
555
576
|
return ComplexType::UNDEFINED if fqns.nil?
|
|
556
577
|
path = fqns + ref[parts.first.length] + parts.last
|
|
557
578
|
end
|