solargraph 0.51.2 → 0.54.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/plugins.yml +40 -0
- data/.github/workflows/rspec.yml +1 -3
- data/.github/workflows/typecheck.yml +34 -0
- data/.yardopts +2 -2
- data/CHANGELOG.md +127 -5
- data/README.md +13 -16
- data/SPONSORS.md +1 -7
- data/lib/solargraph/api_map/cache.rb +50 -20
- data/lib/solargraph/api_map/source_to_yard.rb +17 -10
- data/lib/solargraph/api_map/store.rb +60 -15
- data/lib/solargraph/api_map.rb +282 -123
- data/lib/solargraph/bench.rb +3 -2
- data/lib/solargraph/cache.rb +29 -5
- data/lib/solargraph/complex_type/type_methods.rb +122 -39
- data/lib/solargraph/complex_type/unique_type.rb +310 -76
- data/lib/solargraph/complex_type.rb +166 -44
- data/lib/solargraph/convention.rb +0 -1
- data/lib/solargraph/converters/dd.rb +5 -0
- data/lib/solargraph/converters/dl.rb +3 -0
- data/lib/solargraph/converters/dt.rb +3 -0
- data/lib/solargraph/diagnostics/rubocop.rb +8 -7
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -0
- data/lib/solargraph/diagnostics/type_check.rb +1 -0
- data/lib/solargraph/diagnostics.rb +2 -2
- data/lib/solargraph/doc_map.rb +187 -0
- data/lib/solargraph/gem_pins.rb +72 -0
- data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
- data/lib/solargraph/language_server/host/dispatch.rb +22 -5
- data/lib/solargraph/language_server/host/message_worker.rb +49 -5
- data/lib/solargraph/language_server/host/sources.rb +8 -65
- data/lib/solargraph/language_server/host.rb +65 -84
- data/lib/solargraph/language_server/message/base.rb +19 -12
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
- data/lib/solargraph/language_server/message/initialize.rb +19 -2
- data/lib/solargraph/language_server/message/text_document/completion.rb +0 -3
- data/lib/solargraph/language_server/message/text_document/definition.rb +3 -3
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +3 -3
- data/lib/solargraph/language_server/message/text_document/formatting.rb +1 -0
- data/lib/solargraph/language_server/message/text_document/hover.rb +3 -1
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +3 -3
- data/lib/solargraph/language_server/message/text_document.rb +0 -1
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +2 -2
- data/lib/solargraph/language_server/progress.rb +135 -0
- data/lib/solargraph/language_server/transport/adapter.rb +16 -1
- data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
- data/lib/solargraph/language_server.rb +1 -0
- data/lib/solargraph/library.rb +207 -111
- data/lib/solargraph/location.rb +15 -1
- data/lib/solargraph/page.rb +6 -0
- data/lib/solargraph/parser/comment_ripper.rb +4 -0
- data/lib/solargraph/parser/node_methods.rb +47 -7
- data/lib/solargraph/parser/node_processor/base.rb +11 -1
- data/lib/solargraph/parser/node_processor.rb +1 -0
- data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +31 -9
- data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +62 -43
- data/lib/solargraph/parser/parser_gem/node_methods.rb +495 -0
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +57 -0
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +2 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/def_node.rb +7 -20
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +4 -4
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +53 -0
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sclass_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +8 -6
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/sym_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors.rb +56 -0
- data/lib/solargraph/parser/parser_gem.rb +12 -0
- data/lib/solargraph/parser/region.rb +1 -1
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +8 -12
- data/lib/solargraph/pin/base.rb +78 -10
- data/lib/solargraph/pin/base_variable.rb +40 -7
- data/lib/solargraph/pin/block.rb +69 -46
- data/lib/solargraph/pin/callable.rb +147 -0
- data/lib/solargraph/pin/closure.rb +23 -3
- data/lib/solargraph/pin/common.rb +6 -6
- data/lib/solargraph/pin/conversions.rb +36 -5
- data/lib/solargraph/pin/delegated_method.rb +6 -2
- data/lib/solargraph/pin/documenting.rb +25 -32
- data/lib/solargraph/pin/instance_variable.rb +6 -2
- data/lib/solargraph/pin/local_variable.rb +13 -1
- data/lib/solargraph/pin/method.rb +205 -32
- data/lib/solargraph/pin/namespace.rb +20 -7
- data/lib/solargraph/pin/parameter.rb +41 -36
- data/lib/solargraph/pin/proxy_type.rb +1 -1
- data/lib/solargraph/pin/reference/override.rb +2 -2
- data/lib/solargraph/pin/reference.rb +8 -0
- data/lib/solargraph/pin/search.rb +3 -3
- data/lib/solargraph/pin/signature.rb +8 -14
- data/lib/solargraph/pin.rb +4 -2
- data/lib/solargraph/range.rb +4 -6
- data/lib/solargraph/rbs_map/conversions.rb +326 -76
- data/lib/solargraph/rbs_map/core_fills.rb +16 -33
- data/lib/solargraph/rbs_map/core_map.rb +3 -13
- data/lib/solargraph/rbs_map/stdlib_map.rb +2 -8
- data/lib/solargraph/rbs_map.rb +32 -13
- data/lib/solargraph/shell.rb +95 -72
- data/lib/solargraph/source/chain/array.rb +33 -0
- data/lib/solargraph/source/chain/block_symbol.rb +13 -0
- data/lib/solargraph/source/chain/block_variable.rb +1 -1
- data/lib/solargraph/source/chain/call.rb +152 -69
- data/lib/solargraph/source/chain/constant.rb +15 -1
- data/lib/solargraph/source/chain/if.rb +23 -0
- data/lib/solargraph/source/chain/link.rb +17 -2
- data/lib/solargraph/source/chain/or.rb +2 -2
- data/lib/solargraph/source/chain/z_super.rb +3 -3
- data/lib/solargraph/source/chain.rb +85 -26
- data/lib/solargraph/source/change.rb +3 -0
- data/lib/solargraph/source/cursor.rb +16 -2
- data/lib/solargraph/source/source_chainer.rb +8 -5
- data/lib/solargraph/source/updater.rb +1 -0
- data/lib/solargraph/source.rb +120 -148
- data/lib/solargraph/source_map/clip.rb +16 -27
- data/lib/solargraph/source_map/data.rb +30 -0
- data/lib/solargraph/source_map/mapper.rb +15 -3
- data/lib/solargraph/source_map.rb +48 -24
- data/lib/solargraph/type_checker/checks.rb +10 -2
- data/lib/solargraph/type_checker/rules.rb +6 -1
- data/lib/solargraph/type_checker.rb +150 -39
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/views/environment.erb +3 -5
- data/lib/solargraph/workspace/config.rb +9 -6
- data/lib/solargraph/workspace.rb +30 -3
- data/lib/solargraph/yard_map/cache.rb +6 -0
- data/lib/solargraph/yard_map/helpers.rb +1 -1
- data/lib/solargraph/yard_map/mapper/to_method.rb +16 -3
- data/lib/solargraph/yard_map/mapper.rb +1 -1
- data/lib/solargraph/yard_map/to_method.rb +11 -4
- data/lib/solargraph/yard_map.rb +1 -292
- data/lib/solargraph/yard_tags.rb +20 -0
- data/lib/solargraph/yardoc.rb +52 -0
- data/lib/solargraph.rb +6 -4
- data/solargraph.gemspec +7 -6
- metadata +71 -82
- data/lib/solargraph/api_map/bundler_methods.rb +0 -22
- data/lib/solargraph/documentor.rb +0 -76
- data/lib/solargraph/language_server/host/cataloger.rb +0 -56
- data/lib/solargraph/parser/legacy/node_methods.rb +0 -325
- data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
- data/lib/solargraph/parser/legacy/node_processors/args_node.rb +0 -50
- data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
- data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +0 -18
- data/lib/solargraph/parser/legacy/node_processors.rb +0 -55
- data/lib/solargraph/parser/legacy.rb +0 -12
- data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -153
- data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -160
- data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -317
- data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
- data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
- data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -33
- data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
- data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +0 -75
- data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -68
- data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
- data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
- data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
- data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
- data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
- data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
- data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
- data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
- data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -51
- data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -32
- data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
- data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -279
- data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -64
- data/lib/solargraph/parser/rubyvm/node_wrapper.rb +0 -47
- data/lib/solargraph/parser/rubyvm.rb +0 -40
- data/lib/solargraph/rbs_map/core_signs.rb +0 -33
- data/lib/yard-solargraph.rb +0 -33
@@ -5,10 +5,19 @@ require 'solargraph/source/chain/link'
|
|
5
5
|
|
6
6
|
module Solargraph
|
7
7
|
class Source
|
8
|
-
#
|
9
|
-
#
|
8
|
+
#
|
9
|
+
# Represents an expression as a single call chain at the parse
|
10
|
+
# tree level, made up of constants, variables, and method calls,
|
11
|
+
# each represented as a Link object.
|
12
|
+
#
|
13
|
+
# Computes Pins and/or ComplexTypes representing the interpreted
|
14
|
+
# expression.
|
10
15
|
#
|
11
16
|
class Chain
|
17
|
+
#
|
18
|
+
# A chain of constants, variables, and method calls for inferring types of
|
19
|
+
# values.
|
20
|
+
#
|
12
21
|
autoload :Link, 'solargraph/source/chain/link'
|
13
22
|
autoload :Call, 'solargraph/source/chain/call'
|
14
23
|
autoload :QCall, 'solargraph/source/chain/q_call'
|
@@ -19,23 +28,30 @@ module Solargraph
|
|
19
28
|
autoload :GlobalVariable, 'solargraph/source/chain/global_variable'
|
20
29
|
autoload :Literal, 'solargraph/source/chain/literal'
|
21
30
|
autoload :Head, 'solargraph/source/chain/head'
|
31
|
+
autoload :If, 'solargraph/source/chain/if'
|
22
32
|
autoload :Or, 'solargraph/source/chain/or'
|
23
33
|
autoload :BlockVariable, 'solargraph/source/chain/block_variable'
|
34
|
+
autoload :BlockSymbol, 'solargraph/source/chain/block_symbol'
|
24
35
|
autoload :ZSuper, 'solargraph/source/chain/z_super'
|
25
36
|
autoload :Hash, 'solargraph/source/chain/hash'
|
37
|
+
autoload :Array, 'solargraph/source/chain/array'
|
26
38
|
|
27
39
|
@@inference_stack = []
|
28
40
|
@@inference_depth = 0
|
41
|
+
@@inference_invalidation_key = nil
|
42
|
+
@@inference_cache = {}
|
29
43
|
|
30
44
|
UNDEFINED_CALL = Chain::Call.new('<undefined>')
|
31
45
|
UNDEFINED_CONSTANT = Chain::Constant.new('<undefined>')
|
32
46
|
|
33
|
-
# @return [Array<Source::Chain::Link>]
|
47
|
+
# @return [::Array<Source::Chain::Link>]
|
34
48
|
attr_reader :links
|
35
49
|
|
36
50
|
attr_reader :node
|
37
51
|
|
38
|
-
# @param
|
52
|
+
# @param node [Parser::AST::Node, nil]
|
53
|
+
# @param links [::Array<Chain::Link>]
|
54
|
+
# @param splat [Boolean]
|
39
55
|
def initialize links, node = nil, splat = false
|
40
56
|
@links = links.clone
|
41
57
|
@links.push UNDEFINED_CALL if @links.empty?
|
@@ -54,12 +70,31 @@ module Solargraph
|
|
54
70
|
@base ||= Chain.new(links[0..-2])
|
55
71
|
end
|
56
72
|
|
73
|
+
# Determine potential Pins returned by this chain of words
|
74
|
+
#
|
57
75
|
# @param api_map [ApiMap]
|
58
|
-
# @param name_pin [Pin::
|
59
|
-
#
|
60
|
-
#
|
76
|
+
# @param name_pin [Pin::Closure] the surrounding closure pin for
|
77
|
+
# the statement represented by this chain for type resolution
|
78
|
+
# and method pin lookup.
|
79
|
+
#
|
80
|
+
# For method calls (Chain::Call objects) as the first element
|
81
|
+
# in the chain, 'name_pin.binder' should return the
|
82
|
+
# ComplexType representing the LHS / "self type" of the call.
|
83
|
+
#
|
84
|
+
# @param locals [::Enumerable<Pin::LocalVariable>] Any local
|
85
|
+
# variables / method parameters etc visible by the statement
|
86
|
+
#
|
87
|
+
# @return [::Array<Pin::Base>] Pins representing possible return
|
88
|
+
# types of this method.
|
61
89
|
def define api_map, name_pin, locals
|
62
90
|
return [] if undefined?
|
91
|
+
|
92
|
+
# working_pin is the surrounding closure pin for the link
|
93
|
+
# being processed, whose #binder method will provide the LHS /
|
94
|
+
# 'self type' of the next link (same as the #return_type method
|
95
|
+
# --the type of the result so far).
|
96
|
+
#
|
97
|
+
# @todo ProxyType uses 'type' for the binder, but '
|
63
98
|
working_pin = name_pin
|
64
99
|
links[0..-2].each do |link|
|
65
100
|
pins = link.resolve(api_map, working_pin, locals)
|
@@ -67,19 +102,33 @@ module Solargraph
|
|
67
102
|
return [] if type.undefined?
|
68
103
|
working_pin = Pin::ProxyType.anonymous(type)
|
69
104
|
end
|
70
|
-
links.last.last_context =
|
105
|
+
links.last.last_context = working_pin
|
71
106
|
links.last.resolve(api_map, working_pin, locals)
|
72
107
|
end
|
73
108
|
|
74
109
|
# @param api_map [ApiMap]
|
75
|
-
# @param name_pin [Pin::Base]
|
76
|
-
# @param locals [
|
110
|
+
# @param name_pin [Pin::Base] The pin for the closure in which this code runs
|
111
|
+
# @param locals [::Enumerable<Pin::LocalVariable>]
|
77
112
|
# @return [ComplexType]
|
113
|
+
# @sg-ignore
|
78
114
|
def infer api_map, name_pin, locals
|
79
|
-
|
80
|
-
|
81
|
-
|
115
|
+
out = nil
|
116
|
+
cached = @@inference_cache[[node, node.location, links.map(&:word), name_pin&.return_type, locals]] unless node.nil?
|
117
|
+
return cached if cached && @@inference_invalidation_key == api_map.hash
|
118
|
+
out = infer_uncached api_map, name_pin, locals
|
119
|
+
if @@inference_invalidation_key != api_map.hash
|
120
|
+
@@inference_cache = {}
|
121
|
+
@@inference_invalidation_key = api_map.hash
|
82
122
|
end
|
123
|
+
@@inference_cache[[node, node.location, links.map(&:word), name_pin&.return_type, locals]] = out unless node.nil?
|
124
|
+
out
|
125
|
+
end
|
126
|
+
|
127
|
+
# @param api_map [ApiMap]
|
128
|
+
# @param name_pin [Pin::Base]
|
129
|
+
# @param locals [::Enumerable<Pin::LocalVariable>]
|
130
|
+
# @return [ComplexType]
|
131
|
+
def infer_uncached api_map, name_pin, locals
|
83
132
|
pins = define(api_map, name_pin, locals)
|
84
133
|
type = infer_first_defined(pins, links.last.last_context, api_map, locals)
|
85
134
|
maybe_nil(type)
|
@@ -113,26 +162,29 @@ module Solargraph
|
|
113
162
|
|
114
163
|
private
|
115
164
|
|
116
|
-
# @param pins [Array<Pin::Base>]
|
165
|
+
# @param pins [::Array<Pin::Base>]
|
117
166
|
# @param context [Pin::Base]
|
118
167
|
# @param api_map [ApiMap]
|
168
|
+
# @param locals [::Enumerable<Pin::LocalVariable>]
|
119
169
|
# @return [ComplexType]
|
120
170
|
def infer_first_defined pins, context, api_map, locals
|
121
171
|
possibles = []
|
172
|
+
# @todo this param tag shouldn't be needed to probe the type
|
173
|
+
# @todo ...but given it is needed, typecheck should complain that it is needed
|
174
|
+
# @param pin [Pin::Base]
|
122
175
|
pins.each do |pin|
|
123
176
|
# Avoid infinite recursion
|
124
177
|
next if @@inference_stack.include?(pin.identity)
|
178
|
+
|
125
179
|
@@inference_stack.push pin.identity
|
126
180
|
type = pin.typify(api_map)
|
127
181
|
@@inference_stack.pop
|
128
182
|
if type.defined?
|
129
|
-
if type.
|
130
|
-
|
131
|
-
#
|
132
|
-
#
|
133
|
-
|
134
|
-
# next unless param_type
|
135
|
-
# type = ComplexType.try_parse(param_type.to_s)
|
183
|
+
if type.generic?
|
184
|
+
# @todo even at strong, no typechecking complaint
|
185
|
+
# happens when a [Pin::Base,nil] is passed into a method
|
186
|
+
# that accepts only [Pin::Namespace] as an argument
|
187
|
+
type = type.resolve_generics(pin.closure, context.binder)
|
136
188
|
end
|
137
189
|
if type.defined?
|
138
190
|
possibles.push type
|
@@ -143,10 +195,13 @@ module Solargraph
|
|
143
195
|
if possibles.empty?
|
144
196
|
# Limit method inference recursion
|
145
197
|
return ComplexType::UNDEFINED if @@inference_depth >= 10 && pins.first.is_a?(Pin::Method)
|
198
|
+
|
146
199
|
@@inference_depth += 1
|
200
|
+
# @param pin [Pin::Base]
|
147
201
|
pins.each do |pin|
|
148
202
|
# Avoid infinite recursion
|
149
203
|
next if @@inference_stack.include?(pin.identity)
|
204
|
+
|
150
205
|
@@inference_stack.push pin.identity
|
151
206
|
type = pin.probe(api_map)
|
152
207
|
@@inference_stack.pop
|
@@ -158,21 +213,25 @@ module Solargraph
|
|
158
213
|
@@inference_depth -= 1
|
159
214
|
end
|
160
215
|
return ComplexType::UNDEFINED if possibles.empty?
|
216
|
+
|
161
217
|
type = if possibles.length > 1
|
162
|
-
|
163
|
-
|
218
|
+
# Move nil to the end by convention
|
219
|
+
sorted = possibles.sort { |a, _| a.tag == 'nil' ? 1 : 0 }
|
220
|
+
ComplexType.new(sorted.uniq)
|
164
221
|
else
|
165
|
-
ComplexType.
|
222
|
+
ComplexType.new(possibles)
|
166
223
|
end
|
167
224
|
return type if context.nil? || context.return_type.undefined?
|
168
|
-
|
225
|
+
|
226
|
+
type.self_to_type(context.return_type)
|
169
227
|
end
|
170
228
|
|
171
229
|
# @param type [ComplexType]
|
230
|
+
# @return [ComplexType]
|
172
231
|
def maybe_nil type
|
173
232
|
return type if type.undefined? || type.void? || type.nullable?
|
174
233
|
return type unless nullable?
|
175
|
-
ComplexType.
|
234
|
+
ComplexType.new(type.items + [ComplexType::NIL])
|
176
235
|
end
|
177
236
|
end
|
178
237
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Solargraph
|
4
4
|
class Source
|
5
|
-
# Information about a
|
6
|
-
# there.
|
5
|
+
# Information about a single Position in a Source, including the
|
6
|
+
# word located there.
|
7
7
|
#
|
8
8
|
class Cursor
|
9
9
|
# @return [Position]
|
@@ -35,6 +35,7 @@ module Solargraph
|
|
35
35
|
# The part of the word before the current position. Given the text
|
36
36
|
# `foo.bar`, the start_of_word at position(0, 6) is `ba`.
|
37
37
|
#
|
38
|
+
# @sg-ignore Improve resolution of String#match below
|
38
39
|
# @return [String]
|
39
40
|
def start_of_word
|
40
41
|
@start_of_word ||= begin
|
@@ -103,6 +104,17 @@ module Solargraph
|
|
103
104
|
@string ||= source.string_at?(position)
|
104
105
|
end
|
105
106
|
|
107
|
+
|
108
|
+
# True if the cursor's chain is an assignment to a variable.
|
109
|
+
#
|
110
|
+
# When the chain is an assignment, `Cursor#word` will contain the
|
111
|
+
# variable name.
|
112
|
+
#
|
113
|
+
# @return [Boolean]
|
114
|
+
def assign?
|
115
|
+
[:lvasgn, :ivasgn, :gvasgn, :cvasgn].include? chain&.node&.type
|
116
|
+
end
|
117
|
+
|
106
118
|
# Get a cursor pointing to the method that receives the current statement
|
107
119
|
# as an argument.
|
108
120
|
#
|
@@ -115,6 +127,7 @@ module Solargraph
|
|
115
127
|
end
|
116
128
|
alias receiver recipient
|
117
129
|
|
130
|
+
# @return [AST::Node]
|
118
131
|
def node
|
119
132
|
@node ||= source.node_at(position.line, position.column)
|
120
133
|
end
|
@@ -135,6 +148,7 @@ module Solargraph
|
|
135
148
|
end
|
136
149
|
end
|
137
150
|
|
151
|
+
# @return [Parser::AST::Node, nil]
|
138
152
|
def recipient_node
|
139
153
|
@recipient_node ||= Solargraph::Parser::NodeMethods.find_recipient_node(self)
|
140
154
|
end
|
@@ -14,10 +14,10 @@ module Solargraph
|
|
14
14
|
|
15
15
|
class << self
|
16
16
|
# @param source [Source]
|
17
|
-
# @param position [Position]
|
17
|
+
# @param position [Position, Array(Integer, Integer)]
|
18
18
|
# @return [Source::Chain]
|
19
19
|
def chain source, position
|
20
|
-
new(source, position).chain
|
20
|
+
new(source, Solargraph::Position.normalize(position)).chain
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -41,12 +41,12 @@ module Solargraph
|
|
41
41
|
parent = nil
|
42
42
|
if !source.repaired? && source.parsed? && source.synchronized?
|
43
43
|
tree = source.tree_at(position.line, position.column)
|
44
|
-
# node, parent = source.tree_at(position.line, position.column)[0..2]
|
45
|
-
tree.shift while tree.length > 1 && tree.first.type == :SCOPE
|
46
44
|
node, parent = tree[0..2]
|
47
45
|
elsif source.parsed? && source.repaired? && end_of_phrase == '.'
|
48
46
|
node, parent = source.tree_at(fixed_position.line, fixed_position.column)[0..2]
|
49
47
|
node = Parser.parse(fixed_phrase) if node.nil?
|
48
|
+
elsif source.repaired?
|
49
|
+
node = Parser.parse(fixed_phrase)
|
50
50
|
else
|
51
51
|
node, parent = source.tree_at(fixed_position.line, fixed_position.column)[0..2] unless source.error_ranges.any?{|r| r.nil? || r.include?(fixed_position)}
|
52
52
|
# Exception for positions that chain literal nodes in unsynchronized sources
|
@@ -58,7 +58,7 @@ module Solargraph
|
|
58
58
|
end
|
59
59
|
return Chain.new([Chain::UNDEFINED_CALL]) if node.nil? || (node.type == :sym && !phrase.start_with?(':'))
|
60
60
|
# chain = NodeChainer.chain(node, source.filename, parent && parent.type == :block)
|
61
|
-
chain = Parser.chain(node, source.filename, parent
|
61
|
+
chain = Parser.chain(node, source.filename, parent)
|
62
62
|
if source.repaired? || !source.parsed? || !source.synchronized?
|
63
63
|
if end_of_phrase.strip == '.'
|
64
64
|
chain.links.push Chain::UNDEFINED_CALL
|
@@ -126,10 +126,13 @@ module Solargraph
|
|
126
126
|
Position.line_char_to_offset(@source.code, line, column)
|
127
127
|
end
|
128
128
|
|
129
|
+
# @return [Integer]
|
129
130
|
def signature_data
|
130
131
|
@signature_data ||= get_signature_data_at(offset)
|
131
132
|
end
|
132
133
|
|
134
|
+
# @param index [Integer]
|
135
|
+
# @return [Integer]
|
133
136
|
def get_signature_data_at index
|
134
137
|
brackets = 0
|
135
138
|
squares = 0
|