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
data/lib/solargraph/pin/base.rb
CHANGED
|
@@ -46,7 +46,8 @@ module Solargraph
|
|
|
46
46
|
# @param docstring [YARD::Docstring, nil]
|
|
47
47
|
# @param directives [::Array<YARD::Tags::Directive>, nil]
|
|
48
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: '',
|
|
49
|
+
def initialize location: nil, type_location: nil, closure: nil, source: nil, name: '', comments: '',
|
|
50
|
+
docstring: nil, directives: nil, combine_priority: nil
|
|
50
51
|
@location = location
|
|
51
52
|
@type_location = type_location
|
|
52
53
|
@closure = closure
|
|
@@ -60,7 +61,6 @@ module Solargraph
|
|
|
60
61
|
# @type [ComplexType, ComplexType::UniqueType, nil]
|
|
61
62
|
@binder = nil
|
|
62
63
|
|
|
63
|
-
|
|
64
64
|
assert_source_provided
|
|
65
65
|
assert_location_provided
|
|
66
66
|
end
|
|
@@ -69,12 +69,16 @@ module Solargraph
|
|
|
69
69
|
def assert_location_provided
|
|
70
70
|
return unless best_location.nil? && %i[yardoc source rbs].include?(source)
|
|
71
71
|
|
|
72
|
-
Solargraph.assert_or_log(:best_location,
|
|
72
|
+
Solargraph.assert_or_log(:best_location,
|
|
73
|
+
"Neither location nor type_location provided - #{path} #{source} #{self.class}")
|
|
73
74
|
end
|
|
74
75
|
|
|
75
76
|
# @return [Pin::Closure, nil]
|
|
76
77
|
def closure
|
|
77
|
-
|
|
78
|
+
unless @closure
|
|
79
|
+
Solargraph.assert_or_log(:closure,
|
|
80
|
+
"Closure not set on #{self.class} #{name.inspect} from #{source.inspect}")
|
|
81
|
+
end
|
|
78
82
|
@closure
|
|
79
83
|
end
|
|
80
84
|
|
|
@@ -82,7 +86,7 @@ module Solargraph
|
|
|
82
86
|
# @param attrs [Hash{::Symbol => Object}]
|
|
83
87
|
#
|
|
84
88
|
# @return [self]
|
|
85
|
-
def combine_with
|
|
89
|
+
def combine_with other, attrs = {}
|
|
86
90
|
priority_choice = choose_priority(other)
|
|
87
91
|
return priority_choice unless priority_choice.nil?
|
|
88
92
|
|
|
@@ -101,7 +105,9 @@ module Solargraph
|
|
|
101
105
|
combine_priority: combine_priority
|
|
102
106
|
}.merge(attrs)
|
|
103
107
|
assert_same_macros(other)
|
|
104
|
-
logger.debug
|
|
108
|
+
logger.debug do
|
|
109
|
+
"Base#combine_with(path=#{path}) - other.comments=#{other.comments.inspect}, self.comments = #{comments}"
|
|
110
|
+
end
|
|
105
111
|
out = self.class.new(**new_attrs)
|
|
106
112
|
out.reset_generated!
|
|
107
113
|
out
|
|
@@ -110,7 +116,7 @@ module Solargraph
|
|
|
110
116
|
# @param other [self]
|
|
111
117
|
# @return [self, nil] Returns either the pin chosen based on priority or nil
|
|
112
118
|
# A nil return means that the combination process must proceed
|
|
113
|
-
def choose_priority
|
|
119
|
+
def choose_priority other
|
|
114
120
|
if combine_priority.nil? && !other.combine_priority.nil?
|
|
115
121
|
return other
|
|
116
122
|
elsif other.combine_priority.nil? && !combine_priority.nil?
|
|
@@ -130,7 +136,7 @@ module Solargraph
|
|
|
130
136
|
# @param attr [::Symbol]
|
|
131
137
|
# @sg-ignore
|
|
132
138
|
# @return [undefined]
|
|
133
|
-
def choose_longer
|
|
139
|
+
def choose_longer other, attr
|
|
134
140
|
# @type [undefined]
|
|
135
141
|
val1 = send(attr)
|
|
136
142
|
# @type [undefined]
|
|
@@ -143,22 +149,22 @@ module Solargraph
|
|
|
143
149
|
# @param other [self]
|
|
144
150
|
#
|
|
145
151
|
# @return [::Array<YARD::Tags::Directive>, nil]
|
|
146
|
-
def combine_directives
|
|
147
|
-
return
|
|
152
|
+
def combine_directives other
|
|
153
|
+
return directives if other.directives.empty?
|
|
148
154
|
return other.directives if directives.empty?
|
|
149
155
|
(directives + other.directives).uniq
|
|
150
156
|
end
|
|
151
157
|
|
|
152
158
|
# @param other [self]
|
|
153
159
|
# @return [Pin::Closure, nil]
|
|
154
|
-
def combine_closure
|
|
160
|
+
def combine_closure other
|
|
155
161
|
choose_pin_attr_with_same_name(other, :closure)
|
|
156
162
|
end
|
|
157
163
|
|
|
158
164
|
# @param other [self]
|
|
159
165
|
# @sg-ignore @type should override probed type
|
|
160
166
|
# @return [String]
|
|
161
|
-
def combine_name
|
|
167
|
+
def combine_name other
|
|
162
168
|
if needs_consistent_name? || other.needs_consistent_name?
|
|
163
169
|
assert_same(other, :name)
|
|
164
170
|
else
|
|
@@ -189,14 +195,9 @@ module Solargraph
|
|
|
189
195
|
true
|
|
190
196
|
end
|
|
191
197
|
|
|
192
|
-
# @sg-ignore def should infer as symbol - "Not enough arguments to Module#protected"
|
|
193
|
-
protected def equality_fields
|
|
194
|
-
[name, location, type_location, closure, source]
|
|
195
|
-
end
|
|
196
|
-
|
|
197
198
|
# @param other [self]
|
|
198
199
|
# @return [ComplexType]
|
|
199
|
-
def combine_return_type
|
|
200
|
+
def combine_return_type other
|
|
200
201
|
if return_type.undefined?
|
|
201
202
|
other.return_type
|
|
202
203
|
elsif other.return_type.undefined?
|
|
@@ -211,7 +212,9 @@ module Solargraph
|
|
|
211
212
|
return_type
|
|
212
213
|
else
|
|
213
214
|
all_items = return_type.items + other.return_type.items
|
|
214
|
-
if all_items.any?
|
|
215
|
+
if all_items.any?(&:selfy?) && all_items.any? do |item|
|
|
216
|
+
item.rooted_tag == context.reduce_class_type.rooted_tag
|
|
217
|
+
end
|
|
215
218
|
# assume this was a declaration that should have said 'self'
|
|
216
219
|
all_items.delete_if { |item| item.rooted_tag == context.reduce_class_type.rooted_tag }
|
|
217
220
|
end
|
|
@@ -234,14 +237,17 @@ module Solargraph
|
|
|
234
237
|
#
|
|
235
238
|
# @sg-ignore
|
|
236
239
|
# @return [undefined, nil]
|
|
237
|
-
def choose
|
|
240
|
+
def choose other, attr
|
|
238
241
|
results = [self, other].map(&attr).compact
|
|
239
242
|
# true and false are different classes and can't be sorted
|
|
240
|
-
|
|
243
|
+
|
|
244
|
+
# @sg-ignore Wrong argument type for Array#include?: object
|
|
245
|
+
# expected Boolean, received Proc
|
|
246
|
+
return true if results.any? { |r| [true, false].include?(r) }
|
|
241
247
|
return results.first if results.any? { |r| r.is_a? AST::Node }
|
|
242
248
|
results.min
|
|
243
|
-
rescue
|
|
244
|
-
|
|
249
|
+
rescue StandardError
|
|
250
|
+
warn("Problem handling #{attr} for \n#{inspect}\n and \n#{other.inspect}\n\n#{send(attr).inspect} vs #{other.send(attr).inspect}")
|
|
245
251
|
raise
|
|
246
252
|
end
|
|
247
253
|
|
|
@@ -249,7 +255,7 @@ module Solargraph
|
|
|
249
255
|
# @param attr [::Symbol]
|
|
250
256
|
# @sg-ignore
|
|
251
257
|
# @return [undefined]
|
|
252
|
-
def choose_node
|
|
258
|
+
def choose_node other, attr
|
|
253
259
|
if other.object_id < attr.object_id
|
|
254
260
|
other.send(attr)
|
|
255
261
|
else
|
|
@@ -261,9 +267,9 @@ module Solargraph
|
|
|
261
267
|
# @param attr [::Symbol]
|
|
262
268
|
# @sg-ignore
|
|
263
269
|
# @return [undefined]
|
|
264
|
-
def prefer_rbs_location
|
|
270
|
+
def prefer_rbs_location other, attr
|
|
265
271
|
if rbs_location? && !other.rbs_location?
|
|
266
|
-
|
|
272
|
+
send(attr)
|
|
267
273
|
elsif !rbs_location? && other.rbs_location?
|
|
268
274
|
other.send(attr)
|
|
269
275
|
else
|
|
@@ -278,8 +284,8 @@ module Solargraph
|
|
|
278
284
|
|
|
279
285
|
# @param other [self]
|
|
280
286
|
# @return [void]
|
|
281
|
-
def assert_same_macros
|
|
282
|
-
return unless
|
|
287
|
+
def assert_same_macros other
|
|
288
|
+
return unless source == :yardoc && other.source == :yardoc
|
|
283
289
|
assert_same_count(other, :macros)
|
|
284
290
|
# @param [YARD::Tags::MacroDirective]
|
|
285
291
|
assert_same_array_content(other, :macros) { |macro| macro.tag.name }
|
|
@@ -289,7 +295,7 @@ module Solargraph
|
|
|
289
295
|
# @param attr [::Symbol]
|
|
290
296
|
# @return [void]
|
|
291
297
|
# @todo strong typechecking should complain when there are no block-related tags
|
|
292
|
-
def assert_same_array_content
|
|
298
|
+
def assert_same_array_content other, attr, &block
|
|
293
299
|
arr1 = send(attr)
|
|
294
300
|
raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
|
|
295
301
|
# @type arr1 [::Enumerable]
|
|
@@ -303,7 +309,7 @@ module Solargraph
|
|
|
303
309
|
values2 = arr2.map(&block)
|
|
304
310
|
# @sg-ignore
|
|
305
311
|
return arr1 if values1 == values2
|
|
306
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
312
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
307
313
|
"Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self values = #{values1}\nother values =#{attr} = #{values2}")
|
|
308
314
|
arr1
|
|
309
315
|
end
|
|
@@ -312,15 +318,15 @@ module Solargraph
|
|
|
312
318
|
# @param attr [::Symbol]
|
|
313
319
|
#
|
|
314
320
|
# @return [::Enumerable]
|
|
315
|
-
def assert_same_count
|
|
321
|
+
def assert_same_count other, attr
|
|
316
322
|
# @type [::Enumerable]
|
|
317
|
-
arr1 =
|
|
323
|
+
arr1 = send(attr)
|
|
318
324
|
raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
|
|
319
325
|
# @type [::Enumerable]
|
|
320
326
|
arr2 = other.send(attr)
|
|
321
327
|
raise "Expected #{attr} on #{other} to be an Enumerable, got #{arr2.class}" unless arr2.is_a?(::Enumerable)
|
|
322
328
|
return arr1 if arr1.count == arr2.count
|
|
323
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
329
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
324
330
|
"Inconsistent #{attr.inspect} count value between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{arr1.inspect}\nother.#{attr} = #{arr2.inspect}")
|
|
325
331
|
arr1
|
|
326
332
|
end
|
|
@@ -330,16 +336,16 @@ module Solargraph
|
|
|
330
336
|
#
|
|
331
337
|
# @sg-ignore
|
|
332
338
|
# @return [undefined]
|
|
333
|
-
def assert_same
|
|
339
|
+
def assert_same other, attr
|
|
334
340
|
if other.nil?
|
|
335
|
-
Solargraph.assert_or_log("combine_with_#{attr}_nil"
|
|
341
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_nil",
|
|
336
342
|
"Other was passed in nil in assert_same on #{self}")
|
|
337
343
|
return send(attr)
|
|
338
344
|
end
|
|
339
345
|
val1 = send(attr)
|
|
340
346
|
val2 = other.send(attr)
|
|
341
347
|
return val1 if val1 == val2
|
|
342
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
348
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
343
349
|
"Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
344
350
|
val1
|
|
345
351
|
end
|
|
@@ -348,15 +354,17 @@ module Solargraph
|
|
|
348
354
|
# @param attr [::Symbol]
|
|
349
355
|
# @sg-ignore
|
|
350
356
|
# @return [undefined]
|
|
351
|
-
def choose_pin_attr_with_same_name
|
|
357
|
+
def choose_pin_attr_with_same_name other, attr
|
|
352
358
|
# @type [Pin::Base, nil]
|
|
353
359
|
val1 = send(attr)
|
|
354
360
|
# @type [Pin::Base, nil]
|
|
355
361
|
val2 = other.send(attr)
|
|
356
|
-
raise "Expected pin for #{attr} on\n#{
|
|
357
|
-
|
|
362
|
+
raise "Expected pin for #{attr} on\n#{inspect},\ngot #{val1.inspect}" unless val1.nil? || val1.is_a?(Pin::Base)
|
|
363
|
+
unless val2.nil? || val2.is_a?(Pin::Base)
|
|
364
|
+
raise "Expected pin for #{attr} on\n#{other.inspect},\ngot #{val2.inspect}"
|
|
365
|
+
end
|
|
358
366
|
if val1&.name != val2&.name
|
|
359
|
-
Solargraph.assert_or_log("combine_with_#{attr}_name"
|
|
367
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_name",
|
|
360
368
|
"Inconsistent #{attr.inspect} name values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
361
369
|
end
|
|
362
370
|
choose_pin_attr(other, attr)
|
|
@@ -367,14 +375,14 @@ module Solargraph
|
|
|
367
375
|
#
|
|
368
376
|
# @sg-ignore Missing @return tag for Solargraph::Pin::Base#choose_pin_attr
|
|
369
377
|
# @return [undefined]
|
|
370
|
-
def choose_pin_attr
|
|
378
|
+
def choose_pin_attr other, attr
|
|
371
379
|
# @type [Pin::Base, nil]
|
|
372
380
|
val1 = send(attr)
|
|
373
381
|
# @type [Pin::Base, nil]
|
|
374
382
|
val2 = other.send(attr)
|
|
375
383
|
if val1.class != val2.class
|
|
376
384
|
# :nocov:
|
|
377
|
-
Solargraph.assert_or_log("combine_with_#{attr}_class"
|
|
385
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_class",
|
|
378
386
|
"Inconsistent #{attr.inspect} class values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
379
387
|
return val1
|
|
380
388
|
# :nocov:
|
|
@@ -406,10 +414,9 @@ module Solargraph
|
|
|
406
414
|
|
|
407
415
|
# @param generics_to_resolve [Enumerable<String>]
|
|
408
416
|
# @param return_type_context [ComplexType, ComplexType::UniqueType, nil]
|
|
409
|
-
# @param context [ComplexType]
|
|
410
417
|
# @param resolved_generic_values [Hash{String => ComplexType}]
|
|
411
418
|
# @return [self]
|
|
412
|
-
def resolve_generics_from_context
|
|
419
|
+
def resolve_generics_from_context generics_to_resolve, return_type_context = nil, resolved_generic_values: {}
|
|
413
420
|
proxy return_type.resolve_generics_from_context(generics_to_resolve,
|
|
414
421
|
return_type_context,
|
|
415
422
|
resolved_generic_values: resolved_generic_values)
|
|
@@ -418,7 +425,7 @@ module Solargraph
|
|
|
418
425
|
# @yieldparam [ComplexType]
|
|
419
426
|
# @yieldreturn [ComplexType]
|
|
420
427
|
# @return [self]
|
|
421
|
-
def transform_types
|
|
428
|
+
def transform_types &transform
|
|
422
429
|
proxy return_type.transform(&transform)
|
|
423
430
|
end
|
|
424
431
|
|
|
@@ -430,7 +437,7 @@ module Solargraph
|
|
|
430
437
|
# @param context_type [ComplexType] The receiver type
|
|
431
438
|
# @return [self]
|
|
432
439
|
def resolve_generics definitions, context_type
|
|
433
|
-
transform_types { |t| t
|
|
440
|
+
transform_types { |t| t&.resolve_generics(definitions, context_type) }
|
|
434
441
|
end
|
|
435
442
|
|
|
436
443
|
def all_rooted?
|
|
@@ -439,7 +446,7 @@ module Solargraph
|
|
|
439
446
|
|
|
440
447
|
# @param generics_to_erase [::Array<String>]
|
|
441
448
|
# @return [self]
|
|
442
|
-
def erase_generics
|
|
449
|
+
def erase_generics generics_to_erase
|
|
443
450
|
return self if generics_to_erase.empty?
|
|
444
451
|
transform_types { |t| t.erase_generics(generics_to_erase) }
|
|
445
452
|
end
|
|
@@ -482,15 +489,18 @@ module Solargraph
|
|
|
482
489
|
# @param other [Solargraph::Pin::Base, Object]
|
|
483
490
|
# @return [Boolean]
|
|
484
491
|
def nearly? other
|
|
485
|
-
|
|
492
|
+
instance_of?(other.class) &&
|
|
486
493
|
# @sg-ignore Translate to something flow sensitive typing understands
|
|
487
494
|
name == other.name &&
|
|
488
495
|
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
489
496
|
(closure == other.closure || (closure && closure.nearly?(other.closure))) &&
|
|
490
497
|
# @sg-ignore Translate to something flow sensitive typing understands
|
|
491
498
|
(comments == other.comments ||
|
|
492
|
-
|
|
493
|
-
|
|
499
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
500
|
+
(((maybe_directives? == false && other.maybe_directives? == false) ||
|
|
501
|
+
compare_directives(directives,
|
|
502
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
503
|
+
other.directives)) &&
|
|
494
504
|
# @sg-ignore Translate to something flow sensitive typing understands
|
|
495
505
|
compare_docstring_tags(docstring, other.docstring))
|
|
496
506
|
)
|
|
@@ -573,7 +583,8 @@ module Solargraph
|
|
|
573
583
|
# @param api_map [ApiMap]
|
|
574
584
|
# @return [ComplexType, ComplexType::UniqueType]
|
|
575
585
|
def infer api_map
|
|
576
|
-
Solargraph.assert_or_log(:pin_infer,
|
|
586
|
+
Solargraph.assert_or_log(:pin_infer,
|
|
587
|
+
'WARNING: Pin #infer methods are deprecated. Use #typify or #probe instead.')
|
|
577
588
|
type = typify(api_map)
|
|
578
589
|
return type unless type.undefined?
|
|
579
590
|
probe api_map
|
|
@@ -643,7 +654,7 @@ module Solargraph
|
|
|
643
654
|
rbs = return_type.rooted_tags if return_type.name == 'Class'
|
|
644
655
|
if path
|
|
645
656
|
if rbs
|
|
646
|
-
path
|
|
657
|
+
"#{path} #{rbs}"
|
|
647
658
|
else
|
|
648
659
|
path
|
|
649
660
|
end
|
|
@@ -666,7 +677,7 @@ module Solargraph
|
|
|
666
677
|
|
|
667
678
|
# @return [String]
|
|
668
679
|
def inspect
|
|
669
|
-
"#<#{self.class} `#{
|
|
680
|
+
"#<#{self.class} `#{inner_desc}`#{all_location_text} via #{source.inspect}>"
|
|
670
681
|
end
|
|
671
682
|
|
|
672
683
|
# @return [String]
|
|
@@ -684,6 +695,11 @@ module Solargraph
|
|
|
684
695
|
|
|
685
696
|
protected
|
|
686
697
|
|
|
698
|
+
# @sg-ignore def should infer as symbol - "Not enough arguments to Module#protected"
|
|
699
|
+
def equality_fields
|
|
700
|
+
[name, location, type_location, closure, source]
|
|
701
|
+
end
|
|
702
|
+
|
|
687
703
|
# @return [Boolean]
|
|
688
704
|
attr_writer :probed
|
|
689
705
|
|
|
@@ -693,9 +709,7 @@ module Solargraph
|
|
|
693
709
|
# @return [ComplexType, ComplexType::UniqueType, nil]
|
|
694
710
|
attr_writer :return_type
|
|
695
711
|
|
|
696
|
-
attr_writer :docstring
|
|
697
|
-
|
|
698
|
-
attr_writer :directives
|
|
712
|
+
attr_writer :docstring, :directives
|
|
699
713
|
|
|
700
714
|
private
|
|
701
715
|
|
|
@@ -717,13 +731,13 @@ module Solargraph
|
|
|
717
731
|
# True if two docstrings have the same tags, regardless of any other
|
|
718
732
|
# differences.
|
|
719
733
|
#
|
|
720
|
-
# @param
|
|
721
|
-
# @param
|
|
734
|
+
# @param docstring1 [YARD::Docstring]
|
|
735
|
+
# @param docstring2 [YARD::Docstring]
|
|
722
736
|
# @return [Boolean]
|
|
723
|
-
def compare_docstring_tags
|
|
724
|
-
return false if
|
|
725
|
-
|
|
726
|
-
return false unless compare_tags(
|
|
737
|
+
def compare_docstring_tags docstring1, docstring2
|
|
738
|
+
return false if docstring1.tags.length != docstring2.tags.length
|
|
739
|
+
docstring1.tags.each_index do |i|
|
|
740
|
+
return false unless compare_tags(docstring1.tags[i], docstring2.tags[i])
|
|
727
741
|
end
|
|
728
742
|
true
|
|
729
743
|
end
|
|
@@ -743,7 +757,7 @@ module Solargraph
|
|
|
743
757
|
# @param tag2 [YARD::Tags::Tag]
|
|
744
758
|
# @return [Boolean]
|
|
745
759
|
def compare_tags tag1, tag2
|
|
746
|
-
tag1.
|
|
760
|
+
tag1.instance_of?(tag2.class) &&
|
|
747
761
|
tag1.tag_name == tag2.tag_name &&
|
|
748
762
|
tag1.text == tag2.text &&
|
|
749
763
|
tag1.name == tag2.name &&
|
|
@@ -754,7 +768,7 @@ module Solargraph
|
|
|
754
768
|
def collect_macros
|
|
755
769
|
return [] unless maybe_directives?
|
|
756
770
|
parse = Solargraph::Source.parse_docstring(comments)
|
|
757
|
-
parse.directives.select{ |d| d.tag.tag_name == 'macro' }
|
|
771
|
+
parse.directives.select { |d| d.tag.tag_name == 'macro' }
|
|
758
772
|
end
|
|
759
773
|
end
|
|
760
774
|
end
|
|
@@ -45,9 +45,9 @@ module Solargraph
|
|
|
45
45
|
# @see https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types
|
|
46
46
|
# @see https://en.wikipedia.org/wiki/Intersection_type#TypeScript_example
|
|
47
47
|
# @param presence [Range, nil]
|
|
48
|
-
# @param
|
|
48
|
+
# @param [Hash{Symbol => Object}] splat
|
|
49
49
|
def initialize assignment: nil, assignments: [], mass_assignment: nil,
|
|
50
|
-
presence: nil,
|
|
50
|
+
presence: nil, return_type: nil,
|
|
51
51
|
intersection_return_type: nil, exclude_return_type: nil,
|
|
52
52
|
**splat
|
|
53
53
|
super(**splat)
|
|
@@ -58,7 +58,6 @@ module Solargraph
|
|
|
58
58
|
@intersection_return_type = intersection_return_type
|
|
59
59
|
@exclude_return_type = exclude_return_type
|
|
60
60
|
@presence = presence
|
|
61
|
-
@presence_certain = presence_certain
|
|
62
61
|
end
|
|
63
62
|
|
|
64
63
|
# @param presence [Range]
|
|
@@ -83,44 +82,33 @@ module Solargraph
|
|
|
83
82
|
super
|
|
84
83
|
end
|
|
85
84
|
|
|
86
|
-
def combine_with
|
|
85
|
+
def combine_with other, attrs = {}
|
|
87
86
|
new_assignments = combine_assignments(other)
|
|
88
87
|
new_attrs = attrs.merge({
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
})
|
|
88
|
+
# default values don't exist in RBS parameters; it just
|
|
89
|
+
# tells you if the arg is optional or not. Prefer a
|
|
90
|
+
# provided value if we have one here since we can't rely on
|
|
91
|
+
# it from RBS so we can infer from it and typecheck on it.
|
|
92
|
+
assignment: choose(other, :assignment),
|
|
93
|
+
assignments: new_assignments,
|
|
94
|
+
mass_assignment: combine_mass_assignment(other),
|
|
95
|
+
return_type: combine_return_type(other),
|
|
96
|
+
intersection_return_type: combine_types(other, :intersection_return_type),
|
|
97
|
+
exclude_return_type: combine_types(other, :exclude_return_type),
|
|
98
|
+
presence: combine_presence(other)
|
|
99
|
+
})
|
|
102
100
|
super(other, new_attrs)
|
|
103
101
|
end
|
|
104
102
|
|
|
105
103
|
# @param other [self]
|
|
106
104
|
#
|
|
107
105
|
# @return [Array(AST::Node, Integer), nil]
|
|
108
|
-
def combine_mass_assignment
|
|
106
|
+
def combine_mass_assignment other
|
|
109
107
|
# @todo pick first non-nil arbitrarily - we don't yet support
|
|
110
108
|
# mass assignment merging
|
|
111
109
|
mass_assignment || other.mass_assignment
|
|
112
110
|
end
|
|
113
111
|
|
|
114
|
-
# If a certain pin is being combined with an uncertain pin, we
|
|
115
|
-
# end up with a certain result
|
|
116
|
-
#
|
|
117
|
-
# @param other [self]
|
|
118
|
-
#
|
|
119
|
-
# @return [Boolean]
|
|
120
|
-
def combine_presence_certain(other)
|
|
121
|
-
presence_certain? || other.presence_certain?
|
|
122
|
-
end
|
|
123
|
-
|
|
124
112
|
# @return [Parser::AST::Node, nil]
|
|
125
113
|
def assignment
|
|
126
114
|
@assignment ||= assignments.last
|
|
@@ -129,7 +117,7 @@ module Solargraph
|
|
|
129
117
|
# @param other [self]
|
|
130
118
|
#
|
|
131
119
|
# @return [::Array<Parser::AST::Node>]
|
|
132
|
-
def combine_assignments
|
|
120
|
+
def combine_assignments other
|
|
133
121
|
(other.assignments + assignments).uniq
|
|
134
122
|
end
|
|
135
123
|
|
|
@@ -161,7 +149,7 @@ module Solargraph
|
|
|
161
149
|
# @param parent_node [Parser::AST::Node]
|
|
162
150
|
# @param api_map [ApiMap]
|
|
163
151
|
# @return [::Array<ComplexType>]
|
|
164
|
-
def return_types_from_node
|
|
152
|
+
def return_types_from_node parent_node, api_map
|
|
165
153
|
types = []
|
|
166
154
|
value_position_nodes_only(parent_node).each do |node|
|
|
167
155
|
# Nil nodes may not have a location
|
|
@@ -242,7 +230,7 @@ module Solargraph
|
|
|
242
230
|
|
|
243
231
|
# @param other_loc [Location]
|
|
244
232
|
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
245
|
-
def starts_at?
|
|
233
|
+
def starts_at? other_loc
|
|
246
234
|
location&.filename == other_loc.filename &&
|
|
247
235
|
presence &&
|
|
248
236
|
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
@@ -254,7 +242,7 @@ module Solargraph
|
|
|
254
242
|
# @param other [self]
|
|
255
243
|
#
|
|
256
244
|
# @return [Range, nil]
|
|
257
|
-
def combine_presence
|
|
245
|
+
def combine_presence other
|
|
258
246
|
return presence || other.presence if presence.nil? || other.presence.nil?
|
|
259
247
|
|
|
260
248
|
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
@@ -263,14 +251,14 @@ module Solargraph
|
|
|
263
251
|
|
|
264
252
|
# @param other [self]
|
|
265
253
|
# @return [Pin::Closure, nil]
|
|
266
|
-
def combine_closure
|
|
267
|
-
return closure if
|
|
254
|
+
def combine_closure other
|
|
255
|
+
return closure if closure == other.closure
|
|
268
256
|
|
|
269
257
|
# choose first defined, as that establishes the scope of the variable
|
|
270
258
|
if closure.nil? || other.closure.nil?
|
|
271
259
|
Solargraph.assert_or_log(:varible_closure_missing) do
|
|
272
|
-
|
|
273
|
-
"#{
|
|
260
|
+
'One of the local variables being combined is missing a closure: ' \
|
|
261
|
+
"#{inspect} vs #{other.inspect}"
|
|
274
262
|
end
|
|
275
263
|
return closure || other.closure
|
|
276
264
|
end
|
|
@@ -290,7 +278,7 @@ module Solargraph
|
|
|
290
278
|
|
|
291
279
|
# @param other_closure [Pin::Closure]
|
|
292
280
|
# @param other_loc [Location]
|
|
293
|
-
def visible_at?
|
|
281
|
+
def visible_at? other_closure, other_loc
|
|
294
282
|
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
295
283
|
location.filename == other_loc.filename &&
|
|
296
284
|
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
@@ -298,10 +286,6 @@ module Solargraph
|
|
|
298
286
|
visible_in_closure?(other_closure)
|
|
299
287
|
end
|
|
300
288
|
|
|
301
|
-
def presence_certain?
|
|
302
|
-
@presence_certain
|
|
303
|
-
end
|
|
304
|
-
|
|
305
289
|
protected
|
|
306
290
|
|
|
307
291
|
attr_accessor :exclude_return_type, :intersection_return_type
|
|
@@ -315,40 +299,13 @@ module Solargraph
|
|
|
315
299
|
# @param raw_return_type [ComplexType, ComplexType::UniqueType]
|
|
316
300
|
#
|
|
317
301
|
# @return [ComplexType, ComplexType::UniqueType]
|
|
318
|
-
def adjust_type
|
|
302
|
+
def adjust_type api_map, raw_return_type
|
|
319
303
|
qualified_exclude = exclude_return_type&.qualify(api_map, *(closure&.gates || ['']))
|
|
320
304
|
minus_exclusions = raw_return_type.exclude qualified_exclude, api_map
|
|
321
305
|
qualified_intersection = intersection_return_type&.qualify(api_map, *(closure&.gates || ['']))
|
|
322
306
|
minus_exclusions.intersect_with qualified_intersection, api_map
|
|
323
307
|
end
|
|
324
308
|
|
|
325
|
-
# @param other [self]
|
|
326
|
-
# @return [Pin::Closure, nil]
|
|
327
|
-
def combine_closure(other)
|
|
328
|
-
return closure if self.closure == other.closure
|
|
329
|
-
|
|
330
|
-
# choose first defined, as that establishes the scope of the variable
|
|
331
|
-
if closure.nil? || other.closure.nil?
|
|
332
|
-
Solargraph.assert_or_log(:varible_closure_missing) do
|
|
333
|
-
"One of the local variables being combined is missing a closure: " \
|
|
334
|
-
"#{self.inspect} vs #{other.inspect}"
|
|
335
|
-
end
|
|
336
|
-
return closure || other.closure
|
|
337
|
-
end
|
|
338
|
-
|
|
339
|
-
# @sg-ignore Need to add nil check here
|
|
340
|
-
if closure.location.nil? || other.closure.location.nil?
|
|
341
|
-
# @sg-ignore Need to add nil check here
|
|
342
|
-
return closure.location.nil? ? other.closure : closure
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
# if filenames are different, this will just pick one
|
|
346
|
-
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
347
|
-
return closure if closure.location <= other.closure.location
|
|
348
|
-
|
|
349
|
-
other.closure
|
|
350
|
-
end
|
|
351
|
-
|
|
352
309
|
# See if this variable is visible within 'viewing_closure'
|
|
353
310
|
#
|
|
354
311
|
# @param viewing_closure [Pin::Closure]
|
|
@@ -381,7 +338,7 @@ module Solargraph
|
|
|
381
338
|
|
|
382
339
|
# @param other [self]
|
|
383
340
|
# @return [ComplexType, nil]
|
|
384
|
-
def combine_return_type
|
|
341
|
+
def combine_return_type other
|
|
385
342
|
combine_types(other, :return_type)
|
|
386
343
|
end
|
|
387
344
|
|
|
@@ -389,7 +346,7 @@ module Solargraph
|
|
|
389
346
|
# @param attr [::Symbol]
|
|
390
347
|
#
|
|
391
348
|
# @return [ComplexType, nil]
|
|
392
|
-
def combine_types
|
|
349
|
+
def combine_types other, attr
|
|
393
350
|
# @type [ComplexType, nil]
|
|
394
351
|
type1 = send(attr)
|
|
395
352
|
# @type [ComplexType, nil]
|
data/lib/solargraph/pin/block.rb
CHANGED
|
@@ -15,6 +15,7 @@ module Solargraph
|
|
|
15
15
|
# @param node [Parser::AST::Node, nil]
|
|
16
16
|
# @param context [ComplexType, nil]
|
|
17
17
|
# @param args [::Array<Parameter>]
|
|
18
|
+
# @param [Hash{Symbol => Object}] splat
|
|
18
19
|
def initialize receiver: nil, args: [], context: nil, node: nil, **splat
|
|
19
20
|
super(**splat, parameters: args)
|
|
20
21
|
@receiver = receiver
|
|
@@ -44,7 +45,7 @@ module Solargraph
|
|
|
44
45
|
# @param parameters [::Array<Parameter>]
|
|
45
46
|
#
|
|
46
47
|
# @return [::Array<ComplexType>]
|
|
47
|
-
def destructure_yield_types
|
|
48
|
+
def destructure_yield_types yield_types, parameters
|
|
48
49
|
# yielding a tuple into a block will destructure the tuple
|
|
49
50
|
if yield_types.length == 1
|
|
50
51
|
yield_type = yield_types.first
|
|
@@ -55,7 +56,7 @@ module Solargraph
|
|
|
55
56
|
|
|
56
57
|
# @param api_map [ApiMap]
|
|
57
58
|
# @return [::Array<ComplexType>]
|
|
58
|
-
def typify_parameters
|
|
59
|
+
def typify_parameters api_map
|
|
59
60
|
chain = Parser.chain(receiver, filename, node)
|
|
60
61
|
# @sg-ignore Need to add nil check here
|
|
61
62
|
clip = api_map.clip_at(location.filename, location.range.start)
|