solargraph 0.38.6 → 0.39.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/SPONSORS.md +9 -0
- data/lib/solargraph.rb +1 -0
- data/lib/solargraph/api_map.rb +24 -13
- data/lib/solargraph/api_map/bundler_methods.rb +3 -0
- data/lib/solargraph/api_map/source_to_yard.rb +1 -6
- data/lib/solargraph/api_map/store.rb +19 -3
- data/lib/solargraph/complex_type/type_methods.rb +4 -4
- data/lib/solargraph/convention/base.rb +0 -5
- data/lib/solargraph/core_fills.rb +28 -2
- data/lib/solargraph/diagnostics/base.rb +1 -0
- data/lib/solargraph/diagnostics/type_check.rb +13 -13
- data/lib/solargraph/language_server/host.rb +11 -2
- data/lib/solargraph/language_server/host/sources.rb +20 -11
- data/lib/solargraph/language_server/message/text_document/formatting.rb +16 -11
- data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
- data/lib/solargraph/library.rb +3 -3
- data/lib/solargraph/parser.rb +26 -0
- data/lib/solargraph/parser/comment_ripper.rb +52 -0
- data/lib/solargraph/parser/legacy.rb +12 -0
- data/lib/solargraph/parser/legacy/class_methods.rb +105 -0
- data/lib/solargraph/parser/legacy/flawed_builder.rb +16 -0
- data/lib/solargraph/parser/legacy/node_chainer.rb +115 -0
- data/lib/solargraph/parser/legacy/node_methods.rb +289 -0
- data/lib/solargraph/parser/legacy/node_processors.rb +54 -0
- data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +23 -0
- data/lib/solargraph/parser/legacy/node_processors/args_node.rb +35 -0
- data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +15 -0
- data/lib/solargraph/parser/legacy/node_processors/block_node.rb +22 -0
- data/lib/solargraph/parser/legacy/node_processors/casgn_node.rb +25 -0
- data/lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb +23 -0
- data/lib/solargraph/parser/legacy/node_processors/def_node.rb +63 -0
- data/lib/solargraph/parser/legacy/node_processors/defs_node.rb +36 -0
- data/lib/solargraph/parser/legacy/node_processors/gvasgn_node.rb +23 -0
- data/lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb +38 -0
- data/lib/solargraph/parser/legacy/node_processors/lvasgn_node.rb +28 -0
- data/lib/solargraph/parser/legacy/node_processors/namespace_node.rb +39 -0
- data/lib/solargraph/parser/legacy/node_processors/orasgn_node.rb +16 -0
- data/lib/solargraph/parser/legacy/node_processors/resbody_node.rb +36 -0
- data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +21 -0
- data/lib/solargraph/parser/legacy/node_processors/send_node.rb +232 -0
- data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +18 -0
- data/lib/solargraph/parser/node_methods.rb +43 -0
- data/lib/solargraph/parser/node_processor.rb +43 -0
- data/lib/solargraph/parser/node_processor/base.rb +77 -0
- data/lib/solargraph/{source_map → parser}/region.rb +11 -6
- data/lib/solargraph/parser/rubyvm.rb +40 -0
- data/lib/solargraph/parser/rubyvm/class_methods.rb +146 -0
- data/lib/solargraph/parser/rubyvm/node_chainer.rb +133 -0
- data/lib/solargraph/parser/rubyvm/node_methods.rb +279 -0
- data/lib/solargraph/parser/rubyvm/node_processors.rb +60 -0
- data/lib/solargraph/parser/rubyvm/node_processors/alias_node.rb +23 -0
- data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +62 -0
- data/lib/solargraph/parser/rubyvm/node_processors/begin_node.rb +15 -0
- data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +22 -0
- data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +22 -0
- data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +23 -0
- data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +64 -0
- data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +57 -0
- data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +23 -0
- data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +38 -0
- data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +34 -0
- data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +20 -0
- data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +27 -0
- data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +39 -0
- data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +26 -0
- data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +15 -0
- data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +45 -0
- data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +21 -0
- data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +15 -0
- data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +292 -0
- data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +18 -0
- data/lib/solargraph/parser/snippet.rb +13 -0
- data/lib/solargraph/pin/attribute.rb +8 -0
- data/lib/solargraph/pin/base.rb +1 -1
- data/lib/solargraph/pin/base_method.rb +26 -4
- data/lib/solargraph/pin/base_variable.rb +7 -8
- data/lib/solargraph/pin/block.rb +1 -1
- data/lib/solargraph/pin/constant.rb +16 -0
- data/lib/solargraph/pin/conversions.rb +2 -2
- data/lib/solargraph/pin/method.rb +26 -14
- data/lib/solargraph/pin/parameter.rb +56 -2
- data/lib/solargraph/pin/reference.rb +1 -0
- data/lib/solargraph/pin/reference/override.rb +2 -0
- data/lib/solargraph/pin/reference/prepend.rb +10 -0
- data/lib/solargraph/pin/yard_pin/constant.rb +2 -4
- data/lib/solargraph/pin/yard_pin/method.rb +34 -18
- data/lib/solargraph/pin/yard_pin/namespace.rb +3 -11
- data/lib/solargraph/pin/yard_pin/yard_mixin.rb +3 -12
- data/lib/solargraph/range.rb +8 -2
- data/lib/solargraph/shell.rb +17 -11
- data/lib/solargraph/source.rb +114 -135
- data/lib/solargraph/source/chain.rb +11 -3
- data/lib/solargraph/source/chain/call.rb +1 -2
- data/lib/solargraph/source/chain/constant.rb +44 -8
- data/lib/solargraph/source/chain/link.rb +1 -0
- data/lib/solargraph/source/cursor.rb +2 -28
- data/lib/solargraph/source/source_chainer.rb +12 -6
- data/lib/solargraph/source/updater.rb +2 -0
- data/lib/solargraph/source_map.rb +0 -2
- data/lib/solargraph/source_map/clip.rb +24 -17
- data/lib/solargraph/source_map/mapper.rb +34 -29
- data/lib/solargraph/type_checker.rb +367 -275
- data/lib/solargraph/type_checker/checks.rb +95 -0
- data/lib/solargraph/type_checker/param_def.rb +2 -17
- data/lib/solargraph/type_checker/rules.rb +53 -0
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/views/environment.erb +5 -3
- data/lib/solargraph/workspace.rb +17 -2
- data/lib/solargraph/workspace/config.rb +15 -7
- data/lib/solargraph/yard_map.rb +89 -49
- data/lib/solargraph/yard_map/core_docs.rb +1 -1
- data/solargraph.gemspec +2 -1
- metadata +88 -32
- data/OVERVIEW.md +0 -37
- data/lib/solargraph/source/flawed_builder.rb +0 -15
- data/lib/solargraph/source/node_chainer.rb +0 -111
- data/lib/solargraph/source/node_methods.rb +0 -240
- data/lib/solargraph/source_map/node_processor.rb +0 -85
- data/lib/solargraph/source_map/node_processor/alias_node.rb +0 -21
- data/lib/solargraph/source_map/node_processor/args_node.rb +0 -24
- data/lib/solargraph/source_map/node_processor/base.rb +0 -103
- data/lib/solargraph/source_map/node_processor/begin_node.rb +0 -13
- data/lib/solargraph/source_map/node_processor/block_node.rb +0 -21
- data/lib/solargraph/source_map/node_processor/casgn_node.rb +0 -21
- data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +0 -21
- data/lib/solargraph/source_map/node_processor/def_node.rb +0 -62
- data/lib/solargraph/source_map/node_processor/defs_node.rb +0 -33
- data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +0 -21
- data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +0 -34
- data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +0 -24
- data/lib/solargraph/source_map/node_processor/namespace_node.rb +0 -35
- data/lib/solargraph/source_map/node_processor/orasgn_node.rb +0 -14
- data/lib/solargraph/source_map/node_processor/resbody_node.rb +0 -32
- data/lib/solargraph/source_map/node_processor/sclass_node.rb +0 -19
- data/lib/solargraph/source_map/node_processor/send_node.rb +0 -217
- data/lib/solargraph/source_map/node_processor/sym_node.rb +0 -16
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Parser
|
5
|
+
module Legacy
|
6
|
+
module NodeProcessors
|
7
|
+
class ResbodyNode < Parser::NodeProcessor::Base
|
8
|
+
include Legacy::NodeMethods
|
9
|
+
|
10
|
+
def process
|
11
|
+
if node.children[1]
|
12
|
+
here = get_node_start_position(node.children[1])
|
13
|
+
presence = Range.new(here, region.closure.location.range.ending)
|
14
|
+
loc = get_node_location(node.children[1])
|
15
|
+
types = if node.children[0].nil?
|
16
|
+
['Exception']
|
17
|
+
else
|
18
|
+
node.children[0].children.map do |child|
|
19
|
+
unpack_name(child)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
locals.push Solargraph::Pin::LocalVariable.new(
|
23
|
+
location: loc,
|
24
|
+
closure: region.closure,
|
25
|
+
name: node.children[1].children[0].to_s,
|
26
|
+
comments: "@type [#{types.join(',')}]",
|
27
|
+
presence: presence
|
28
|
+
)
|
29
|
+
end
|
30
|
+
NodeProcessor.process(node.children[2], region, pins, locals)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Parser
|
5
|
+
module Legacy
|
6
|
+
module NodeProcessors
|
7
|
+
class SclassNode < Parser::NodeProcessor::Base
|
8
|
+
def process
|
9
|
+
# @todo Temporarily skipping remote metaclasses
|
10
|
+
return unless node.children[0].is_a?(AST::Node) && node.children[0].type == :self
|
11
|
+
pins.push Solargraph::Pin::Singleton.new(
|
12
|
+
location: get_node_location(node),
|
13
|
+
closure: region.closure
|
14
|
+
)
|
15
|
+
process_children region.update(visibility: :public, scope: :class, closure: pins.last)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,232 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Parser
|
5
|
+
module Legacy
|
6
|
+
module NodeProcessors
|
7
|
+
class SendNode < Parser::NodeProcessor::Base
|
8
|
+
include Legacy::NodeMethods
|
9
|
+
|
10
|
+
def process
|
11
|
+
if node.children[0].nil?
|
12
|
+
if [:private, :public, :protected].include?(node.children[1])
|
13
|
+
if (node.children.length > 2)
|
14
|
+
node.children[2..-1].each do |child|
|
15
|
+
next unless child.is_a?(AST::Node) && (child.type == :sym || child.type == :str)
|
16
|
+
name = child.children[0].to_s
|
17
|
+
matches = pins.select{ |pin| pin.is_a?(Pin::BaseMethod) && pin.name == name && pin.namespace == region.closure.full_context.namespace && pin.context.scope == (region.scope || :instance)}
|
18
|
+
matches.each do |pin|
|
19
|
+
# @todo Smelly instance variable access
|
20
|
+
pin.instance_variable_set(:@visibility, node.children[1])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
# @todo Smelly instance variable access
|
25
|
+
region.instance_variable_set(:@visibility, node.children[1])
|
26
|
+
end
|
27
|
+
elsif node.children[1] == :module_function
|
28
|
+
process_module_function
|
29
|
+
elsif [:attr_reader, :attr_writer, :attr_accessor].include?(node.children[1])
|
30
|
+
process_attribute
|
31
|
+
elsif node.children[1] == :include
|
32
|
+
process_include
|
33
|
+
elsif node.children[1] == :extend
|
34
|
+
process_extend
|
35
|
+
elsif node.children[1] == :prepend
|
36
|
+
process_prepend
|
37
|
+
elsif node.children[1] == :require
|
38
|
+
process_require
|
39
|
+
elsif node.children[1] == :private_constant
|
40
|
+
process_private_constant
|
41
|
+
elsif node.children[1] == :alias_method && node.children[2] && node.children[2] && node.children[2].type == :sym && node.children[3] && node.children[3].type == :sym
|
42
|
+
process_alias_method
|
43
|
+
elsif node.children[1] == :private_class_method && node.children[2].is_a?(AST::Node)
|
44
|
+
# Processing a private class can potentially handle children on its own
|
45
|
+
return if process_private_class_method
|
46
|
+
end
|
47
|
+
elsif node.children[1] == :require && node.children[0].to_s == '(const nil :Bundler)'
|
48
|
+
pins.push Pin::Reference::Require.new(Solargraph::Location.new(region.filename, Solargraph::Range.from_to(0, 0, 0, 0)), 'bundler/require')
|
49
|
+
end
|
50
|
+
process_children
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# @return [void]
|
56
|
+
def process_attribute
|
57
|
+
node.children[2..-1].each do |a|
|
58
|
+
loc = get_node_location(node)
|
59
|
+
clos = region.closure
|
60
|
+
cmnt = comments_for(node)
|
61
|
+
if node.children[1] == :attr_reader || node.children[1] == :attr_accessor
|
62
|
+
pins.push Solargraph::Pin::Attribute.new(
|
63
|
+
location: loc,
|
64
|
+
closure: clos,
|
65
|
+
name: a.children[0].to_s,
|
66
|
+
comments: cmnt,
|
67
|
+
access: :reader,
|
68
|
+
scope: region.scope || :instance,
|
69
|
+
visibility: region.visibility
|
70
|
+
)
|
71
|
+
end
|
72
|
+
if node.children[1] == :attr_writer || node.children[1] == :attr_accessor
|
73
|
+
pins.push Solargraph::Pin::Attribute.new(
|
74
|
+
location: loc,
|
75
|
+
closure: clos,
|
76
|
+
name: "#{a.children[0]}=",
|
77
|
+
comments: cmnt,
|
78
|
+
access: :writer,
|
79
|
+
scope: region.scope || :instance,
|
80
|
+
visibility: region.visibility
|
81
|
+
)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [void]
|
87
|
+
def process_include
|
88
|
+
if node.children[2].is_a?(AST::Node) && node.children[2].type == :const
|
89
|
+
cp = region.closure
|
90
|
+
node.children[2..-1].each do |i|
|
91
|
+
pins.push Pin::Reference::Include.new(
|
92
|
+
location: get_node_location(i),
|
93
|
+
closure: cp,
|
94
|
+
name: unpack_name(i)
|
95
|
+
)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def process_prepend
|
101
|
+
if node.children[2].is_a?(AST::Node) && node.children[2].type == :const
|
102
|
+
cp = region.closure
|
103
|
+
node.children[2..-1].each do |i|
|
104
|
+
pins.push Pin::Reference::Prepend.new(
|
105
|
+
location: get_node_location(i),
|
106
|
+
closure: cp,
|
107
|
+
name: unpack_name(i)
|
108
|
+
)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [void]
|
114
|
+
def process_extend
|
115
|
+
node.children[2..-1].each do |i|
|
116
|
+
loc = get_node_location(node)
|
117
|
+
if i.type == :self
|
118
|
+
pins.push Pin::Reference::Extend.new(
|
119
|
+
location: loc,
|
120
|
+
closure: region.closure,
|
121
|
+
name: region.closure.full_context.namespace
|
122
|
+
)
|
123
|
+
else
|
124
|
+
pins.push Pin::Reference::Extend.new(
|
125
|
+
location: loc,
|
126
|
+
closure: region.closure,
|
127
|
+
name: unpack_name(i)
|
128
|
+
)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# @return [void]
|
134
|
+
def process_require
|
135
|
+
if node.children[2].is_a?(AST::Node) && node.children[2].type == :str
|
136
|
+
path = node.children[2].children[0].to_s
|
137
|
+
pins.push Pin::Reference::Require.new(get_node_location(node), path)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# @return [void]
|
142
|
+
def process_module_function
|
143
|
+
if node.children[2].nil?
|
144
|
+
# @todo Smelly instance variable access
|
145
|
+
region.instance_variable_set(:@visibility, :module_function)
|
146
|
+
elsif node.children[2].type == :sym || node.children[2].type == :str
|
147
|
+
node.children[2..-1].each do |x|
|
148
|
+
cn = x.children[0].to_s
|
149
|
+
ref = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == cn}.first
|
150
|
+
unless ref.nil?
|
151
|
+
pins.delete ref
|
152
|
+
mm = Solargraph::Pin::Method.new(
|
153
|
+
location: ref.location,
|
154
|
+
closure: ref.closure,
|
155
|
+
name: ref.name,
|
156
|
+
comments: ref.comments,
|
157
|
+
scope: :class,
|
158
|
+
visibility: :public,
|
159
|
+
node: ref.node
|
160
|
+
)
|
161
|
+
cm = Solargraph::Pin::Method.new(
|
162
|
+
location: ref.location,
|
163
|
+
closure: ref.closure,
|
164
|
+
name: ref.name,
|
165
|
+
comments: ref.comments,
|
166
|
+
scope: :instance,
|
167
|
+
visibility: :private,
|
168
|
+
node: ref.node)
|
169
|
+
pins.push mm, cm
|
170
|
+
pins.select{|pin| pin.is_a?(Pin::InstanceVariable) && pin.closure.path == ref.path}.each do |ivar|
|
171
|
+
pins.delete ivar
|
172
|
+
pins.push Solargraph::Pin::InstanceVariable.new(
|
173
|
+
location: ivar.location,
|
174
|
+
closure: cm,
|
175
|
+
name: ivar.name,
|
176
|
+
comments: ivar.comments,
|
177
|
+
assignment: ivar.assignment
|
178
|
+
)
|
179
|
+
pins.push Solargraph::Pin::InstanceVariable.new(
|
180
|
+
location: ivar.location,
|
181
|
+
closure: mm,
|
182
|
+
name: ivar.name,
|
183
|
+
comments: ivar.comments,
|
184
|
+
assignment: ivar.assignment
|
185
|
+
)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
elsif node.children[2].type == :def
|
190
|
+
NodeProcessor.process node.children[2], region.update(visibility: :module_function), pins, locals
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
# @return [void]
|
195
|
+
def process_private_constant
|
196
|
+
if node.children[2] && (node.children[2].type == :sym || node.children[2].type == :str)
|
197
|
+
cn = node.children[2].children[0].to_s
|
198
|
+
ref = pins.select{|p| [Solargraph::Pin::Namespace, Solargraph::Pin::Constant].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == cn}.first
|
199
|
+
# HACK: Smelly instance variable access
|
200
|
+
ref.instance_variable_set(:@visibility, :private) unless ref.nil?
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# @return [void]
|
205
|
+
def process_alias_method
|
206
|
+
loc = get_node_location(node)
|
207
|
+
pins.push Solargraph::Pin::MethodAlias.new(
|
208
|
+
location: get_node_location(node),
|
209
|
+
closure: region.closure,
|
210
|
+
name: node.children[2].children[0].to_s,
|
211
|
+
original: node.children[3].children[0].to_s,
|
212
|
+
scope: region.scope || :instance
|
213
|
+
)
|
214
|
+
end
|
215
|
+
|
216
|
+
# @return [Boolean]
|
217
|
+
def process_private_class_method
|
218
|
+
if node.children[2].type == :sym || node.children[2].type == :str
|
219
|
+
ref = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == node.children[2].children[0].to_s}.first
|
220
|
+
# HACK: Smelly instance variable access
|
221
|
+
ref.instance_variable_set(:@visibility, :private) unless ref.nil?
|
222
|
+
false
|
223
|
+
else
|
224
|
+
process_children region.update(scope: :class, visibility: :private)
|
225
|
+
true
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Parser
|
5
|
+
module Legacy
|
6
|
+
module NodeProcessors
|
7
|
+
class SymNode < Parser::NodeProcessor::Base
|
8
|
+
def process
|
9
|
+
pins.push Solargraph::Pin::Symbol.new(
|
10
|
+
get_node_location(node),
|
11
|
+
":#{node.children[0]}"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Parser
|
3
|
+
class NodeMethods
|
4
|
+
module_function
|
5
|
+
|
6
|
+
def unpack_name node
|
7
|
+
raise NotImplementedError
|
8
|
+
end
|
9
|
+
|
10
|
+
def infer_literal_type node
|
11
|
+
raise NotImplementedError
|
12
|
+
end
|
13
|
+
|
14
|
+
def calls_from node
|
15
|
+
raise NotImplementedError
|
16
|
+
end
|
17
|
+
|
18
|
+
def returns_from node
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
|
22
|
+
def process node
|
23
|
+
raise NotImplementedError
|
24
|
+
end
|
25
|
+
|
26
|
+
def references node
|
27
|
+
raise NotImplementedError
|
28
|
+
end
|
29
|
+
|
30
|
+
def chain node, filename = nil, in_block = false
|
31
|
+
raise NotImplementedError
|
32
|
+
end
|
33
|
+
|
34
|
+
def node? node
|
35
|
+
raise NotImplementedError
|
36
|
+
end
|
37
|
+
|
38
|
+
def convert_hash node
|
39
|
+
raise NotImplementedError
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Parser
|
5
|
+
# The processor classes used by SourceMap::Mapper to generate pins from
|
6
|
+
# parser nodes.
|
7
|
+
#
|
8
|
+
module NodeProcessor
|
9
|
+
autoload :Base, 'solargraph/parser/node_processor/base'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
@@processors ||= {}
|
13
|
+
|
14
|
+
# Register a processor for a node type.
|
15
|
+
#
|
16
|
+
# @param type [Symbol]
|
17
|
+
# @param cls [Class<NodeProcessor::Base>]
|
18
|
+
# @return [Class<NodeProcessor::Base>]
|
19
|
+
def register type, cls
|
20
|
+
@@processors[type] = cls
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param node [Parser::AST::Node]
|
25
|
+
# @param region [Region]
|
26
|
+
# @param pins [Array<Pin::Base>]
|
27
|
+
# @return [Array(Array<Pin::Base>, Array<Pin::Base>)]
|
28
|
+
def self.process node, region = Region.new, pins = [], locals = []
|
29
|
+
if pins.empty?
|
30
|
+
pins.push Pin::Namespace.new(
|
31
|
+
location: region.source.location,
|
32
|
+
name: ''
|
33
|
+
)
|
34
|
+
end
|
35
|
+
return [pins, locals] unless Parser.is_ast_node?(node)
|
36
|
+
klass = @@processors[node.type] || NodeProcessor::Base
|
37
|
+
processor = klass.new(node, region, pins, locals)
|
38
|
+
processor.process
|
39
|
+
[processor.pins, processor.locals]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Parser
|
5
|
+
module NodeProcessor
|
6
|
+
class Base
|
7
|
+
# @todo The base node processor should not include legacy node methods
|
8
|
+
# include Legacy::NodeMethods
|
9
|
+
|
10
|
+
# @return [Parser::AST::Node]
|
11
|
+
attr_reader :node
|
12
|
+
|
13
|
+
# @return [Region]
|
14
|
+
attr_reader :region
|
15
|
+
|
16
|
+
# @return [Array<Pin::Base>]
|
17
|
+
attr_reader :pins
|
18
|
+
|
19
|
+
# @return [Array<Pin::Base>]
|
20
|
+
attr_reader :locals
|
21
|
+
|
22
|
+
# @param node [Parser::AST::Node]
|
23
|
+
# @param region [Region]
|
24
|
+
# @param pins [Array<Pin::Base>]
|
25
|
+
def initialize node, region, pins, locals
|
26
|
+
@node = node
|
27
|
+
@region = region
|
28
|
+
@pins = pins
|
29
|
+
@locals = locals
|
30
|
+
end
|
31
|
+
|
32
|
+
# Subclasses should override this method to generate new pins.
|
33
|
+
#
|
34
|
+
# @return [void]
|
35
|
+
def process
|
36
|
+
process_children
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# @param subregion [Region]
|
42
|
+
# @return [void]
|
43
|
+
def process_children subregion = region
|
44
|
+
node.children.each do |child|
|
45
|
+
next unless Parser.is_ast_node?(child)
|
46
|
+
NodeProcessor.process(child, subregion, pins, locals)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param node [Parser::AST::Node]
|
51
|
+
# @return [Solargraph::Location]
|
52
|
+
def get_node_location(node)
|
53
|
+
range = Parser.node_range(node)
|
54
|
+
Location.new(region.filename, range)
|
55
|
+
end
|
56
|
+
|
57
|
+
def comments_for(node)
|
58
|
+
region.source.comments_for(node)
|
59
|
+
end
|
60
|
+
|
61
|
+
def named_path_pin position
|
62
|
+
pins.select{|pin| pin.is_a?(Pin::Closure) && pin.path && !pin.path.empty? && pin.location.range.contain?(position)}.last
|
63
|
+
end
|
64
|
+
|
65
|
+
# @todo Candidate for deprecation
|
66
|
+
def block_pin position
|
67
|
+
pins.select{|pin| pin.is_a?(Pin::Closure) && pin.location.range.contain?(position)}.last
|
68
|
+
end
|
69
|
+
|
70
|
+
# @todo Candidate for deprecation
|
71
|
+
def closure_pin position
|
72
|
+
pins.select{|pin| pin.is_a?(Pin::Closure) && pin.location.range.contain?(position)}.last
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|