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
|
@@ -28,18 +28,14 @@ module Solargraph
|
|
|
28
28
|
# @param arguments [::Array<Chain>]
|
|
29
29
|
# @param block [Chain, nil]
|
|
30
30
|
def initialize word, location = nil, arguments = [], block = nil
|
|
31
|
-
|
|
31
|
+
super(word)
|
|
32
|
+
|
|
32
33
|
@location = location
|
|
33
34
|
@arguments = arguments
|
|
34
35
|
@block = block
|
|
35
36
|
fix_block_pass
|
|
36
37
|
end
|
|
37
38
|
|
|
38
|
-
# @sg-ignore Fix "Not enough arguments to Module#protected"
|
|
39
|
-
protected def equality_fields
|
|
40
|
-
super + [arguments, block]
|
|
41
|
-
end
|
|
42
|
-
|
|
43
39
|
def with_block?
|
|
44
40
|
!!@block
|
|
45
41
|
end
|
|
@@ -50,24 +46,32 @@ module Solargraph
|
|
|
50
46
|
def resolve api_map, name_pin, locals
|
|
51
47
|
return super_pins(api_map, name_pin) if word == 'super'
|
|
52
48
|
return yield_pins(api_map, name_pin) if word == 'yield'
|
|
53
|
-
found = if head?
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
found = api_map.var_at_location(locals, word, name_pin, location) if head?
|
|
50
|
+
|
|
51
|
+
return inferred_pins([found], api_map, name_pin, locals) unless found.nil?
|
|
52
|
+
binder = name_pin.binder
|
|
53
|
+
# this is a q_call - i.e., foo&.bar - assume result of call
|
|
54
|
+
# will be nil or result as if binder were not nil -
|
|
55
|
+
# chain.rb#maybe_nil will add the nil type later, we just
|
|
56
|
+
# need to worry about the not-nil case
|
|
57
|
+
|
|
58
|
+
# @sg-ignore Need to handle duck-typed method calls on union types
|
|
59
|
+
binder = binder.without_nil if nullable?
|
|
60
|
+
# @sg-ignore Need to handle duck-typed method calls on union types
|
|
61
|
+
pin_groups = binder.each_unique_type.map do |context|
|
|
60
62
|
ns_tag = context.namespace == '' ? '' : context.namespace_type.tag
|
|
61
63
|
stack = api_map.get_method_stack(ns_tag, word, scope: context.scope)
|
|
62
64
|
[stack.first].compact
|
|
63
65
|
end
|
|
66
|
+
pin_groups = [] if !api_map.loose_unions && pin_groups.any?(&:empty?)
|
|
67
|
+
pins = pin_groups.flatten.uniq(&:path)
|
|
64
68
|
return [] if pins.empty?
|
|
65
69
|
inferred_pins(pins, api_map, name_pin, locals)
|
|
66
70
|
end
|
|
67
71
|
|
|
68
72
|
private
|
|
69
73
|
|
|
70
|
-
# @param pins [::Enumerable<Pin::
|
|
74
|
+
# @param pins [::Enumerable<Pin::Base>]
|
|
71
75
|
# @param api_map [ApiMap]
|
|
72
76
|
# @param name_pin [Pin::Base]
|
|
73
77
|
# @param locals [::Array<Solargraph::Pin::LocalVariable, Solargraph::Pin::Parameter>]
|
|
@@ -84,9 +88,13 @@ module Solargraph
|
|
|
84
88
|
# reject it regardless
|
|
85
89
|
|
|
86
90
|
with_block, without_block = overloads.partition(&:block?)
|
|
91
|
+
# @sg-ignore flow sensitive typing should handle is_a? and next
|
|
92
|
+
# @type Array<Pin::Signature>
|
|
87
93
|
sorted_overloads = with_block + without_block
|
|
88
94
|
# @type [Pin::Signature, nil]
|
|
89
95
|
new_signature_pin = nil
|
|
96
|
+
# @sg-ignore flow sensitive typing should handle is_a? and next
|
|
97
|
+
# @param ol [Pin::Signature]
|
|
90
98
|
sorted_overloads.each do |ol|
|
|
91
99
|
next unless ol.arity_matches?(arguments, with_block?)
|
|
92
100
|
match = true
|
|
@@ -99,6 +107,7 @@ module Solargraph
|
|
|
99
107
|
break
|
|
100
108
|
end
|
|
101
109
|
arg_name_pin = Pin::ProxyType.anonymous(name_pin.context,
|
|
110
|
+
closure: name_pin.closure,
|
|
102
111
|
gates: name_pin.gates,
|
|
103
112
|
source: :chain)
|
|
104
113
|
atype = atypes[idx] ||= arg.infer(api_map, arg_name_pin, locals)
|
|
@@ -110,37 +119,43 @@ module Solargraph
|
|
|
110
119
|
if match
|
|
111
120
|
if ol.block && with_block?
|
|
112
121
|
block_atypes = ol.block.parameters.map(&:return_type)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
# @todo Need to add nil check here
|
|
123
|
+
blocktype = if block.links.map(&:class) == [BlockSymbol]
|
|
124
|
+
# like the bar in foo(&:bar)
|
|
125
|
+
block_symbol_call_type(api_map, name_pin.context, block_atypes, locals)
|
|
126
|
+
else
|
|
127
|
+
block_call_type(api_map, name_pin, locals)
|
|
128
|
+
end
|
|
119
129
|
end
|
|
120
130
|
# @type new_signature_pin [Pin::Signature]
|
|
121
|
-
new_signature_pin = ol.resolve_generics_from_context_until_complete(ol.generics, atypes, nil, nil,
|
|
131
|
+
new_signature_pin = ol.resolve_generics_from_context_until_complete(ol.generics, atypes, nil, nil,
|
|
132
|
+
blocktype)
|
|
122
133
|
new_return_type = new_signature_pin.return_type
|
|
123
|
-
if head?
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
self_type = if head?
|
|
135
|
+
# If we're at the head of the chain, we called a
|
|
136
|
+
# method somewhere that marked itself as returning
|
|
137
|
+
# self. Given we didn't invoke this on an object,
|
|
138
|
+
# this must be a method in this same class - so we
|
|
139
|
+
# use our own self type
|
|
140
|
+
name_pin.context
|
|
141
|
+
else
|
|
142
|
+
# if we're past the head in the chain, whatever the
|
|
143
|
+
# type of the lhs side is what 'self' will be in its
|
|
144
|
+
# declaration - we can't just use the type of the
|
|
145
|
+
# method pin, as this might be a subclass of the
|
|
146
|
+
# place where the method is defined
|
|
147
|
+
name_pin.binder
|
|
148
|
+
end
|
|
138
149
|
# This same logic applies to the YARD work done by
|
|
139
150
|
# 'with_params()'.
|
|
140
151
|
#
|
|
141
152
|
# qualify(), however, happens in the namespace where
|
|
142
153
|
# the docs were written - from the method pin.
|
|
143
|
-
|
|
154
|
+
# @todo Need to add nil check here
|
|
155
|
+
if new_return_type.defined?
|
|
156
|
+
type = with_params(new_return_type.self_to_type(self_type), self_type).qualify(api_map,
|
|
157
|
+
*p.gates)
|
|
158
|
+
end
|
|
144
159
|
type ||= ComplexType::UNDEFINED
|
|
145
160
|
end
|
|
146
161
|
break if type.defined?
|
|
@@ -149,21 +164,28 @@ module Solargraph
|
|
|
149
164
|
next p.proxy(type) if type.defined?
|
|
150
165
|
if !p.macros.empty?
|
|
151
166
|
result = process_macro(p, api_map, name_pin.context, locals)
|
|
167
|
+
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
152
168
|
next result unless result.return_type.undefined?
|
|
153
169
|
elsif !p.directives.empty?
|
|
154
170
|
result = process_directive(p, api_map, name_pin.context, locals)
|
|
171
|
+
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
155
172
|
next result unless result.return_type.undefined?
|
|
156
173
|
end
|
|
157
174
|
p
|
|
158
175
|
end
|
|
159
|
-
logger.debug
|
|
160
|
-
|
|
176
|
+
logger.debug do
|
|
177
|
+
"Call#inferred_pins(name_pin.binder=#{name_pin.binder}, word=#{word}, pins=#{pins.map(&:desc)}, name_pin=#{name_pin}) - result=#{result}"
|
|
178
|
+
end
|
|
179
|
+
result.map do |pin|
|
|
161
180
|
if pin.path == 'Class#new' && name_pin.binder.tag != 'Class'
|
|
162
181
|
reduced_context = name_pin.binder.reduce_class_type
|
|
163
182
|
pin.proxy(reduced_context)
|
|
164
183
|
else
|
|
184
|
+
# @sg-ignore Need to add nil check here
|
|
165
185
|
next pin if pin.return_type.undefined?
|
|
186
|
+
# @sg-ignore Need to add nil check here
|
|
166
187
|
selfy = pin.return_type.self_to_type(name_pin.binder)
|
|
188
|
+
# @sg-ignore Need to add nil check here
|
|
167
189
|
selfy == pin.return_type ? pin : pin.proxy(selfy)
|
|
168
190
|
end
|
|
169
191
|
end
|
|
@@ -171,7 +193,7 @@ module Solargraph
|
|
|
171
193
|
|
|
172
194
|
# @param pin [Pin::Base]
|
|
173
195
|
# @param api_map [ApiMap]
|
|
174
|
-
# @param context [ComplexType]
|
|
196
|
+
# @param context [ComplexType, ComplexType::UniqueType]
|
|
175
197
|
# @param locals [::Array<Solargraph::Pin::LocalVariable, Solargraph::Pin::Parameter>]
|
|
176
198
|
# @return [Pin::Base]
|
|
177
199
|
def process_macro pin, api_map, context, locals
|
|
@@ -190,7 +212,7 @@ module Solargraph
|
|
|
190
212
|
|
|
191
213
|
# @param pin [Pin::Method]
|
|
192
214
|
# @param api_map [ApiMap]
|
|
193
|
-
# @param context [ComplexType]
|
|
215
|
+
# @param context [ComplexType, ComplexType::UniqueType]
|
|
194
216
|
# @param locals [::Array<Solargraph::Pin::LocalVariable, Solargraph::Pin::Parameter>]
|
|
195
217
|
# @return [Pin::ProxyType]
|
|
196
218
|
def process_directive pin, api_map, context, locals
|
|
@@ -206,21 +228,24 @@ module Solargraph
|
|
|
206
228
|
# @param pin [Pin::Base]
|
|
207
229
|
# @param macro [YARD::Tags::MacroDirective]
|
|
208
230
|
# @param api_map [ApiMap]
|
|
209
|
-
# @param context [ComplexType]
|
|
231
|
+
# @param context [ComplexType, ComplexType::UniqueType]
|
|
210
232
|
# @param locals [::Array<Pin::LocalVariable, Pin::Parameter>]
|
|
211
233
|
# @return [Pin::ProxyType]
|
|
212
234
|
def inner_process_macro pin, macro, api_map, context, locals
|
|
213
|
-
vals = arguments.map{ |c| Pin::ProxyType.anonymous(c.infer(api_map, pin, locals), source: :chain) }
|
|
235
|
+
vals = arguments.map { |c| Pin::ProxyType.anonymous(c.infer(api_map, pin, locals), source: :chain) }
|
|
214
236
|
txt = macro.tag.text.clone
|
|
237
|
+
# @sg-ignore Need to add nil check here
|
|
215
238
|
if txt.empty? && macro.tag.name
|
|
216
239
|
named = api_map.named_macro(macro.tag.name)
|
|
217
240
|
txt = named.tag.text.clone if named
|
|
218
241
|
end
|
|
219
242
|
i = 1
|
|
220
243
|
vals.each do |v|
|
|
244
|
+
# @sg-ignore Need to add nil check here
|
|
221
245
|
txt.gsub!(/\$#{i}/, v.context.namespace)
|
|
222
246
|
i += 1
|
|
223
247
|
end
|
|
248
|
+
# @sg-ignore Need to add nil check here
|
|
224
249
|
docstring = Solargraph::Source.parse_docstring(txt).to_docstring
|
|
225
250
|
tag = docstring.tag(:return)
|
|
226
251
|
unless tag.nil? || tag.types.nil?
|
|
@@ -233,7 +258,7 @@ module Solargraph
|
|
|
233
258
|
# @param context [ComplexType]
|
|
234
259
|
# @return [ComplexType, nil]
|
|
235
260
|
def extra_return_type docstring, context
|
|
236
|
-
if docstring.has_tag?('return_single_parameter')
|
|
261
|
+
if docstring.has_tag?('return_single_parameter') # && context.subtypes.one?
|
|
237
262
|
return context.subtypes.first || ComplexType::UNDEFINED
|
|
238
263
|
elsif docstring.has_tag?('return_value_parameter') && context.value_types.one?
|
|
239
264
|
return context.value_types.first
|
|
@@ -243,9 +268,10 @@ module Solargraph
|
|
|
243
268
|
|
|
244
269
|
# @param name_pin [Pin::Base]
|
|
245
270
|
# @return [Pin::Method, nil]
|
|
246
|
-
def find_method_pin
|
|
271
|
+
def find_method_pin name_pin
|
|
247
272
|
method_pin = name_pin
|
|
248
273
|
until method_pin.is_a?(Pin::Method)
|
|
274
|
+
# @sg-ignore Need to support this in flow sensitive typing
|
|
249
275
|
method_pin = method_pin.closure
|
|
250
276
|
return if method_pin.nil?
|
|
251
277
|
end
|
|
@@ -259,7 +285,7 @@ module Solargraph
|
|
|
259
285
|
method_pin = find_method_pin(name_pin)
|
|
260
286
|
return [] if method_pin.nil?
|
|
261
287
|
pins = api_map.get_method_stack(method_pin.namespace, method_pin.name, scope: method_pin.context.scope)
|
|
262
|
-
pins.reject{|p| p.path == name_pin.path}
|
|
288
|
+
pins.reject { |p| p.path == name_pin.path }
|
|
263
289
|
end
|
|
264
290
|
|
|
265
291
|
# @param api_map [ApiMap]
|
|
@@ -271,13 +297,14 @@ module Solargraph
|
|
|
271
297
|
|
|
272
298
|
# @param signature_pin [Pin::Signature]
|
|
273
299
|
method_pin.signatures.map(&:block).compact.map do |signature_pin|
|
|
300
|
+
# @sg-ignore Need to add nil check here
|
|
274
301
|
return_type = signature_pin.return_type.qualify(api_map, *name_pin.gates)
|
|
275
302
|
signature_pin.proxy(return_type)
|
|
276
303
|
end
|
|
277
304
|
end
|
|
278
305
|
|
|
279
306
|
# @param type [ComplexType]
|
|
280
|
-
# @param context [ComplexType]
|
|
307
|
+
# @param context [ComplexType, ComplexType::UniqueType]
|
|
281
308
|
# @return [ComplexType]
|
|
282
309
|
def with_params type, context
|
|
283
310
|
return type unless type.to_s.include?('$')
|
|
@@ -291,13 +318,14 @@ module Solargraph
|
|
|
291
318
|
end
|
|
292
319
|
|
|
293
320
|
# @param api_map [ApiMap]
|
|
294
|
-
# @param context [ComplexType]
|
|
321
|
+
# @param context [ComplexType, ComplexType::UniqueType]
|
|
295
322
|
# @param block_parameter_types [::Array<ComplexType>]
|
|
296
323
|
# @param locals [::Array<Pin::LocalVariable>]
|
|
297
324
|
# @return [ComplexType, nil]
|
|
298
|
-
def block_symbol_call_type
|
|
325
|
+
def block_symbol_call_type api_map, context, block_parameter_types, locals
|
|
299
326
|
# Ruby's shorthand for sending the passed in method name
|
|
300
327
|
# to the first yield parameter with no arguments
|
|
328
|
+
# @sg-ignore Need to add nil check here
|
|
301
329
|
block_symbol_name = block.links.first.word
|
|
302
330
|
block_symbol_call_path = "#{block_parameter_types.first}##{block_symbol_name}"
|
|
303
331
|
callee = api_map.get_path_pins(block_symbol_call_path).first
|
|
@@ -305,31 +333,43 @@ module Solargraph
|
|
|
305
333
|
# @todo: Figure out why we get unresolved generics at
|
|
306
334
|
# this point and need to assume method return types
|
|
307
335
|
# based on the generic type
|
|
336
|
+
# @sg-ignore Need to add nil check here
|
|
308
337
|
return_type ||= api_map.get_path_pins("#{context.subtypes.first}##{block.links.first.word}").first&.return_type
|
|
309
338
|
return_type || ComplexType::UNDEFINED
|
|
310
339
|
end
|
|
311
340
|
|
|
312
341
|
# @param api_map [ApiMap]
|
|
313
342
|
# @return [Pin::Block, nil]
|
|
314
|
-
def find_block_pin
|
|
343
|
+
def find_block_pin api_map
|
|
344
|
+
# @sg-ignore Need to add nil check here
|
|
315
345
|
node_location = Solargraph::Location.from_node(block.node)
|
|
316
|
-
return if
|
|
346
|
+
return if node_location.nil?
|
|
317
347
|
block_pins = api_map.get_block_pins
|
|
348
|
+
# @sg-ignore Need to add nil check here
|
|
318
349
|
block_pins.find { |pin| pin.location.contain?(node_location) }
|
|
319
350
|
end
|
|
320
351
|
|
|
321
352
|
# @param api_map [ApiMap]
|
|
322
353
|
# @param name_pin [Pin::Base]
|
|
323
|
-
# @param block_parameter_types [::Array<ComplexType>]
|
|
324
354
|
# @param locals [::Array<Pin::LocalVariable>]
|
|
325
355
|
# @return [ComplexType, nil]
|
|
326
|
-
def block_call_type
|
|
356
|
+
def block_call_type api_map, name_pin, locals
|
|
327
357
|
return nil unless with_block?
|
|
328
358
|
|
|
329
|
-
block_context_pin = name_pin
|
|
330
359
|
block_pin = find_block_pin(api_map)
|
|
331
|
-
|
|
332
|
-
block
|
|
360
|
+
# We use the block pin as the closure, as the parameters
|
|
361
|
+
# here will only be defined inside the block itself and we
|
|
362
|
+
# need to be able to see them
|
|
363
|
+
# @sg-ignore Need to add nil check here
|
|
364
|
+
block.infer(api_map, block_pin, locals)
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
protected
|
|
368
|
+
|
|
369
|
+
# @sg-ignore Fix "Not enough arguments to Module#protected"
|
|
370
|
+
def equality_fields
|
|
371
|
+
# @sg-ignore literal arrays in this module turn into ::Solargraph::Source::Chain::Array
|
|
372
|
+
super + [arguments, block]
|
|
333
373
|
end
|
|
334
374
|
end
|
|
335
375
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
class Source
|
|
5
|
-
class Chain
|
|
6
|
-
class ClassVariable < Link
|
|
7
|
-
def resolve api_map, name_pin, locals
|
|
8
|
-
api_map.get_class_variable_pins(name_pin.context.namespace).select{|p| p.name == word}
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
class Source
|
|
5
|
+
class Chain
|
|
6
|
+
class ClassVariable < Link
|
|
7
|
+
def resolve api_map, name_pin, locals
|
|
8
|
+
api_map.get_class_variable_pins(name_pin.context.namespace).select { |p| p.name == word }
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -6,18 +6,22 @@ module Solargraph
|
|
|
6
6
|
class Constant < Link
|
|
7
7
|
def initialize word
|
|
8
8
|
@word = word
|
|
9
|
+
|
|
10
|
+
super
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def resolve api_map, name_pin, locals
|
|
12
14
|
return [Pin::ROOT_PIN] if word.empty?
|
|
13
15
|
if word.start_with?('::')
|
|
14
|
-
base = word[2
|
|
16
|
+
base = word[2..]
|
|
15
17
|
gates = ['']
|
|
16
18
|
else
|
|
17
19
|
base = word
|
|
18
20
|
gates = name_pin.gates
|
|
19
21
|
end
|
|
22
|
+
# @sg-ignore Need to add nil check here
|
|
20
23
|
fqns = api_map.resolve(base, gates)
|
|
24
|
+
# @sg-ignore Need to add nil check here
|
|
21
25
|
api_map.get_path_pins(fqns)
|
|
22
26
|
end
|
|
23
27
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
class Source
|
|
5
|
-
class Chain
|
|
6
|
-
class GlobalVariable < Link
|
|
7
|
-
def resolve api_map, name_pin, locals
|
|
8
|
-
api_map.get_global_variable_pins.select{|p| p.name == word}
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
class Source
|
|
5
|
+
class Chain
|
|
6
|
+
class GlobalVariable < Link
|
|
7
|
+
def resolve api_map, name_pin, locals
|
|
8
|
+
api_map.get_global_variable_pins.select { |p| p.name == word }
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -12,11 +12,6 @@ module Solargraph
|
|
|
12
12
|
@splatted = splatted
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
# @sg-ignore Fix "Not enough arguments to Module#protected"
|
|
16
|
-
protected def equality_fields
|
|
17
|
-
super + [@splatted]
|
|
18
|
-
end
|
|
19
|
-
|
|
20
15
|
def word
|
|
21
16
|
@word ||= "<#{@type}>"
|
|
22
17
|
end
|
|
@@ -28,6 +23,14 @@ module Solargraph
|
|
|
28
23
|
def splatted?
|
|
29
24
|
@splatted
|
|
30
25
|
end
|
|
26
|
+
|
|
27
|
+
protected
|
|
28
|
+
|
|
29
|
+
# @sg-ignore Fix "Not enough arguments to Module#protected"
|
|
30
|
+
def equality_fields
|
|
31
|
+
# @sg-ignore literal arrays in this module turn into ::Solargraph::Source::Chain::Array
|
|
32
|
+
super + [@splatted]
|
|
33
|
+
end
|
|
31
34
|
end
|
|
32
35
|
end
|
|
33
36
|
end
|
|
@@ -4,23 +4,25 @@ module Solargraph
|
|
|
4
4
|
class Source
|
|
5
5
|
class Chain
|
|
6
6
|
class If < Link
|
|
7
|
-
def word
|
|
8
|
-
'<if>'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
7
|
# @param links [::Array<Chain>]
|
|
12
8
|
def initialize links
|
|
13
|
-
|
|
14
|
-
end
|
|
9
|
+
super('<if>')
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
protected def equality_fields
|
|
18
|
-
super + [@links]
|
|
11
|
+
@links = links
|
|
19
12
|
end
|
|
20
13
|
|
|
21
14
|
def resolve api_map, name_pin, locals
|
|
22
15
|
types = @links.map { |link| link.infer(api_map, name_pin, locals) }
|
|
23
|
-
[Solargraph::Pin::ProxyType.anonymous(Solargraph::ComplexType.try_parse(types.map(&:tag).uniq.join(', ')),
|
|
16
|
+
[Solargraph::Pin::ProxyType.anonymous(Solargraph::ComplexType.try_parse(types.map(&:tag).uniq.join(', ')),
|
|
17
|
+
source: :chain)]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
protected
|
|
21
|
+
|
|
22
|
+
# @sg-ignore Fix "Not enough arguments to Module#protected"
|
|
23
|
+
def equality_fields
|
|
24
|
+
# @sg-ignore literal arrays in this module turn into ::Solargraph::Source::Chain::Array
|
|
25
|
+
super + [@links]
|
|
24
26
|
end
|
|
25
27
|
end
|
|
26
28
|
end
|
|
@@ -4,9 +4,32 @@ module Solargraph
|
|
|
4
4
|
class Source
|
|
5
5
|
class Chain
|
|
6
6
|
class InstanceVariable < Link
|
|
7
|
+
# @param word [String]
|
|
8
|
+
# @param node [Parser::AST::Node, nil] The node representing the variable
|
|
9
|
+
# @param location [Location, nil] The location of the variable reference in the source
|
|
10
|
+
def initialize word, node, location
|
|
11
|
+
super(word)
|
|
12
|
+
@node = node
|
|
13
|
+
@location = location
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @sg-ignore Declared return type
|
|
17
|
+
# ::Array<::Solargraph::Pin::Base> does not match inferred
|
|
18
|
+
# type ::Array<::Solargraph::Pin::BaseVariable, ::NilClass>
|
|
19
|
+
# for Solargraph::Source::Chain::InstanceVariable#resolve
|
|
7
20
|
def resolve api_map, name_pin, locals
|
|
8
|
-
api_map.get_instance_variable_pins(name_pin.
|
|
21
|
+
ivars = api_map.get_instance_variable_pins(name_pin.context.namespace, name_pin.context.scope).select do |p|
|
|
22
|
+
p.name == word
|
|
23
|
+
end
|
|
24
|
+
out = api_map.var_at_location(ivars, word, name_pin, location)
|
|
25
|
+
[out].compact
|
|
9
26
|
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
# @todo: Missed nil violation
|
|
31
|
+
# @return [Location]
|
|
32
|
+
attr_reader :location
|
|
10
33
|
end
|
|
11
34
|
end
|
|
12
35
|
end
|