solargraph 0.59.0.dev.1 → 0.59.0
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/linting.yml +3 -1
- data/.github/workflows/plugins.yml +12 -3
- data/.github/workflows/rspec.yml +9 -54
- data/.github/workflows/typecheck.yml +2 -1
- data/.gitignore +1 -0
- data/.rubocop.yml +38 -6
- data/.rubocop_todo.yml +40 -931
- data/CHANGELOG.md +22 -1
- data/Gemfile +3 -1
- data/Rakefile +25 -23
- data/bin/solargraph +2 -1
- data/lib/solargraph/api_map/constants.rb +0 -1
- data/lib/solargraph/api_map/index.rb +11 -11
- data/lib/solargraph/api_map/source_to_yard.rb +9 -8
- data/lib/solargraph/api_map/store.rb +28 -20
- data/lib/solargraph/api_map.rb +70 -41
- data/lib/solargraph/bench.rb +44 -45
- data/lib/solargraph/complex_type/type_methods.rb +14 -16
- data/lib/solargraph/complex_type/unique_type.rb +56 -47
- data/lib/solargraph/complex_type.rb +70 -62
- 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 +370 -132
- data/lib/solargraph/equality.rb +3 -3
- data/lib/solargraph/gem_pins.rb +19 -18
- 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 +68 -95
- data/lib/solargraph/location.rb +10 -12
- data/lib/solargraph/logging.rb +4 -6
- 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 -44
- 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 -6
- 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 -2
- 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 +76 -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 +74 -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/type_alias.rb +16 -0
- data/lib/solargraph/pin/reference.rb +18 -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 +71 -488
- data/lib/solargraph/position.rb +38 -17
- data/lib/solargraph/range.rb +10 -9
- data/lib/solargraph/rbs_map/conversions.rb +327 -221
- 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 +5 -15
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +224 -66
- 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 +26 -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 +51 -47
- data/lib/solargraph/source_map.rb +8 -4
- data/lib/solargraph/type_checker/rules.rb +8 -8
- data/lib/solargraph/type_checker.rb +95 -102
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +11 -10
- data/lib/solargraph/workspace/gemspecs.rb +3 -3
- data/lib/solargraph/workspace.rb +45 -165
- 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_map.rb +17 -18
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph/yardoc.rb +26 -33
- data/lib/solargraph.rb +7 -5
- data/solargraph.gemspec +36 -35
- metadata +33 -38
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,15 @@ 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
|
+
return true if results.any? { |r| [true, false].include?(r) }
|
|
241
245
|
return results.first if results.any? { |r| r.is_a? AST::Node }
|
|
242
246
|
results.min
|
|
243
|
-
rescue
|
|
244
|
-
|
|
247
|
+
rescue StandardError
|
|
248
|
+
warn("Problem handling #{attr} for \n#{inspect}\n and \n#{other.inspect}\n\n#{send(attr).inspect} vs #{other.send(attr).inspect}")
|
|
245
249
|
raise
|
|
246
250
|
end
|
|
247
251
|
|
|
@@ -249,7 +253,7 @@ module Solargraph
|
|
|
249
253
|
# @param attr [::Symbol]
|
|
250
254
|
# @sg-ignore
|
|
251
255
|
# @return [undefined]
|
|
252
|
-
def choose_node
|
|
256
|
+
def choose_node other, attr
|
|
253
257
|
if other.object_id < attr.object_id
|
|
254
258
|
other.send(attr)
|
|
255
259
|
else
|
|
@@ -261,9 +265,9 @@ module Solargraph
|
|
|
261
265
|
# @param attr [::Symbol]
|
|
262
266
|
# @sg-ignore
|
|
263
267
|
# @return [undefined]
|
|
264
|
-
def prefer_rbs_location
|
|
268
|
+
def prefer_rbs_location other, attr
|
|
265
269
|
if rbs_location? && !other.rbs_location?
|
|
266
|
-
|
|
270
|
+
send(attr)
|
|
267
271
|
elsif !rbs_location? && other.rbs_location?
|
|
268
272
|
other.send(attr)
|
|
269
273
|
else
|
|
@@ -278,8 +282,8 @@ module Solargraph
|
|
|
278
282
|
|
|
279
283
|
# @param other [self]
|
|
280
284
|
# @return [void]
|
|
281
|
-
def assert_same_macros
|
|
282
|
-
return unless
|
|
285
|
+
def assert_same_macros other
|
|
286
|
+
return unless source == :yardoc && other.source == :yardoc
|
|
283
287
|
assert_same_count(other, :macros)
|
|
284
288
|
# @param [YARD::Tags::MacroDirective]
|
|
285
289
|
assert_same_array_content(other, :macros) { |macro| macro.tag.name }
|
|
@@ -289,7 +293,7 @@ module Solargraph
|
|
|
289
293
|
# @param attr [::Symbol]
|
|
290
294
|
# @return [void]
|
|
291
295
|
# @todo strong typechecking should complain when there are no block-related tags
|
|
292
|
-
def assert_same_array_content
|
|
296
|
+
def assert_same_array_content other, attr, &block
|
|
293
297
|
arr1 = send(attr)
|
|
294
298
|
raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
|
|
295
299
|
# @type arr1 [::Enumerable]
|
|
@@ -303,7 +307,7 @@ module Solargraph
|
|
|
303
307
|
values2 = arr2.map(&block)
|
|
304
308
|
# @sg-ignore
|
|
305
309
|
return arr1 if values1 == values2
|
|
306
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
310
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
307
311
|
"Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self values = #{values1}\nother values =#{attr} = #{values2}")
|
|
308
312
|
arr1
|
|
309
313
|
end
|
|
@@ -312,15 +316,15 @@ module Solargraph
|
|
|
312
316
|
# @param attr [::Symbol]
|
|
313
317
|
#
|
|
314
318
|
# @return [::Enumerable]
|
|
315
|
-
def assert_same_count
|
|
319
|
+
def assert_same_count other, attr
|
|
316
320
|
# @type [::Enumerable]
|
|
317
|
-
arr1 =
|
|
321
|
+
arr1 = send(attr)
|
|
318
322
|
raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
|
|
319
323
|
# @type [::Enumerable]
|
|
320
324
|
arr2 = other.send(attr)
|
|
321
325
|
raise "Expected #{attr} on #{other} to be an Enumerable, got #{arr2.class}" unless arr2.is_a?(::Enumerable)
|
|
322
326
|
return arr1 if arr1.count == arr2.count
|
|
323
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
327
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
324
328
|
"Inconsistent #{attr.inspect} count value between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{arr1.inspect}\nother.#{attr} = #{arr2.inspect}")
|
|
325
329
|
arr1
|
|
326
330
|
end
|
|
@@ -330,16 +334,16 @@ module Solargraph
|
|
|
330
334
|
#
|
|
331
335
|
# @sg-ignore
|
|
332
336
|
# @return [undefined]
|
|
333
|
-
def assert_same
|
|
337
|
+
def assert_same other, attr
|
|
334
338
|
if other.nil?
|
|
335
|
-
Solargraph.assert_or_log("combine_with_#{attr}_nil"
|
|
339
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_nil",
|
|
336
340
|
"Other was passed in nil in assert_same on #{self}")
|
|
337
341
|
return send(attr)
|
|
338
342
|
end
|
|
339
343
|
val1 = send(attr)
|
|
340
344
|
val2 = other.send(attr)
|
|
341
345
|
return val1 if val1 == val2
|
|
342
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
346
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
343
347
|
"Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
344
348
|
val1
|
|
345
349
|
end
|
|
@@ -348,15 +352,17 @@ module Solargraph
|
|
|
348
352
|
# @param attr [::Symbol]
|
|
349
353
|
# @sg-ignore
|
|
350
354
|
# @return [undefined]
|
|
351
|
-
def choose_pin_attr_with_same_name
|
|
355
|
+
def choose_pin_attr_with_same_name other, attr
|
|
352
356
|
# @type [Pin::Base, nil]
|
|
353
357
|
val1 = send(attr)
|
|
354
358
|
# @type [Pin::Base, nil]
|
|
355
359
|
val2 = other.send(attr)
|
|
356
|
-
raise "Expected pin for #{attr} on\n#{
|
|
357
|
-
|
|
360
|
+
raise "Expected pin for #{attr} on\n#{inspect},\ngot #{val1.inspect}" unless val1.nil? || val1.is_a?(Pin::Base)
|
|
361
|
+
unless val2.nil? || val2.is_a?(Pin::Base)
|
|
362
|
+
raise "Expected pin for #{attr} on\n#{other.inspect},\ngot #{val2.inspect}"
|
|
363
|
+
end
|
|
358
364
|
if val1&.name != val2&.name
|
|
359
|
-
Solargraph.assert_or_log("combine_with_#{attr}_name"
|
|
365
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_name",
|
|
360
366
|
"Inconsistent #{attr.inspect} name values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
361
367
|
end
|
|
362
368
|
choose_pin_attr(other, attr)
|
|
@@ -367,14 +373,14 @@ module Solargraph
|
|
|
367
373
|
#
|
|
368
374
|
# @sg-ignore Missing @return tag for Solargraph::Pin::Base#choose_pin_attr
|
|
369
375
|
# @return [undefined]
|
|
370
|
-
def choose_pin_attr
|
|
376
|
+
def choose_pin_attr other, attr
|
|
371
377
|
# @type [Pin::Base, nil]
|
|
372
378
|
val1 = send(attr)
|
|
373
379
|
# @type [Pin::Base, nil]
|
|
374
380
|
val2 = other.send(attr)
|
|
375
381
|
if val1.class != val2.class
|
|
376
382
|
# :nocov:
|
|
377
|
-
Solargraph.assert_or_log("combine_with_#{attr}_class"
|
|
383
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_class",
|
|
378
384
|
"Inconsistent #{attr.inspect} class values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
379
385
|
return val1
|
|
380
386
|
# :nocov:
|
|
@@ -406,10 +412,9 @@ module Solargraph
|
|
|
406
412
|
|
|
407
413
|
# @param generics_to_resolve [Enumerable<String>]
|
|
408
414
|
# @param return_type_context [ComplexType, ComplexType::UniqueType, nil]
|
|
409
|
-
# @param context [ComplexType]
|
|
410
415
|
# @param resolved_generic_values [Hash{String => ComplexType}]
|
|
411
416
|
# @return [self]
|
|
412
|
-
def resolve_generics_from_context
|
|
417
|
+
def resolve_generics_from_context generics_to_resolve, return_type_context = nil, resolved_generic_values: {}
|
|
413
418
|
proxy return_type.resolve_generics_from_context(generics_to_resolve,
|
|
414
419
|
return_type_context,
|
|
415
420
|
resolved_generic_values: resolved_generic_values)
|
|
@@ -418,7 +423,7 @@ module Solargraph
|
|
|
418
423
|
# @yieldparam [ComplexType]
|
|
419
424
|
# @yieldreturn [ComplexType]
|
|
420
425
|
# @return [self]
|
|
421
|
-
def transform_types
|
|
426
|
+
def transform_types &transform
|
|
422
427
|
proxy return_type.transform(&transform)
|
|
423
428
|
end
|
|
424
429
|
|
|
@@ -430,7 +435,7 @@ module Solargraph
|
|
|
430
435
|
# @param context_type [ComplexType] The receiver type
|
|
431
436
|
# @return [self]
|
|
432
437
|
def resolve_generics definitions, context_type
|
|
433
|
-
transform_types { |t| t
|
|
438
|
+
transform_types { |t| t&.resolve_generics(definitions, context_type) }
|
|
434
439
|
end
|
|
435
440
|
|
|
436
441
|
def all_rooted?
|
|
@@ -439,7 +444,7 @@ module Solargraph
|
|
|
439
444
|
|
|
440
445
|
# @param generics_to_erase [::Array<String>]
|
|
441
446
|
# @return [self]
|
|
442
|
-
def erase_generics
|
|
447
|
+
def erase_generics generics_to_erase
|
|
443
448
|
return self if generics_to_erase.empty?
|
|
444
449
|
transform_types { |t| t.erase_generics(generics_to_erase) }
|
|
445
450
|
end
|
|
@@ -482,15 +487,18 @@ module Solargraph
|
|
|
482
487
|
# @param other [Solargraph::Pin::Base, Object]
|
|
483
488
|
# @return [Boolean]
|
|
484
489
|
def nearly? other
|
|
485
|
-
|
|
490
|
+
instance_of?(other.class) &&
|
|
486
491
|
# @sg-ignore Translate to something flow sensitive typing understands
|
|
487
492
|
name == other.name &&
|
|
488
493
|
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
489
494
|
(closure == other.closure || (closure && closure.nearly?(other.closure))) &&
|
|
490
495
|
# @sg-ignore Translate to something flow sensitive typing understands
|
|
491
496
|
(comments == other.comments ||
|
|
492
|
-
|
|
493
|
-
|
|
497
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
498
|
+
(((maybe_directives? == false && other.maybe_directives? == false) ||
|
|
499
|
+
compare_directives(directives,
|
|
500
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
501
|
+
other.directives)) &&
|
|
494
502
|
# @sg-ignore Translate to something flow sensitive typing understands
|
|
495
503
|
compare_docstring_tags(docstring, other.docstring))
|
|
496
504
|
)
|
|
@@ -573,7 +581,8 @@ module Solargraph
|
|
|
573
581
|
# @param api_map [ApiMap]
|
|
574
582
|
# @return [ComplexType, ComplexType::UniqueType]
|
|
575
583
|
def infer api_map
|
|
576
|
-
Solargraph.assert_or_log(:pin_infer,
|
|
584
|
+
Solargraph.assert_or_log(:pin_infer,
|
|
585
|
+
'WARNING: Pin #infer methods are deprecated. Use #typify or #probe instead.')
|
|
577
586
|
type = typify(api_map)
|
|
578
587
|
return type unless type.undefined?
|
|
579
588
|
probe api_map
|
|
@@ -643,7 +652,7 @@ module Solargraph
|
|
|
643
652
|
rbs = return_type.rooted_tags if return_type.name == 'Class'
|
|
644
653
|
if path
|
|
645
654
|
if rbs
|
|
646
|
-
path
|
|
655
|
+
"#{path} #{rbs}"
|
|
647
656
|
else
|
|
648
657
|
path
|
|
649
658
|
end
|
|
@@ -666,7 +675,7 @@ module Solargraph
|
|
|
666
675
|
|
|
667
676
|
# @return [String]
|
|
668
677
|
def inspect
|
|
669
|
-
"#<#{self.class} `#{
|
|
678
|
+
"#<#{self.class} `#{inner_desc}`#{all_location_text} via #{source.inspect}>"
|
|
670
679
|
end
|
|
671
680
|
|
|
672
681
|
# @return [String]
|
|
@@ -684,6 +693,11 @@ module Solargraph
|
|
|
684
693
|
|
|
685
694
|
protected
|
|
686
695
|
|
|
696
|
+
# @sg-ignore def should infer as symbol - "Not enough arguments to Module#protected"
|
|
697
|
+
def equality_fields
|
|
698
|
+
[name, location, type_location, closure, source]
|
|
699
|
+
end
|
|
700
|
+
|
|
687
701
|
# @return [Boolean]
|
|
688
702
|
attr_writer :probed
|
|
689
703
|
|
|
@@ -693,9 +707,7 @@ module Solargraph
|
|
|
693
707
|
# @return [ComplexType, ComplexType::UniqueType, nil]
|
|
694
708
|
attr_writer :return_type
|
|
695
709
|
|
|
696
|
-
attr_writer :docstring
|
|
697
|
-
|
|
698
|
-
attr_writer :directives
|
|
710
|
+
attr_writer :docstring, :directives
|
|
699
711
|
|
|
700
712
|
private
|
|
701
713
|
|
|
@@ -717,13 +729,13 @@ module Solargraph
|
|
|
717
729
|
# True if two docstrings have the same tags, regardless of any other
|
|
718
730
|
# differences.
|
|
719
731
|
#
|
|
720
|
-
# @param
|
|
721
|
-
# @param
|
|
732
|
+
# @param docstring1 [YARD::Docstring]
|
|
733
|
+
# @param docstring2 [YARD::Docstring]
|
|
722
734
|
# @return [Boolean]
|
|
723
|
-
def compare_docstring_tags
|
|
724
|
-
return false if
|
|
725
|
-
|
|
726
|
-
return false unless compare_tags(
|
|
735
|
+
def compare_docstring_tags docstring1, docstring2
|
|
736
|
+
return false if docstring1.tags.length != docstring2.tags.length
|
|
737
|
+
docstring1.tags.each_index do |i|
|
|
738
|
+
return false unless compare_tags(docstring1.tags[i], docstring2.tags[i])
|
|
727
739
|
end
|
|
728
740
|
true
|
|
729
741
|
end
|
|
@@ -743,7 +755,7 @@ module Solargraph
|
|
|
743
755
|
# @param tag2 [YARD::Tags::Tag]
|
|
744
756
|
# @return [Boolean]
|
|
745
757
|
def compare_tags tag1, tag2
|
|
746
|
-
tag1.
|
|
758
|
+
tag1.instance_of?(tag2.class) &&
|
|
747
759
|
tag1.tag_name == tag2.tag_name &&
|
|
748
760
|
tag1.text == tag2.text &&
|
|
749
761
|
tag1.name == tag2.name &&
|
|
@@ -754,7 +766,7 @@ module Solargraph
|
|
|
754
766
|
def collect_macros
|
|
755
767
|
return [] unless maybe_directives?
|
|
756
768
|
parse = Solargraph::Source.parse_docstring(comments)
|
|
757
|
-
parse.directives.select{ |d| d.tag.tag_name == 'macro' }
|
|
769
|
+
parse.directives.select { |d| d.tag.tag_name == 'macro' }
|
|
758
770
|
end
|
|
759
771
|
end
|
|
760
772
|
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)
|