solargraph 0.58.3 → 0.59.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 +12 -5
- data/.github/workflows/plugins.yml +54 -34
- data/.github/workflows/rspec.yml +15 -28
- data/.github/workflows/typecheck.yml +6 -3
- data/.rubocop.yml +38 -6
- data/.rubocop_todo.yml +53 -966
- data/CHANGELOG.md +24 -0
- 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 +12 -3
- data/lib/solargraph/api_map/index.rb +29 -18
- data/lib/solargraph/api_map/source_to_yard.rb +22 -9
- data/lib/solargraph/api_map/store.rb +40 -30
- data/lib/solargraph/api_map.rb +160 -78
- data/lib/solargraph/bench.rb +2 -3
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +31 -18
- data/lib/solargraph/complex_type/unique_type.rb +221 -63
- data/lib/solargraph/complex_type.rb +173 -59
- data/lib/solargraph/convention/active_support_concern.rb +111 -111
- data/lib/solargraph/convention/base.rb +50 -50
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +1 -1
- 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 +1 -1
- data/lib/solargraph/convention/gemspec.rb +1 -1
- data/lib/solargraph/convention/rakefile.rb +1 -1
- 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 +2 -2
- data/lib/solargraph/converters/dd.rb +2 -0
- data/lib/solargraph/converters/dl.rb +2 -0
- data/lib/solargraph/converters/dt.rb +2 -0
- data/lib/solargraph/converters/misc.rb +2 -0
- 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 +4 -8
- data/lib/solargraph/diagnostics.rb +55 -55
- data/lib/solargraph/doc_map.rb +38 -39
- data/lib/solargraph/environ.rb +52 -52
- data/lib/solargraph/equality.rb +4 -4
- data/lib/solargraph/gem_pins.rb +4 -15
- data/lib/solargraph/language_server/error_codes.rb +10 -10
- 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 +35 -28
- data/lib/solargraph/language_server/message/base.rb +1 -1
- data/lib/solargraph/language_server/message/client/register_capability.rb +1 -3
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +6 -8
- 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 +7 -7
- data/lib/solargraph/language_server/message/extended/download_core.rb +2 -1
- data/lib/solargraph/language_server/message/extended/environment.rb +25 -25
- data/lib/solargraph/language_server/message/extended/search.rb +1 -1
- data/lib/solargraph/language_server/message/initialize.rb +20 -14
- data/lib/solargraph/language_server/message/initialized.rb +28 -28
- 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 +17 -10
- 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 +13 -6
- data/lib/solargraph/language_server/message/text_document/references.rb +17 -10
- data/lib/solargraph/language_server/message/text_document/rename.rb +20 -13
- 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/text_document.rb +28 -28
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +34 -28
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +38 -30
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +23 -17
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -17
- data/lib/solargraph/language_server/message.rb +1 -1
- data/lib/solargraph/language_server/progress.rb +143 -143
- data/lib/solargraph/language_server/request.rb +4 -2
- data/lib/solargraph/language_server/transport/adapter.rb +68 -68
- data/lib/solargraph/language_server/transport/data_reader.rb +11 -13
- data/lib/solargraph/language_server/uri_helpers.rb +2 -2
- data/lib/solargraph/language_server.rb +20 -20
- data/lib/solargraph/library.rb +57 -38
- data/lib/solargraph/location.rb +17 -14
- data/lib/solargraph/logging.rb +22 -4
- data/lib/solargraph/page.rb +1 -1
- data/lib/solargraph/parser/comment_ripper.rb +19 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +324 -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 +30 -14
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +51 -25
- data/lib/solargraph/parser/parser_gem/node_methods.rb +181 -73
- data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +24 -24
- 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 +11 -12
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +36 -36
- data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +24 -24
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +10 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +9 -8
- data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +24 -24
- 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/namespace_node.rb +40 -40
- 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/sym_node.rb +20 -20
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +1 -1
- 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 +2 -0
- data/lib/solargraph/parser/region.rb +9 -3
- data/lib/solargraph/parser/snippet.rb +3 -1
- data/lib/solargraph/parser.rb +2 -0
- data/lib/solargraph/pin/base.rb +126 -82
- 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 +3 -5
- 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 +158 -104
- data/lib/solargraph/pin/method_alias.rb +8 -0
- data/lib/solargraph/pin/namespace.rb +19 -12
- data/lib/solargraph/pin/parameter.rb +102 -36
- data/lib/solargraph/pin/proxy_type.rb +4 -1
- data/lib/solargraph/pin/reference/override.rb +1 -1
- data/lib/solargraph/pin/reference/require.rb +14 -14
- data/lib/solargraph/pin/reference/superclass.rb +2 -0
- data/lib/solargraph/pin/reference/type_alias.rb +16 -0
- data/lib/solargraph/pin/reference.rb +20 -0
- data/lib/solargraph/pin/search.rb +8 -7
- data/lib/solargraph/pin/signature.rb +15 -12
- data/lib/solargraph/pin/singleton.rb +11 -11
- 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 +22 -19
- data/lib/solargraph/position.rb +17 -10
- data/lib/solargraph/range.rb +16 -15
- data/lib/solargraph/rbs_map/conversions.rb +367 -231
- data/lib/solargraph/rbs_map/core_fills.rb +18 -11
- 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 +76 -32
- data/lib/solargraph/server_methods.rb +1 -1
- data/lib/solargraph/shell.rb +258 -66
- data/lib/solargraph/source/chain/array.rb +3 -12
- data/lib/solargraph/source/chain/block_symbol.rb +13 -13
- data/lib/solargraph/source/chain/block_variable.rb +13 -13
- data/lib/solargraph/source/chain/call.rb +96 -56
- data/lib/solargraph/source/chain/class_variable.rb +1 -1
- data/lib/solargraph/source/chain/constant.rb +5 -1
- data/lib/solargraph/source/chain/global_variable.rb +1 -1
- data/lib/solargraph/source/chain/hash.rb +8 -5
- data/lib/solargraph/source/chain/head.rb +19 -19
- 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 +12 -22
- data/lib/solargraph/source/chain/literal.rb +22 -15
- data/lib/solargraph/source/chain/or.rb +10 -4
- data/lib/solargraph/source/chain/q_call.rb +2 -0
- data/lib/solargraph/source/chain/variable.rb +3 -1
- data/lib/solargraph/source/chain/z_super.rb +1 -3
- data/lib/solargraph/source/chain.rb +51 -38
- data/lib/solargraph/source/change.rb +12 -5
- data/lib/solargraph/source/cursor.rb +33 -18
- 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 +54 -30
- data/lib/solargraph/source_map/data.rb +4 -1
- data/lib/solargraph/source_map/mapper.rb +69 -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 +196 -122
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +14 -11
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +1 -0
- data/lib/solargraph/workspace.rb +50 -28
- data/lib/solargraph/yard_map/cache.rb +25 -25
- data/lib/solargraph/yard_map/helpers.rb +8 -3
- data/lib/solargraph/yard_map/mapper/to_constant.rb +28 -28
- 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_map.rb +17 -18
- data/lib/solargraph/yard_tags.rb +2 -2
- data/lib/solargraph/yardoc.rb +7 -4
- data/lib/solargraph.rb +33 -10
- data/rbs/fills/rubygems/0/dependency.rbs +193 -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 +37 -35
- metadata +41 -42
- 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/rbs/fills/tuple/tuple.rbs +0 -149
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,17 @@ 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
|
+
return true if results.any? { |r| [true, false].include?(r) }
|
|
245
|
+
return results.first if results.any? { |r| r.is_a? AST::Node }
|
|
221
246
|
results.min
|
|
222
|
-
rescue
|
|
223
|
-
|
|
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}")
|
|
224
249
|
raise
|
|
225
250
|
end
|
|
226
251
|
|
|
@@ -228,7 +253,7 @@ module Solargraph
|
|
|
228
253
|
# @param attr [::Symbol]
|
|
229
254
|
# @sg-ignore
|
|
230
255
|
# @return [undefined]
|
|
231
|
-
def choose_node
|
|
256
|
+
def choose_node other, attr
|
|
232
257
|
if other.object_id < attr.object_id
|
|
233
258
|
other.send(attr)
|
|
234
259
|
else
|
|
@@ -240,9 +265,9 @@ module Solargraph
|
|
|
240
265
|
# @param attr [::Symbol]
|
|
241
266
|
# @sg-ignore
|
|
242
267
|
# @return [undefined]
|
|
243
|
-
def prefer_rbs_location
|
|
268
|
+
def prefer_rbs_location other, attr
|
|
244
269
|
if rbs_location? && !other.rbs_location?
|
|
245
|
-
|
|
270
|
+
send(attr)
|
|
246
271
|
elsif !rbs_location? && other.rbs_location?
|
|
247
272
|
other.send(attr)
|
|
248
273
|
else
|
|
@@ -250,14 +275,15 @@ module Solargraph
|
|
|
250
275
|
end
|
|
251
276
|
end
|
|
252
277
|
|
|
278
|
+
# @sg-ignore need boolish support for ? methods
|
|
253
279
|
def rbs_location?
|
|
254
280
|
type_location&.rbs?
|
|
255
281
|
end
|
|
256
282
|
|
|
257
283
|
# @param other [self]
|
|
258
284
|
# @return [void]
|
|
259
|
-
def assert_same_macros
|
|
260
|
-
return unless
|
|
285
|
+
def assert_same_macros other
|
|
286
|
+
return unless source == :yardoc && other.source == :yardoc
|
|
261
287
|
assert_same_count(other, :macros)
|
|
262
288
|
# @param [YARD::Tags::MacroDirective]
|
|
263
289
|
assert_same_array_content(other, :macros) { |macro| macro.tag.name }
|
|
@@ -267,7 +293,7 @@ module Solargraph
|
|
|
267
293
|
# @param attr [::Symbol]
|
|
268
294
|
# @return [void]
|
|
269
295
|
# @todo strong typechecking should complain when there are no block-related tags
|
|
270
|
-
def assert_same_array_content(other, attr, &
|
|
296
|
+
def assert_same_array_content(other, attr, &)
|
|
271
297
|
arr1 = send(attr)
|
|
272
298
|
raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
|
|
273
299
|
# @type arr1 [::Enumerable]
|
|
@@ -276,12 +302,12 @@ module Solargraph
|
|
|
276
302
|
# @type arr2 [::Enumerable]
|
|
277
303
|
|
|
278
304
|
# @type [undefined]
|
|
279
|
-
values1 = arr1.map(&
|
|
305
|
+
values1 = arr1.map(&)
|
|
280
306
|
# @type [undefined]
|
|
281
|
-
values2 = arr2.map(&
|
|
307
|
+
values2 = arr2.map(&)
|
|
282
308
|
# @sg-ignore
|
|
283
309
|
return arr1 if values1 == values2
|
|
284
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
310
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
285
311
|
"Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self values = #{values1}\nother values =#{attr} = #{values2}")
|
|
286
312
|
arr1
|
|
287
313
|
end
|
|
@@ -290,15 +316,15 @@ module Solargraph
|
|
|
290
316
|
# @param attr [::Symbol]
|
|
291
317
|
#
|
|
292
318
|
# @return [::Enumerable]
|
|
293
|
-
def assert_same_count
|
|
319
|
+
def assert_same_count other, attr
|
|
294
320
|
# @type [::Enumerable]
|
|
295
|
-
arr1 =
|
|
321
|
+
arr1 = send(attr)
|
|
296
322
|
raise "Expected #{attr} on #{self} to be an Enumerable, got #{arr1.class}" unless arr1.is_a?(::Enumerable)
|
|
297
323
|
# @type [::Enumerable]
|
|
298
324
|
arr2 = other.send(attr)
|
|
299
325
|
raise "Expected #{attr} on #{other} to be an Enumerable, got #{arr2.class}" unless arr2.is_a?(::Enumerable)
|
|
300
326
|
return arr1 if arr1.count == arr2.count
|
|
301
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
327
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
302
328
|
"Inconsistent #{attr.inspect} count value between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{arr1.inspect}\nother.#{attr} = #{arr2.inspect}")
|
|
303
329
|
arr1
|
|
304
330
|
end
|
|
@@ -308,12 +334,16 @@ module Solargraph
|
|
|
308
334
|
#
|
|
309
335
|
# @sg-ignore
|
|
310
336
|
# @return [undefined]
|
|
311
|
-
def assert_same
|
|
312
|
-
|
|
337
|
+
def assert_same other, attr
|
|
338
|
+
if other.nil?
|
|
339
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_nil",
|
|
340
|
+
"Other was passed in nil in assert_same on #{self}")
|
|
341
|
+
return send(attr)
|
|
342
|
+
end
|
|
313
343
|
val1 = send(attr)
|
|
314
344
|
val2 = other.send(attr)
|
|
315
345
|
return val1 if val1 == val2
|
|
316
|
-
Solargraph.assert_or_log("combine_with_#{attr}"
|
|
346
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}",
|
|
317
347
|
"Inconsistent #{attr.inspect} values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
318
348
|
val1
|
|
319
349
|
end
|
|
@@ -322,15 +352,17 @@ module Solargraph
|
|
|
322
352
|
# @param attr [::Symbol]
|
|
323
353
|
# @sg-ignore
|
|
324
354
|
# @return [undefined]
|
|
325
|
-
def choose_pin_attr_with_same_name
|
|
355
|
+
def choose_pin_attr_with_same_name other, attr
|
|
326
356
|
# @type [Pin::Base, nil]
|
|
327
357
|
val1 = send(attr)
|
|
328
358
|
# @type [Pin::Base, nil]
|
|
329
359
|
val2 = other.send(attr)
|
|
330
|
-
raise "Expected pin for #{attr} on\n#{
|
|
331
|
-
|
|
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
|
|
332
364
|
if val1&.name != val2&.name
|
|
333
|
-
Solargraph.assert_or_log("combine_with_#{attr}_name"
|
|
365
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_name",
|
|
334
366
|
"Inconsistent #{attr.inspect} name values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
335
367
|
end
|
|
336
368
|
choose_pin_attr(other, attr)
|
|
@@ -341,14 +373,14 @@ module Solargraph
|
|
|
341
373
|
#
|
|
342
374
|
# @sg-ignore Missing @return tag for Solargraph::Pin::Base#choose_pin_attr
|
|
343
375
|
# @return [undefined]
|
|
344
|
-
def choose_pin_attr
|
|
376
|
+
def choose_pin_attr other, attr
|
|
345
377
|
# @type [Pin::Base, nil]
|
|
346
378
|
val1 = send(attr)
|
|
347
379
|
# @type [Pin::Base, nil]
|
|
348
380
|
val2 = other.send(attr)
|
|
349
381
|
if val1.class != val2.class
|
|
350
382
|
# :nocov:
|
|
351
|
-
Solargraph.assert_or_log("combine_with_#{attr}_class"
|
|
383
|
+
Solargraph.assert_or_log(:"combine_with_#{attr}_class",
|
|
352
384
|
"Inconsistent #{attr.inspect} class values between \nself =#{inspect} and \nother=#{other.inspect}:\n\n self.#{attr} = #{val1.inspect}\nother.#{attr} = #{val2.inspect}")
|
|
353
385
|
return val1
|
|
354
386
|
# :nocov:
|
|
@@ -358,8 +390,11 @@ module Solargraph
|
|
|
358
390
|
[
|
|
359
391
|
# maximize number of gates, as types in other combined pins may
|
|
360
392
|
# depend on those gates
|
|
393
|
+
|
|
394
|
+
# @sg-ignore Need better handling of #compact
|
|
361
395
|
closure.gates.length,
|
|
362
396
|
# use basename so that results don't vary system to system
|
|
397
|
+
# @sg-ignore Need better handling of #compact
|
|
363
398
|
File.basename(closure.best_location.to_s)
|
|
364
399
|
]
|
|
365
400
|
end
|
|
@@ -376,11 +411,10 @@ module Solargraph
|
|
|
376
411
|
end
|
|
377
412
|
|
|
378
413
|
# @param generics_to_resolve [Enumerable<String>]
|
|
379
|
-
# @param return_type_context [ComplexType, nil]
|
|
380
|
-
# @param context [ComplexType]
|
|
414
|
+
# @param return_type_context [ComplexType, ComplexType::UniqueType, nil]
|
|
381
415
|
# @param resolved_generic_values [Hash{String => ComplexType}]
|
|
382
416
|
# @return [self]
|
|
383
|
-
def resolve_generics_from_context
|
|
417
|
+
def resolve_generics_from_context generics_to_resolve, return_type_context = nil, resolved_generic_values: {}
|
|
384
418
|
proxy return_type.resolve_generics_from_context(generics_to_resolve,
|
|
385
419
|
return_type_context,
|
|
386
420
|
resolved_generic_values: resolved_generic_values)
|
|
@@ -389,7 +423,7 @@ module Solargraph
|
|
|
389
423
|
# @yieldparam [ComplexType]
|
|
390
424
|
# @yieldreturn [ComplexType]
|
|
391
425
|
# @return [self]
|
|
392
|
-
def transform_types
|
|
426
|
+
def transform_types &transform
|
|
393
427
|
proxy return_type.transform(&transform)
|
|
394
428
|
end
|
|
395
429
|
|
|
@@ -401,7 +435,7 @@ module Solargraph
|
|
|
401
435
|
# @param context_type [ComplexType] The receiver type
|
|
402
436
|
# @return [self]
|
|
403
437
|
def resolve_generics definitions, context_type
|
|
404
|
-
transform_types { |t| t
|
|
438
|
+
transform_types { |t| t&.resolve_generics(definitions, context_type) }
|
|
405
439
|
end
|
|
406
440
|
|
|
407
441
|
def all_rooted?
|
|
@@ -410,7 +444,7 @@ module Solargraph
|
|
|
410
444
|
|
|
411
445
|
# @param generics_to_erase [::Array<String>]
|
|
412
446
|
# @return [self]
|
|
413
|
-
def erase_generics
|
|
447
|
+
def erase_generics generics_to_erase
|
|
414
448
|
return self if generics_to_erase.empty?
|
|
415
449
|
transform_types { |t| t.erase_generics(generics_to_erase) }
|
|
416
450
|
end
|
|
@@ -418,6 +452,7 @@ module Solargraph
|
|
|
418
452
|
# @return [String, nil]
|
|
419
453
|
def filename
|
|
420
454
|
return nil if location.nil?
|
|
455
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
421
456
|
location.filename
|
|
422
457
|
end
|
|
423
458
|
|
|
@@ -452,12 +487,20 @@ module Solargraph
|
|
|
452
487
|
# @param other [Solargraph::Pin::Base, Object]
|
|
453
488
|
# @return [Boolean]
|
|
454
489
|
def nearly? other
|
|
455
|
-
|
|
490
|
+
instance_of?(other.class) &&
|
|
491
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
456
492
|
name == other.name &&
|
|
493
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
457
494
|
(closure == other.closure || (closure && closure.nearly?(other.closure))) &&
|
|
495
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
458
496
|
(comments == other.comments ||
|
|
459
|
-
|
|
460
|
-
|
|
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)) &&
|
|
502
|
+
# @sg-ignore Translate to something flow sensitive typing understands
|
|
503
|
+
compare_docstring_tags(docstring, other.docstring))
|
|
461
504
|
)
|
|
462
505
|
end
|
|
463
506
|
|
|
@@ -484,6 +527,7 @@ module Solargraph
|
|
|
484
527
|
@docstring ||= Solargraph::Source.parse_docstring('').to_docstring
|
|
485
528
|
end
|
|
486
529
|
|
|
530
|
+
# @sg-ignore parse_comments will always set @directives
|
|
487
531
|
# @return [::Array<YARD::Tags::Directive>]
|
|
488
532
|
def directives
|
|
489
533
|
parse_comments unless @directives
|
|
@@ -520,7 +564,7 @@ module Solargraph
|
|
|
520
564
|
# provided ApiMap.
|
|
521
565
|
#
|
|
522
566
|
# @param api_map [ApiMap]
|
|
523
|
-
# @return [ComplexType]
|
|
567
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
524
568
|
def typify api_map
|
|
525
569
|
return_type.qualify(api_map, *(closure&.gates || ['']))
|
|
526
570
|
end
|
|
@@ -528,16 +572,17 @@ module Solargraph
|
|
|
528
572
|
# Infer the pin's return type via static code analysis.
|
|
529
573
|
#
|
|
530
574
|
# @param api_map [ApiMap]
|
|
531
|
-
# @return [ComplexType]
|
|
575
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
532
576
|
def probe api_map
|
|
533
577
|
typify api_map
|
|
534
578
|
end
|
|
535
579
|
|
|
536
580
|
# @deprecated Use #typify and/or #probe instead
|
|
537
581
|
# @param api_map [ApiMap]
|
|
538
|
-
# @return [ComplexType]
|
|
582
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
539
583
|
def infer api_map
|
|
540
|
-
Solargraph
|
|
584
|
+
Solargraph.assert_or_log(:pin_infer,
|
|
585
|
+
'WARNING: Pin #infer methods are deprecated. Use #typify or #probe instead.')
|
|
541
586
|
type = typify(api_map)
|
|
542
587
|
return type unless type.undefined?
|
|
543
588
|
probe api_map
|
|
@@ -568,7 +613,7 @@ module Solargraph
|
|
|
568
613
|
# the return type and the #proxied? setting, the proxy should be a clone
|
|
569
614
|
# of the original.
|
|
570
615
|
#
|
|
571
|
-
# @param return_type [ComplexType]
|
|
616
|
+
# @param return_type [ComplexType, ComplexType::UniqueType, nil]
|
|
572
617
|
# @return [self]
|
|
573
618
|
def proxy return_type
|
|
574
619
|
result = dup
|
|
@@ -607,7 +652,7 @@ module Solargraph
|
|
|
607
652
|
rbs = return_type.rooted_tags if return_type.name == 'Class'
|
|
608
653
|
if path
|
|
609
654
|
if rbs
|
|
610
|
-
path
|
|
655
|
+
"#{path} #{rbs}"
|
|
611
656
|
else
|
|
612
657
|
path
|
|
613
658
|
end
|
|
@@ -618,7 +663,7 @@ module Solargraph
|
|
|
618
663
|
|
|
619
664
|
# @return [String]
|
|
620
665
|
def inner_desc
|
|
621
|
-
closure_info = closure&.
|
|
666
|
+
closure_info = closure&.name.inspect
|
|
622
667
|
binder_info = binder&.desc
|
|
623
668
|
"name=#{name.inspect} return_type=#{type_desc}, context=#{context.rooted_tags}, closure=#{closure_info}, binder=#{binder_info}"
|
|
624
669
|
end
|
|
@@ -630,7 +675,7 @@ module Solargraph
|
|
|
630
675
|
|
|
631
676
|
# @return [String]
|
|
632
677
|
def inspect
|
|
633
|
-
"#<#{self.class} `#{
|
|
678
|
+
"#<#{self.class} `#{inner_desc}`#{all_location_text} via #{source.inspect}>"
|
|
634
679
|
end
|
|
635
680
|
|
|
636
681
|
# @return [String]
|
|
@@ -646,24 +691,23 @@ module Solargraph
|
|
|
646
691
|
end
|
|
647
692
|
end
|
|
648
693
|
|
|
649
|
-
# @return [void]
|
|
650
|
-
def reset_generated!
|
|
651
|
-
end
|
|
652
|
-
|
|
653
694
|
protected
|
|
654
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
|
+
|
|
655
701
|
# @return [Boolean]
|
|
656
702
|
attr_writer :probed
|
|
657
703
|
|
|
658
704
|
# @return [Boolean]
|
|
659
705
|
attr_writer :proxied
|
|
660
706
|
|
|
661
|
-
# @return [ComplexType]
|
|
707
|
+
# @return [ComplexType, ComplexType::UniqueType, nil]
|
|
662
708
|
attr_writer :return_type
|
|
663
709
|
|
|
664
|
-
attr_writer :docstring
|
|
665
|
-
|
|
666
|
-
attr_writer :directives
|
|
710
|
+
attr_writer :docstring, :directives
|
|
667
711
|
|
|
668
712
|
private
|
|
669
713
|
|
|
@@ -685,13 +729,13 @@ module Solargraph
|
|
|
685
729
|
# True if two docstrings have the same tags, regardless of any other
|
|
686
730
|
# differences.
|
|
687
731
|
#
|
|
688
|
-
# @param
|
|
689
|
-
# @param
|
|
732
|
+
# @param docstring1 [YARD::Docstring]
|
|
733
|
+
# @param docstring2 [YARD::Docstring]
|
|
690
734
|
# @return [Boolean]
|
|
691
|
-
def compare_docstring_tags
|
|
692
|
-
return false if
|
|
693
|
-
|
|
694
|
-
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])
|
|
695
739
|
end
|
|
696
740
|
true
|
|
697
741
|
end
|
|
@@ -711,7 +755,7 @@ module Solargraph
|
|
|
711
755
|
# @param tag2 [YARD::Tags::Tag]
|
|
712
756
|
# @return [Boolean]
|
|
713
757
|
def compare_tags tag1, tag2
|
|
714
|
-
tag1.
|
|
758
|
+
tag1.instance_of?(tag2.class) &&
|
|
715
759
|
tag1.tag_name == tag2.tag_name &&
|
|
716
760
|
tag1.text == tag2.text &&
|
|
717
761
|
tag1.name == tag2.name &&
|
|
@@ -722,7 +766,7 @@ module Solargraph
|
|
|
722
766
|
def collect_macros
|
|
723
767
|
return [] unless maybe_directives?
|
|
724
768
|
parse = Solargraph::Source.parse_docstring(comments)
|
|
725
|
-
parse.directives.select{ |d| d.tag.tag_name == 'macro' }
|
|
769
|
+
parse.directives.select { |d| d.tag.tag_name == 'macro' }
|
|
726
770
|
end
|
|
727
771
|
end
|
|
728
772
|
end
|