solargraph 0.58.2 → 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/.envrc +3 -0
- data/.github/workflows/linting.yml +4 -5
- data/.github/workflows/plugins.yml +41 -34
- data/.github/workflows/rspec.yml +44 -23
- data/.github/workflows/typecheck.yml +2 -2
- data/.rubocop.yml +32 -5
- data/.rubocop_todo.yml +50 -966
- data/Gemfile +3 -1
- data/README.md +3 -3
- data/Rakefile +26 -23
- data/bin/solargraph +2 -1
- data/lib/solargraph/api_map/cache.rb +3 -3
- data/lib/solargraph/api_map/constants.rb +13 -3
- data/lib/solargraph/api_map/index.rb +23 -18
- data/lib/solargraph/api_map/source_to_yard.rb +22 -9
- data/lib/solargraph/api_map/store.rb +33 -28
- data/lib/solargraph/api_map.rb +150 -82
- data/lib/solargraph/bench.rb +44 -45
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +28 -17
- data/lib/solargraph/complex_type/unique_type.rb +218 -57
- data/lib/solargraph/complex_type.rb +170 -57
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +7 -5
- data/lib/solargraph/convention/data_definition.rb +5 -2
- 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 +2 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +4 -3
- data/lib/solargraph/convention/struct_definition.rb +8 -4
- 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/require_not_found.rb +1 -0
- data/lib/solargraph/diagnostics/rubocop.rb +11 -10
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +5 -3
- data/lib/solargraph/diagnostics/type_check.rb +11 -10
- data/lib/solargraph/diagnostics/update_errors.rb +37 -41
- data/lib/solargraph/doc_map.rb +133 -373
- data/lib/solargraph/equality.rb +4 -4
- data/lib/solargraph/gem_pins.rb +21 -20
- data/lib/solargraph/language_server/error_codes.rb +20 -20
- data/lib/solargraph/language_server/host/diagnoser.rb +1 -1
- data/lib/solargraph/language_server/host/dispatch.rb +3 -3
- data/lib/solargraph/language_server/host/message_worker.rb +4 -3
- data/lib/solargraph/language_server/host/sources.rb +2 -1
- data/lib/solargraph/language_server/host.rb +30 -22
- 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 +12 -18
- data/lib/solargraph/language_server/message/extended/document.rb +1 -0
- 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 +10 -8
- data/lib/solargraph/language_server/message/text_document/definition.rb +41 -32
- 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 -19
- data/lib/solargraph/language_server/message/text_document/formatting.rb +8 -6
- data/lib/solargraph/language_server/message/text_document/hover.rb +5 -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 +3 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -17
- 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 -17
- 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 +85 -44
- data/lib/solargraph/location.rb +17 -14
- data/lib/solargraph/logging.rb +24 -4
- data/lib/solargraph/page.rb +92 -92
- data/lib/solargraph/parser/comment_ripper.rb +19 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +326 -108
- data/lib/solargraph/parser/node_processor/base.rb +34 -4
- data/lib/solargraph/parser/node_processor.rb +8 -7
- data/lib/solargraph/parser/parser_gem/class_methods.rb +32 -14
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +50 -25
- data/lib/solargraph/parser/parser_gem/node_methods.rb +91 -70
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +4 -4
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +13 -11
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +9 -0
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +12 -12
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +10 -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 +36 -6
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +5 -3
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +4 -5
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +124 -113
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +6 -2
- data/lib/solargraph/parser/parser_gem/node_processors.rb +4 -0
- data/lib/solargraph/parser/parser_gem.rb +14 -12
- data/lib/solargraph/parser/region.rb +9 -3
- data/lib/solargraph/parser/snippet.rb +3 -1
- data/lib/solargraph/parser.rb +25 -23
- data/lib/solargraph/pin/base.rb +126 -80
- data/lib/solargraph/pin/base_variable.rb +273 -24
- data/lib/solargraph/pin/block.rb +29 -6
- data/lib/solargraph/pin/breakable.rb +7 -1
- data/lib/solargraph/pin/callable.rb +65 -21
- data/lib/solargraph/pin/closure.rb +7 -10
- data/lib/solargraph/pin/common.rb +24 -6
- data/lib/solargraph/pin/compound_statement.rb +55 -0
- data/lib/solargraph/pin/constant.rb +43 -45
- data/lib/solargraph/pin/conversions.rb +10 -4
- data/lib/solargraph/pin/delegated_method.rb +19 -8
- data/lib/solargraph/pin/documenting.rb +4 -2
- data/lib/solargraph/pin/instance_variable.rb +5 -1
- data/lib/solargraph/pin/keyword.rb +0 -4
- data/lib/solargraph/pin/local_variable.rb +15 -59
- data/lib/solargraph/pin/method.rb +153 -104
- data/lib/solargraph/pin/method_alias.rb +8 -0
- data/lib/solargraph/pin/namespace.rb +19 -12
- data/lib/solargraph/pin/parameter.rb +100 -36
- data/lib/solargraph/pin/proxy_type.rb +4 -1
- data/lib/solargraph/pin/reference/override.rb +1 -1
- data/lib/solargraph/pin/reference/superclass.rb +2 -0
- data/lib/solargraph/pin/reference.rb +19 -0
- data/lib/solargraph/pin/search.rb +3 -2
- data/lib/solargraph/pin/signature.rb +15 -12
- data/lib/solargraph/pin/symbol.rb +2 -1
- data/lib/solargraph/pin/until.rb +2 -4
- data/lib/solargraph/pin/while.rb +2 -4
- data/lib/solargraph/pin.rb +2 -0
- data/lib/solargraph/pin_cache.rb +490 -73
- data/lib/solargraph/position.rb +14 -10
- data/lib/solargraph/range.rb +16 -15
- data/lib/solargraph/rbs_map/conversions.rb +343 -214
- data/lib/solargraph/rbs_map/core_fills.rb +91 -84
- data/lib/solargraph/rbs_map/core_map.rb +24 -17
- data/lib/solargraph/rbs_map/stdlib_map.rb +33 -5
- data/lib/solargraph/rbs_map.rb +77 -32
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +128 -73
- data/lib/solargraph/source/chain/array.rb +39 -37
- data/lib/solargraph/source/chain/call.rb +96 -56
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +5 -1
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +8 -5
- data/lib/solargraph/source/chain/if.rb +12 -10
- data/lib/solargraph/source/chain/instance_variable.rb +24 -1
- data/lib/solargraph/source/chain/link.rb +99 -109
- data/lib/solargraph/source/chain/literal.rb +9 -6
- data/lib/solargraph/source/chain/or.rb +10 -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 +49 -38
- data/lib/solargraph/source/change.rb +12 -5
- data/lib/solargraph/source/cursor.rb +23 -17
- data/lib/solargraph/source/encoding_fixes.rb +6 -7
- data/lib/solargraph/source/source_chainer.rb +56 -32
- data/lib/solargraph/source/updater.rb +5 -1
- data/lib/solargraph/source.rb +59 -35
- data/lib/solargraph/source_map/clip.rb +48 -29
- data/lib/solargraph/source_map/data.rb +4 -1
- data/lib/solargraph/source_map/mapper.rb +71 -42
- data/lib/solargraph/source_map.rb +21 -9
- data/lib/solargraph/type_checker/problem.rb +3 -1
- data/lib/solargraph/type_checker/rules.rb +81 -8
- data/lib/solargraph/type_checker.rb +195 -120
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +13 -10
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +1 -0
- data/lib/solargraph/workspace.rb +149 -30
- data/lib/solargraph/yard_map/helpers.rb +8 -3
- data/lib/solargraph/yard_map/mapper/to_method.rb +13 -7
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +2 -1
- data/lib/solargraph/yard_map/mapper.rb +13 -8
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph/yardoc.rb +33 -23
- data/lib/solargraph.rb +29 -8
- data/rbs/fills/rubygems/0/dependency.rbs +193 -0
- data/rbs/fills/tuple/tuple.rbs +28 -0
- data/rbs/shims/ast/0/node.rbs +1 -1
- data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
- data/solargraph.gemspec +36 -34
- metadata +38 -33
- data/lib/solargraph/type_checker/checks.rb +0 -124
- data/lib/solargraph/type_checker/param_def.rb +0 -37
- data/lib/solargraph/yard_map/to_method.rb +0 -89
data/lib/solargraph/pin/base.rb
CHANGED
|
@@ -41,12 +41,13 @@ module Solargraph
|
|
|
41
41
|
# @param type_location [Solargraph::Location, nil]
|
|
42
42
|
# @param closure [Solargraph::Pin::Closure, nil]
|
|
43
43
|
# @param name [String]
|
|
44
|
-
# @param comments [String]
|
|
44
|
+
# @param comments [String, nil]
|
|
45
45
|
# @param source [Symbol, nil]
|
|
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
|
|
@@ -57,6 +58,8 @@ module Solargraph
|
|
|
57
58
|
@docstring = docstring
|
|
58
59
|
@directives = directives
|
|
59
60
|
@combine_priority = combine_priority
|
|
61
|
+
# @type [ComplexType, ComplexType::UniqueType, nil]
|
|
62
|
+
@binder = nil
|
|
60
63
|
|
|
61
64
|
assert_source_provided
|
|
62
65
|
assert_location_provided
|
|
@@ -66,13 +69,16 @@ module Solargraph
|
|
|
66
69
|
def assert_location_provided
|
|
67
70
|
return unless best_location.nil? && %i[yardoc source rbs].include?(source)
|
|
68
71
|
|
|
69
|
-
Solargraph.assert_or_log(:best_location,
|
|
72
|
+
Solargraph.assert_or_log(:best_location,
|
|
73
|
+
"Neither location nor type_location provided - #{path} #{source} #{self.class}")
|
|
70
74
|
end
|
|
71
75
|
|
|
72
76
|
# @return [Pin::Closure, nil]
|
|
73
77
|
def closure
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
unless @closure
|
|
79
|
+
Solargraph.assert_or_log(:closure,
|
|
80
|
+
"Closure not set on #{self.class} #{name.inspect} from #{source.inspect}")
|
|
81
|
+
end
|
|
76
82
|
@closure
|
|
77
83
|
end
|
|
78
84
|
|
|
@@ -80,8 +86,7 @@ module Solargraph
|
|
|
80
86
|
# @param attrs [Hash{::Symbol => Object}]
|
|
81
87
|
#
|
|
82
88
|
# @return [self]
|
|
83
|
-
def combine_with
|
|
84
|
-
raise "tried to combine #{other.class} with #{self.class}" unless other.class == self.class
|
|
89
|
+
def combine_with other, attrs = {}
|
|
85
90
|
priority_choice = choose_priority(other)
|
|
86
91
|
return priority_choice unless priority_choice.nil?
|
|
87
92
|
|
|
@@ -92,7 +97,7 @@ module Solargraph
|
|
|
92
97
|
location: location,
|
|
93
98
|
type_location: type_location,
|
|
94
99
|
name: combined_name,
|
|
95
|
-
closure:
|
|
100
|
+
closure: combine_closure(other),
|
|
96
101
|
comments: choose_longer(other, :comments),
|
|
97
102
|
source: :combined,
|
|
98
103
|
docstring: choose(other, :docstring),
|
|
@@ -100,7 +105,9 @@ module Solargraph
|
|
|
100
105
|
combine_priority: combine_priority
|
|
101
106
|
}.merge(attrs)
|
|
102
107
|
assert_same_macros(other)
|
|
103
|
-
logger.debug
|
|
108
|
+
logger.debug do
|
|
109
|
+
"Base#combine_with(path=#{path}) - other.comments=#{other.comments.inspect}, self.comments = #{comments}"
|
|
110
|
+
end
|
|
104
111
|
out = self.class.new(**new_attrs)
|
|
105
112
|
out.reset_generated!
|
|
106
113
|
out
|
|
@@ -109,7 +116,7 @@ module Solargraph
|
|
|
109
116
|
# @param other [self]
|
|
110
117
|
# @return [self, nil] Returns either the pin chosen based on priority or nil
|
|
111
118
|
# A nil return means that the combination process must proceed
|
|
112
|
-
def choose_priority
|
|
119
|
+
def choose_priority other
|
|
113
120
|
if combine_priority.nil? && !other.combine_priority.nil?
|
|
114
121
|
return other
|
|
115
122
|
elsif other.combine_priority.nil? && !combine_priority.nil?
|
|
@@ -129,7 +136,7 @@ module Solargraph
|
|
|
129
136
|
# @param attr [::Symbol]
|
|
130
137
|
# @sg-ignore
|
|
131
138
|
# @return [undefined]
|
|
132
|
-
def choose_longer
|
|
139
|
+
def choose_longer other, attr
|
|
133
140
|
# @type [undefined]
|
|
134
141
|
val1 = send(attr)
|
|
135
142
|
# @type [undefined]
|
|
@@ -140,16 +147,24 @@ module Solargraph
|
|
|
140
147
|
end
|
|
141
148
|
|
|
142
149
|
# @param other [self]
|
|
150
|
+
#
|
|
143
151
|
# @return [::Array<YARD::Tags::Directive>, nil]
|
|
144
|
-
def combine_directives
|
|
145
|
-
return
|
|
152
|
+
def combine_directives other
|
|
153
|
+
return directives if other.directives.empty?
|
|
146
154
|
return other.directives if directives.empty?
|
|
147
|
-
|
|
155
|
+
(directives + other.directives).uniq
|
|
148
156
|
end
|
|
149
157
|
|
|
150
158
|
# @param other [self]
|
|
159
|
+
# @return [Pin::Closure, nil]
|
|
160
|
+
def combine_closure other
|
|
161
|
+
choose_pin_attr_with_same_name(other, :closure)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# @param other [self]
|
|
165
|
+
# @sg-ignore @type should override probed type
|
|
151
166
|
# @return [String]
|
|
152
|
-
def combine_name
|
|
167
|
+
def combine_name other
|
|
153
168
|
if needs_consistent_name? || other.needs_consistent_name?
|
|
154
169
|
assert_same(other, :name)
|
|
155
170
|
else
|
|
@@ -170,6 +185,9 @@ module Solargraph
|
|
|
170
185
|
# Same with @directives, @macros, @maybe_directives, which
|
|
171
186
|
# regenerate docstring
|
|
172
187
|
@deprecated = nil
|
|
188
|
+
@context = nil
|
|
189
|
+
@binder = nil
|
|
190
|
+
@path = nil
|
|
173
191
|
reset_conversions
|
|
174
192
|
end
|
|
175
193
|
|
|
@@ -177,25 +195,26 @@ module Solargraph
|
|
|
177
195
|
true
|
|
178
196
|
end
|
|
179
197
|
|
|
180
|
-
# @sg-ignore def should infer as symbol - "Not enough arguments to Module#protected"
|
|
181
|
-
protected def equality_fields
|
|
182
|
-
[name, location, type_location, closure, source]
|
|
183
|
-
end
|
|
184
|
-
|
|
185
198
|
# @param other [self]
|
|
186
199
|
# @return [ComplexType]
|
|
187
|
-
def combine_return_type
|
|
200
|
+
def combine_return_type other
|
|
188
201
|
if return_type.undefined?
|
|
189
202
|
other.return_type
|
|
190
203
|
elsif other.return_type.undefined?
|
|
191
204
|
return_type
|
|
205
|
+
elsif return_type.erased_version_of?(other.return_type)
|
|
206
|
+
other.return_type
|
|
207
|
+
elsif other.return_type.erased_version_of?(return_type)
|
|
208
|
+
return_type
|
|
192
209
|
elsif dodgy_return_type_source? && !other.dodgy_return_type_source?
|
|
193
210
|
other.return_type
|
|
194
211
|
elsif other.dodgy_return_type_source? && !dodgy_return_type_source?
|
|
195
212
|
return_type
|
|
196
213
|
else
|
|
197
214
|
all_items = return_type.items + other.return_type.items
|
|
198
|
-
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
|
|
199
218
|
# assume this was a declaration that should have said 'self'
|
|
200
219
|
all_items.delete_if { |item| item.rooted_tag == context.reduce_class_type.rooted_tag }
|
|
201
220
|
end
|
|
@@ -203,9 +222,12 @@ module Solargraph
|
|
|
203
222
|
end
|
|
204
223
|
end
|
|
205
224
|
|
|
225
|
+
# @sg-ignore need boolish support for ? methods
|
|
206
226
|
def dodgy_return_type_source?
|
|
207
227
|
# uses a lot of 'Object' instead of 'self'
|
|
208
|
-
location&.filename&.include?('core_ext/object/')
|
|
228
|
+
location&.filename&.include?('core_ext/object/') ||
|
|
229
|
+
# ditto
|
|
230
|
+
location&.filename&.include?('stdlib/date/0/date.rbs')
|
|
209
231
|
end
|
|
210
232
|
|
|
211
233
|
# when choices are arbitrary, make sure the choice is consistent
|
|
@@ -213,14 +235,19 @@ module Solargraph
|
|
|
213
235
|
# @param other [Pin::Base]
|
|
214
236
|
# @param attr [::Symbol]
|
|
215
237
|
#
|
|
216
|
-
# @
|
|
217
|
-
|
|
238
|
+
# @sg-ignore
|
|
239
|
+
# @return [undefined, nil]
|
|
240
|
+
def choose other, attr
|
|
218
241
|
results = [self, other].map(&attr).compact
|
|
219
242
|
# true and false are different classes and can't be sorted
|
|
220
|
-
|
|
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) }
|
|
247
|
+
return results.first if results.any? { |r| r.is_a? AST::Node }
|
|
221
248
|
results.min
|
|
222
|
-
rescue
|
|
223
|
-
|
|
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}")
|
|
224
251
|
raise
|
|
225
252
|
end
|
|
226
253
|
|
|
@@ -228,7 +255,7 @@ module Solargraph
|
|
|
228
255
|
# @param attr [::Symbol]
|
|
229
256
|
# @sg-ignore
|
|
230
257
|
# @return [undefined]
|
|
231
|
-
def choose_node
|
|
258
|
+
def choose_node other, attr
|
|
232
259
|
if other.object_id < attr.object_id
|
|
233
260
|
other.send(attr)
|
|
234
261
|
else
|
|
@@ -240,9 +267,9 @@ module Solargraph
|
|
|
240
267
|
# @param attr [::Symbol]
|
|
241
268
|
# @sg-ignore
|
|
242
269
|
# @return [undefined]
|
|
243
|
-
def prefer_rbs_location
|
|
270
|
+
def prefer_rbs_location other, attr
|
|
244
271
|
if rbs_location? && !other.rbs_location?
|
|
245
|
-
|
|
272
|
+
send(attr)
|
|
246
273
|
elsif !rbs_location? && other.rbs_location?
|
|
247
274
|
other.send(attr)
|
|
248
275
|
else
|
|
@@ -250,14 +277,15 @@ module Solargraph
|
|
|
250
277
|
end
|
|
251
278
|
end
|
|
252
279
|
|
|
280
|
+
# @sg-ignore need boolish support for ? methods
|
|
253
281
|
def rbs_location?
|
|
254
282
|
type_location&.rbs?
|
|
255
283
|
end
|
|
256
284
|
|
|
257
285
|
# @param other [self]
|
|
258
286
|
# @return [void]
|
|
259
|
-
def assert_same_macros
|
|
260
|
-
return unless
|
|
287
|
+
def assert_same_macros other
|
|
288
|
+
return unless source == :yardoc && other.source == :yardoc
|
|
261
289
|
assert_same_count(other, :macros)
|
|
262
290
|
# @param [YARD::Tags::MacroDirective]
|
|
263
291
|
assert_same_array_content(other, :macros) { |macro| macro.tag.name }
|
|
@@ -267,7 +295,7 @@ module Solargraph
|
|
|
267
295
|
# @param attr [::Symbol]
|
|
268
296
|
# @return [void]
|
|
269
297
|
# @todo strong typechecking should complain when there are no block-related tags
|
|
270
|
-
def assert_same_array_content
|
|
298
|
+
def assert_same_array_content other, attr, &block
|
|
271
299
|
arr1 = send(attr)
|
|
272
300
|
raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
|
|
273
301
|
# @type arr1 [::Enumerable]
|
|
@@ -281,7 +309,7 @@ module Solargraph
|
|
|
281
309
|
values2 = arr2.map(&block)
|
|
282
310
|
# @sg-ignore
|
|
283
311
|
return arr1 if values1 == values2
|
|
284
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
312
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
285
313
|
"Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self values = #{values1}\nother values =#{attr} = #{values2}")
|
|
286
314
|
arr1
|
|
287
315
|
end
|
|
@@ -290,15 +318,15 @@ module Solargraph
|
|
|
290
318
|
# @param attr [::Symbol]
|
|
291
319
|
#
|
|
292
320
|
# @return [::Enumerable]
|
|
293
|
-
def assert_same_count
|
|
321
|
+
def assert_same_count other, attr
|
|
294
322
|
# @type [::Enumerable]
|
|
295
|
-
arr1 =
|
|
323
|
+
arr1 = send(attr)
|
|
296
324
|
raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
|
|
297
325
|
# @type [::Enumerable]
|
|
298
326
|
arr2 = other.send(attr)
|
|
299
327
|
raise "Expected #{attr} on #{other} to be an Enumerable, got #{arr2.class}" unless arr2.is_a?(::Enumerable)
|
|
300
328
|
return arr1 if arr1.count == arr2.count
|
|
301
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
329
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
302
330
|
"Inconsistent #{attr.inspect} count value between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{arr1.inspect}\nother.#{attr} = #{arr2.inspect}")
|
|
303
331
|
arr1
|
|
304
332
|
end
|
|
@@ -308,12 +336,16 @@ module Solargraph
|
|
|
308
336
|
#
|
|
309
337
|
# @sg-ignore
|
|
310
338
|
# @return [undefined]
|
|
311
|
-
def assert_same
|
|
312
|
-
|
|
339
|
+
def assert_same other, attr
|
|
340
|
+
if other.nil?
|
|
341
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_nil",
|
|
342
|
+
"Other was passed in nil in assert_same on #{self}")
|
|
343
|
+
return send(attr)
|
|
344
|
+
end
|
|
313
345
|
val1 = send(attr)
|
|
314
346
|
val2 = other.send(attr)
|
|
315
347
|
return val1 if val1 == val2
|
|
316
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
348
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
317
349
|
"Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
318
350
|
val1
|
|
319
351
|
end
|
|
@@ -322,15 +354,17 @@ module Solargraph
|
|
|
322
354
|
# @param attr [::Symbol]
|
|
323
355
|
# @sg-ignore
|
|
324
356
|
# @return [undefined]
|
|
325
|
-
def choose_pin_attr_with_same_name
|
|
357
|
+
def choose_pin_attr_with_same_name other, attr
|
|
326
358
|
# @type [Pin::Base, nil]
|
|
327
359
|
val1 = send(attr)
|
|
328
360
|
# @type [Pin::Base, nil]
|
|
329
361
|
val2 = other.send(attr)
|
|
330
|
-
raise "Expected pin for #{attr} on\n#{
|
|
331
|
-
|
|
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
|
|
332
366
|
if val1&.name != val2&.name
|
|
333
|
-
Solargraph.assert_or_log("combine_with_#{attr}_name"
|
|
367
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_name",
|
|
334
368
|
"Inconsistent #{attr.inspect} name values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
335
369
|
end
|
|
336
370
|
choose_pin_attr(other, attr)
|
|
@@ -341,14 +375,14 @@ module Solargraph
|
|
|
341
375
|
#
|
|
342
376
|
# @sg-ignore Missing @return tag for Solargraph::Pin::Base#choose_pin_attr
|
|
343
377
|
# @return [undefined]
|
|
344
|
-
def choose_pin_attr
|
|
378
|
+
def choose_pin_attr other, attr
|
|
345
379
|
# @type [Pin::Base, nil]
|
|
346
380
|
val1 = send(attr)
|
|
347
381
|
# @type [Pin::Base, nil]
|
|
348
382
|
val2 = other.send(attr)
|
|
349
383
|
if val1.class != val2.class
|
|
350
384
|
# :nocov:
|
|
351
|
-
Solargraph.assert_or_log("combine_with_#{attr}_class"
|
|
385
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_class",
|
|
352
386
|
"Inconsistent #{attr.inspect} class values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
353
387
|
return val1
|
|
354
388
|
# :nocov:
|
|
@@ -358,8 +392,11 @@ module Solargraph
|
|
|
358
392
|
[
|
|
359
393
|
# maximize number of gates, as types in other combined pins may
|
|
360
394
|
# depend on those gates
|
|
395
|
+
|
|
396
|
+
# @sg-ignore Need better handling of #compact
|
|
361
397
|
closure.gates.length,
|
|
362
398
|
# use basename so that results don't vary system to system
|
|
399
|
+
# @sg-ignore Need better handling of #compact
|
|
363
400
|
File.basename(closure.best_location.to_s)
|
|
364
401
|
]
|
|
365
402
|
end
|
|
@@ -376,11 +413,10 @@ module Solargraph
|
|
|
376
413
|
end
|
|
377
414
|
|
|
378
415
|
# @param generics_to_resolve [Enumerable<String>]
|
|
379
|
-
# @param return_type_context [ComplexType, nil]
|
|
380
|
-
# @param context [ComplexType]
|
|
416
|
+
# @param return_type_context [ComplexType, ComplexType::UniqueType, nil]
|
|
381
417
|
# @param resolved_generic_values [Hash{String => ComplexType}]
|
|
382
418
|
# @return [self]
|
|
383
|
-
def resolve_generics_from_context
|
|
419
|
+
def resolve_generics_from_context generics_to_resolve, return_type_context = nil, resolved_generic_values: {}
|
|
384
420
|
proxy return_type.resolve_generics_from_context(generics_to_resolve,
|
|
385
421
|
return_type_context,
|
|
386
422
|
resolved_generic_values: resolved_generic_values)
|
|
@@ -389,7 +425,7 @@ module Solargraph
|
|
|
389
425
|
# @yieldparam [ComplexType]
|
|
390
426
|
# @yieldreturn [ComplexType]
|
|
391
427
|
# @return [self]
|
|
392
|
-
def transform_types
|
|
428
|
+
def transform_types &transform
|
|
393
429
|
proxy return_type.transform(&transform)
|
|
394
430
|
end
|
|
395
431
|
|
|
@@ -401,7 +437,7 @@ module Solargraph
|
|
|
401
437
|
# @param context_type [ComplexType] The receiver type
|
|
402
438
|
# @return [self]
|
|
403
439
|
def resolve_generics definitions, context_type
|
|
404
|
-
transform_types { |t| t
|
|
440
|
+
transform_types { |t| t&.resolve_generics(definitions, context_type) }
|
|
405
441
|
end
|
|
406
442
|
|
|
407
443
|
def all_rooted?
|
|
@@ -410,7 +446,7 @@ module Solargraph
|
|
|
410
446
|
|
|
411
447
|
# @param generics_to_erase [::Array<String>]
|
|
412
448
|
# @return [self]
|
|
413
|
-
def erase_generics
|
|
449
|
+
def erase_generics generics_to_erase
|
|
414
450
|
return self if generics_to_erase.empty?
|
|
415
451
|
transform_types { |t| t.erase_generics(generics_to_erase) }
|
|
416
452
|
end
|
|
@@ -418,6 +454,7 @@ module Solargraph
|
|
|
418
454
|
# @return [String, nil]
|
|
419
455
|
def filename
|
|
420
456
|
return nil if location.nil?
|
|
457
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
421
458
|
location.filename
|
|
422
459
|
end
|
|
423
460
|
|
|
@@ -452,12 +489,20 @@ module Solargraph
|
|
|
452
489
|
# @param other [Solargraph::Pin::Base, Object]
|
|
453
490
|
# @return [Boolean]
|
|
454
491
|
def nearly? other
|
|
455
|
-
|
|
492
|
+
instance_of?(other.class) &&
|
|
493
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
456
494
|
name == other.name &&
|
|
495
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
457
496
|
(closure == other.closure || (closure && closure.nearly?(other.closure))) &&
|
|
497
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
458
498
|
(comments == other.comments ||
|
|
459
|
-
|
|
460
|
-
|
|
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)) &&
|
|
504
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
505
|
+
compare_docstring_tags(docstring, other.docstring))
|
|
461
506
|
)
|
|
462
507
|
end
|
|
463
508
|
|
|
@@ -484,6 +529,7 @@ module Solargraph
|
|
|
484
529
|
@docstring ||= Solargraph::Source.parse_docstring('').to_docstring
|
|
485
530
|
end
|
|
486
531
|
|
|
532
|
+
# @sg-ignore parse_comments will always set @directives
|
|
487
533
|
# @return [::Array<YARD::Tags::Directive>]
|
|
488
534
|
def directives
|
|
489
535
|
parse_comments unless @directives
|
|
@@ -520,7 +566,7 @@ module Solargraph
|
|
|
520
566
|
# provided ApiMap.
|
|
521
567
|
#
|
|
522
568
|
# @param api_map [ApiMap]
|
|
523
|
-
# @return [ComplexType]
|
|
569
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
524
570
|
def typify api_map
|
|
525
571
|
return_type.qualify(api_map, *(closure&.gates || ['']))
|
|
526
572
|
end
|
|
@@ -528,16 +574,17 @@ module Solargraph
|
|
|
528
574
|
# Infer the pin's return type via static code analysis.
|
|
529
575
|
#
|
|
530
576
|
# @param api_map [ApiMap]
|
|
531
|
-
# @return [ComplexType]
|
|
577
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
532
578
|
def probe api_map
|
|
533
579
|
typify api_map
|
|
534
580
|
end
|
|
535
581
|
|
|
536
582
|
# @deprecated Use #typify and/or #probe instead
|
|
537
583
|
# @param api_map [ApiMap]
|
|
538
|
-
# @return [ComplexType]
|
|
584
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
539
585
|
def infer api_map
|
|
540
|
-
Solargraph
|
|
586
|
+
Solargraph.assert_or_log(:pin_infer,
|
|
587
|
+
'WARNING: Pin #infer methods are deprecated. Use #typify or #probe instead.')
|
|
541
588
|
type = typify(api_map)
|
|
542
589
|
return type unless type.undefined?
|
|
543
590
|
probe api_map
|
|
@@ -568,7 +615,7 @@ module Solargraph
|
|
|
568
615
|
# the return type and the #proxied? setting, the proxy should be a clone
|
|
569
616
|
# of the original.
|
|
570
617
|
#
|
|
571
|
-
# @param return_type [ComplexType]
|
|
618
|
+
# @param return_type [ComplexType, ComplexType::UniqueType, nil]
|
|
572
619
|
# @return [self]
|
|
573
620
|
def proxy return_type
|
|
574
621
|
result = dup
|
|
@@ -607,7 +654,7 @@ module Solargraph
|
|
|
607
654
|
rbs = return_type.rooted_tags if return_type.name == 'Class'
|
|
608
655
|
if path
|
|
609
656
|
if rbs
|
|
610
|
-
path
|
|
657
|
+
"#{path} #{rbs}"
|
|
611
658
|
else
|
|
612
659
|
path
|
|
613
660
|
end
|
|
@@ -618,7 +665,7 @@ module Solargraph
|
|
|
618
665
|
|
|
619
666
|
# @return [String]
|
|
620
667
|
def inner_desc
|
|
621
|
-
closure_info = closure&.
|
|
668
|
+
closure_info = closure&.name.inspect
|
|
622
669
|
binder_info = binder&.desc
|
|
623
670
|
"name=#{name.inspect} return_type=#{type_desc}, context=#{context.rooted_tags}, closure=#{closure_info}, binder=#{binder_info}"
|
|
624
671
|
end
|
|
@@ -630,7 +677,7 @@ module Solargraph
|
|
|
630
677
|
|
|
631
678
|
# @return [String]
|
|
632
679
|
def inspect
|
|
633
|
-
"#<#{self.class} `#{
|
|
680
|
+
"#<#{self.class} `#{inner_desc}`#{all_location_text} via #{source.inspect}>"
|
|
634
681
|
end
|
|
635
682
|
|
|
636
683
|
# @return [String]
|
|
@@ -646,24 +693,23 @@ module Solargraph
|
|
|
646
693
|
end
|
|
647
694
|
end
|
|
648
695
|
|
|
649
|
-
# @return [void]
|
|
650
|
-
def reset_generated!
|
|
651
|
-
end
|
|
652
|
-
|
|
653
696
|
protected
|
|
654
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
|
+
|
|
655
703
|
# @return [Boolean]
|
|
656
704
|
attr_writer :probed
|
|
657
705
|
|
|
658
706
|
# @return [Boolean]
|
|
659
707
|
attr_writer :proxied
|
|
660
708
|
|
|
661
|
-
# @return [ComplexType]
|
|
709
|
+
# @return [ComplexType, ComplexType::UniqueType, nil]
|
|
662
710
|
attr_writer :return_type
|
|
663
711
|
|
|
664
|
-
attr_writer :docstring
|
|
665
|
-
|
|
666
|
-
attr_writer :directives
|
|
712
|
+
attr_writer :docstring, :directives
|
|
667
713
|
|
|
668
714
|
private
|
|
669
715
|
|
|
@@ -685,13 +731,13 @@ module Solargraph
|
|
|
685
731
|
# True if two docstrings have the same tags, regardless of any other
|
|
686
732
|
# differences.
|
|
687
733
|
#
|
|
688
|
-
# @param
|
|
689
|
-
# @param
|
|
734
|
+
# @param docstring1 [YARD::Docstring]
|
|
735
|
+
# @param docstring2 [YARD::Docstring]
|
|
690
736
|
# @return [Boolean]
|
|
691
|
-
def compare_docstring_tags
|
|
692
|
-
return false if
|
|
693
|
-
|
|
694
|
-
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])
|
|
695
741
|
end
|
|
696
742
|
true
|
|
697
743
|
end
|
|
@@ -711,7 +757,7 @@ module Solargraph
|
|
|
711
757
|
# @param tag2 [YARD::Tags::Tag]
|
|
712
758
|
# @return [Boolean]
|
|
713
759
|
def compare_tags tag1, tag2
|
|
714
|
-
tag1.
|
|
760
|
+
tag1.instance_of?(tag2.class) &&
|
|
715
761
|
tag1.tag_name == tag2.tag_name &&
|
|
716
762
|
tag1.text == tag2.text &&
|
|
717
763
|
tag1.name == tag2.name &&
|
|
@@ -722,7 +768,7 @@ module Solargraph
|
|
|
722
768
|
def collect_macros
|
|
723
769
|
return [] unless maybe_directives?
|
|
724
770
|
parse = Solargraph::Source.parse_docstring(comments)
|
|
725
|
-
parse.directives.select{ |d| d.tag.tag_name == 'macro' }
|
|
771
|
+
parse.directives.select { |d| d.tag.tag_name == 'macro' }
|
|
726
772
|
end
|
|
727
773
|
end
|
|
728
774
|
end
|