solargraph 0.56.0 → 0.58.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/.gitattributes +2 -0
- data/.github/workflows/linting.yml +127 -0
- data/.github/workflows/plugins.yml +183 -7
- data/.github/workflows/rspec.yml +55 -5
- data/.github/workflows/typecheck.yml +6 -3
- data/.gitignore +6 -0
- data/.overcommit.yml +72 -0
- data/.rspec +1 -0
- data/.rubocop.yml +66 -0
- data/.rubocop_todo.yml +1279 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +92 -1
- data/README.md +8 -4
- data/Rakefile +125 -13
- data/bin/solargraph +3 -0
- data/lib/solargraph/api_map/cache.rb +110 -109
- data/lib/solargraph/api_map/constants.rb +279 -0
- data/lib/solargraph/api_map/index.rb +193 -175
- data/lib/solargraph/api_map/source_to_yard.rb +97 -88
- data/lib/solargraph/api_map/store.rb +384 -266
- data/lib/solargraph/api_map.rb +945 -973
- data/lib/solargraph/bench.rb +1 -0
- data/lib/solargraph/complex_type/type_methods.rb +228 -222
- data/lib/solargraph/complex_type/unique_type.rb +482 -475
- data/lib/solargraph/complex_type.rb +444 -423
- data/lib/solargraph/convention/active_support_concern.rb +111 -0
- data/lib/solargraph/convention/base.rb +17 -0
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -0
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +91 -0
- data/lib/solargraph/convention/data_definition.rb +105 -0
- data/lib/solargraph/convention/gemspec.rb +3 -2
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +61 -60
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +102 -100
- data/lib/solargraph/convention/struct_definition.rb +164 -101
- data/lib/solargraph/convention.rb +32 -2
- data/lib/solargraph/diagnostics/require_not_found.rb +53 -53
- data/lib/solargraph/diagnostics/rubocop.rb +118 -113
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +68 -66
- data/lib/solargraph/diagnostics/type_check.rb +55 -55
- data/lib/solargraph/doc_map.rb +439 -405
- data/lib/solargraph/environ.rb +9 -2
- data/lib/solargraph/equality.rb +34 -33
- data/lib/solargraph/gem_pins.rb +98 -88
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
- data/lib/solargraph/language_server/host/dispatch.rb +130 -128
- data/lib/solargraph/language_server/host/message_worker.rb +112 -109
- data/lib/solargraph/language_server/host/sources.rb +99 -99
- data/lib/solargraph/language_server/host.rb +878 -871
- data/lib/solargraph/language_server/message/base.rb +2 -1
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +114 -114
- data/lib/solargraph/language_server/message/extended/document.rb +23 -23
- data/lib/solargraph/language_server/message/text_document/completion.rb +56 -56
- data/lib/solargraph/language_server/message/text_document/definition.rb +40 -38
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +26 -26
- data/lib/solargraph/language_server/message/text_document/formatting.rb +148 -131
- data/lib/solargraph/language_server/message/text_document/hover.rb +58 -58
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +24 -24
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -24
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +2 -0
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +23 -23
- data/lib/solargraph/language_server/progress.rb +8 -0
- data/lib/solargraph/language_server/request.rb +4 -1
- data/lib/solargraph/library.rb +683 -666
- data/lib/solargraph/location.rb +82 -79
- data/lib/solargraph/logging.rb +37 -28
- data/lib/solargraph/page.rb +3 -0
- data/lib/solargraph/parser/comment_ripper.rb +69 -62
- data/lib/solargraph/parser/flow_sensitive_typing.rb +255 -227
- data/lib/solargraph/parser/node_processor/base.rb +92 -87
- data/lib/solargraph/parser/node_processor.rb +62 -46
- data/lib/solargraph/parser/parser_gem/class_methods.rb +149 -159
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +166 -164
- data/lib/solargraph/parser/parser_gem/node_methods.rb +486 -497
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -21
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +59 -59
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +15 -15
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +46 -45
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +1 -21
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +53 -53
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +23 -21
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +40 -40
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +59 -53
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +0 -22
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -41
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -16
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +38 -37
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +52 -43
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +291 -271
- data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors.rb +70 -66
- data/lib/solargraph/parser/region.rb +69 -66
- data/lib/solargraph/parser/snippet.rb +17 -15
- data/lib/solargraph/pin/base.rb +729 -651
- data/lib/solargraph/pin/base_variable.rb +126 -125
- data/lib/solargraph/pin/block.rb +104 -103
- data/lib/solargraph/pin/breakable.rb +9 -9
- data/lib/solargraph/pin/callable.rb +231 -218
- data/lib/solargraph/pin/closure.rb +72 -74
- data/lib/solargraph/pin/common.rb +79 -75
- data/lib/solargraph/pin/constant.rb +2 -0
- data/lib/solargraph/pin/conversions.rb +123 -123
- data/lib/solargraph/pin/delegated_method.rb +120 -120
- data/lib/solargraph/pin/documenting.rb +114 -114
- data/lib/solargraph/pin/instance_variable.rb +34 -34
- data/lib/solargraph/pin/keyword.rb +20 -20
- data/lib/solargraph/pin/local_variable.rb +75 -76
- data/lib/solargraph/pin/method.rb +672 -651
- data/lib/solargraph/pin/method_alias.rb +34 -31
- data/lib/solargraph/pin/namespace.rb +115 -115
- data/lib/solargraph/pin/parameter.rb +275 -261
- data/lib/solargraph/pin/proxy_type.rb +39 -35
- data/lib/solargraph/pin/reference/override.rb +47 -33
- data/lib/solargraph/pin/reference/superclass.rb +15 -10
- data/lib/solargraph/pin/reference.rb +39 -22
- data/lib/solargraph/pin/search.rb +61 -56
- data/lib/solargraph/pin/signature.rb +61 -59
- data/lib/solargraph/pin/symbol.rb +53 -48
- data/lib/solargraph/pin/until.rb +18 -18
- data/lib/solargraph/pin/while.rb +18 -18
- data/lib/solargraph/pin.rb +44 -44
- data/lib/solargraph/pin_cache.rb +245 -185
- data/lib/solargraph/position.rb +132 -116
- data/lib/solargraph/range.rb +112 -107
- data/lib/solargraph/rbs_map/conversions.rb +823 -773
- data/lib/solargraph/rbs_map/core_fills.rb +18 -0
- data/lib/solargraph/rbs_map/core_map.rb +58 -51
- data/lib/solargraph/rbs_map/stdlib_map.rb +43 -43
- data/lib/solargraph/rbs_map.rb +163 -150
- data/lib/solargraph/shell.rb +352 -268
- data/lib/solargraph/source/chain/call.rb +337 -333
- data/lib/solargraph/source/chain/constant.rb +26 -89
- data/lib/solargraph/source/chain/hash.rb +34 -34
- data/lib/solargraph/source/chain/if.rb +28 -28
- data/lib/solargraph/source/chain/instance_variable.rb +13 -13
- data/lib/solargraph/source/chain/link.rb +11 -2
- data/lib/solargraph/source/chain/literal.rb +48 -48
- data/lib/solargraph/source/chain/or.rb +23 -23
- data/lib/solargraph/source/chain.rb +291 -282
- data/lib/solargraph/source/change.rb +82 -82
- data/lib/solargraph/source/cursor.rb +166 -167
- data/lib/solargraph/source/encoding_fixes.rb +23 -23
- data/lib/solargraph/source/source_chainer.rb +194 -194
- data/lib/solargraph/source/updater.rb +55 -55
- data/lib/solargraph/source.rb +498 -495
- data/lib/solargraph/source_map/clip.rb +226 -234
- data/lib/solargraph/source_map/data.rb +34 -30
- data/lib/solargraph/source_map/mapper.rb +259 -259
- data/lib/solargraph/source_map.rb +212 -200
- data/lib/solargraph/type_checker/checks.rb +124 -124
- data/lib/solargraph/type_checker/param_def.rb +37 -35
- data/lib/solargraph/type_checker/problem.rb +32 -32
- data/lib/solargraph/type_checker/rules.rb +84 -62
- data/lib/solargraph/type_checker.rb +814 -699
- data/lib/solargraph/version.rb +5 -5
- data/lib/solargraph/workspace/config.rb +255 -239
- data/lib/solargraph/workspace/require_paths.rb +97 -0
- data/lib/solargraph/workspace.rb +220 -249
- data/lib/solargraph/yard_map/helpers.rb +44 -16
- data/lib/solargraph/yard_map/mapper/to_constant.rb +5 -5
- data/lib/solargraph/yard_map/mapper/to_method.rb +130 -134
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +31 -30
- data/lib/solargraph/yard_map/mapper.rb +79 -79
- data/lib/solargraph/yard_map/to_method.rb +89 -88
- data/lib/solargraph/yardoc.rb +87 -49
- data/lib/solargraph.rb +105 -90
- data/rbs/fills/bundler/0/bundler.rbs +4271 -0
- data/rbs/fills/open3/0/open3.rbs +172 -0
- data/rbs/fills/rubygems/0/basic_specification.rbs +326 -0
- data/rbs/fills/rubygems/0/errors.rbs +364 -0
- data/rbs/fills/rubygems/0/spec_fetcher.rbs +107 -0
- data/rbs/fills/rubygems/0/specification.rbs +1753 -0
- data/rbs/fills/{tuple.rbs → tuple/tuple.rbs} +2 -3
- data/rbs/shims/ast/0/node.rbs +5 -0
- data/rbs/shims/ast/2.4/.rbs_meta.yaml +9 -0
- data/rbs/shims/ast/2.4/ast.rbs +73 -0
- data/rbs/shims/parser/3.2.0.1/builders/default.rbs +195 -0
- data/rbs/shims/parser/3.2.0.1/manifest.yaml +7 -0
- data/rbs/shims/parser/3.2.0.1/parser.rbs +201 -0
- data/rbs/shims/parser/3.2.0.1/polyfill.rbs +4 -0
- data/rbs/shims/thor/1.2.0.1/.rbs_meta.yaml +9 -0
- data/rbs/shims/thor/1.2.0.1/manifest.yaml +7 -0
- data/rbs/shims/thor/1.2.0.1/thor.rbs +17 -0
- data/rbs_collection.yaml +4 -4
- data/solargraph.gemspec +26 -5
- metadata +187 -15
- data/lib/.rubocop.yml +0 -22
- data/lib/solargraph/parser/node_methods.rb +0 -97
|
@@ -1,271 +1,291 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Parser
|
|
5
|
-
module ParserGem
|
|
6
|
-
module NodeProcessors
|
|
7
|
-
class SendNode < Parser::NodeProcessor::Base
|
|
8
|
-
include ParserGem::NodeMethods
|
|
9
|
-
|
|
10
|
-
def process
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
ref
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Parser
|
|
5
|
+
module ParserGem
|
|
6
|
+
module NodeProcessors
|
|
7
|
+
class SendNode < Parser::NodeProcessor::Base
|
|
8
|
+
include ParserGem::NodeMethods
|
|
9
|
+
|
|
10
|
+
def process
|
|
11
|
+
# @sg-ignore Variable type could not be inferred for method_name
|
|
12
|
+
# @type [Symbol]
|
|
13
|
+
method_name = node.children[1]
|
|
14
|
+
# :nocov:
|
|
15
|
+
unless method_name.instance_of?(Symbol)
|
|
16
|
+
Solargraph.assert_or_log(:parser_method_name, "Expected method name to be a Symbol, got #{method_name.class} for node #{node.inspect}")
|
|
17
|
+
return process_children
|
|
18
|
+
end
|
|
19
|
+
# :nocov:
|
|
20
|
+
if node.children[0].nil?
|
|
21
|
+
if [:private, :public, :protected].include?(method_name)
|
|
22
|
+
process_visibility
|
|
23
|
+
elsif method_name == :module_function
|
|
24
|
+
process_module_function
|
|
25
|
+
elsif [:attr_reader, :attr_writer, :attr_accessor].include?(method_name)
|
|
26
|
+
process_attribute
|
|
27
|
+
elsif method_name == :include
|
|
28
|
+
process_include
|
|
29
|
+
elsif method_name == :extend
|
|
30
|
+
process_extend
|
|
31
|
+
elsif method_name == :prepend
|
|
32
|
+
process_prepend
|
|
33
|
+
elsif method_name == :require
|
|
34
|
+
process_require
|
|
35
|
+
elsif method_name == :autoload
|
|
36
|
+
process_autoload
|
|
37
|
+
elsif method_name == :private_constant
|
|
38
|
+
process_private_constant
|
|
39
|
+
elsif method_name == :alias_method && node.children[2] && node.children[2] && node.children[2].type == :sym && node.children[3] && node.children[3].type == :sym
|
|
40
|
+
process_alias_method
|
|
41
|
+
elsif method_name == :private_class_method && node.children[2].is_a?(AST::Node)
|
|
42
|
+
# Processing a private class can potentially handle children on its own
|
|
43
|
+
return if process_private_class_method
|
|
44
|
+
end
|
|
45
|
+
elsif method_name == :require && node.children[0].to_s == '(const nil :Bundler)'
|
|
46
|
+
pins.push Pin::Reference::Require.new(Solargraph::Location.new(region.filename, Solargraph::Range.from_to(0, 0, 0, 0)), 'bundler/require', source: :parser)
|
|
47
|
+
end
|
|
48
|
+
process_children
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
# @return [void]
|
|
54
|
+
def process_visibility
|
|
55
|
+
if (node.children.length > 2)
|
|
56
|
+
node.children[2..-1].each do |child|
|
|
57
|
+
# @sg-ignore Variable type could not be inferred for method_name
|
|
58
|
+
# @type [Symbol]
|
|
59
|
+
visibility = node.children[1]
|
|
60
|
+
# :nocov:
|
|
61
|
+
unless visibility.instance_of?(Symbol)
|
|
62
|
+
Solargraph.assert_or_log(:parser_visibility, "Expected visibility name to be a Symbol, got #{visibility.class} for node #{node.inspect}")
|
|
63
|
+
return process_children
|
|
64
|
+
end
|
|
65
|
+
# :nocov:
|
|
66
|
+
if child.is_a?(::Parser::AST::Node) && (child.type == :sym || child.type == :str)
|
|
67
|
+
name = child.children[0].to_s
|
|
68
|
+
matches = pins.select{ |pin| pin.is_a?(Pin::Method) && pin.name == name && pin.namespace == region.closure.full_context.namespace && pin.context.scope == (region.scope || :instance)}
|
|
69
|
+
matches.each do |pin|
|
|
70
|
+
# @todo Smelly instance variable access
|
|
71
|
+
pin.instance_variable_set(:@visibility, visibility)
|
|
72
|
+
end
|
|
73
|
+
else
|
|
74
|
+
process_children region.update(visibility: visibility)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
else
|
|
78
|
+
# @todo Smelly instance variable access
|
|
79
|
+
region.instance_variable_set(:@visibility, node.children[1])
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @return [void]
|
|
84
|
+
def process_attribute
|
|
85
|
+
node.children[2..-1].each do |a|
|
|
86
|
+
loc = get_node_location(node)
|
|
87
|
+
clos = region.closure
|
|
88
|
+
cmnt = comments_for(node)
|
|
89
|
+
if node.children[1] == :attr_reader || node.children[1] == :attr_accessor
|
|
90
|
+
pins.push Solargraph::Pin::Method.new(
|
|
91
|
+
location: loc,
|
|
92
|
+
closure: clos,
|
|
93
|
+
name: a.children[0].to_s,
|
|
94
|
+
comments: cmnt,
|
|
95
|
+
scope: region.scope || :instance,
|
|
96
|
+
visibility: region.visibility,
|
|
97
|
+
attribute: true,
|
|
98
|
+
source: :parser
|
|
99
|
+
)
|
|
100
|
+
end
|
|
101
|
+
if node.children[1] == :attr_writer || node.children[1] == :attr_accessor
|
|
102
|
+
method_pin = Solargraph::Pin::Method.new(
|
|
103
|
+
location: loc,
|
|
104
|
+
closure: clos,
|
|
105
|
+
name: "#{a.children[0]}=",
|
|
106
|
+
comments: cmnt,
|
|
107
|
+
scope: region.scope || :instance,
|
|
108
|
+
visibility: region.visibility,
|
|
109
|
+
attribute: true,
|
|
110
|
+
source: :parser
|
|
111
|
+
)
|
|
112
|
+
pins.push method_pin
|
|
113
|
+
method_pin.parameters.push Pin::Parameter.new(name: 'value', decl: :arg, closure: pins.last, source: :parser)
|
|
114
|
+
if method_pin.return_type.defined?
|
|
115
|
+
pins.last.docstring.add_tag YARD::Tags::Tag.new(:param, '', pins.last.return_type.items.map(&:rooted_tags), 'value')
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# @return [void]
|
|
122
|
+
def process_include
|
|
123
|
+
if node.children[2].is_a?(AST::Node) && node.children[2].type == :const
|
|
124
|
+
cp = region.closure
|
|
125
|
+
node.children[2..-1].each do |i|
|
|
126
|
+
type = region.scope == :class ? Pin::Reference::Extend : Pin::Reference::Include
|
|
127
|
+
pins.push type.new(
|
|
128
|
+
location: get_node_location(i),
|
|
129
|
+
closure: cp,
|
|
130
|
+
name: unpack_name(i),
|
|
131
|
+
source: :parser
|
|
132
|
+
)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# @return [void]
|
|
138
|
+
def process_prepend
|
|
139
|
+
if node.children[2].is_a?(AST::Node) && node.children[2].type == :const
|
|
140
|
+
cp = region.closure
|
|
141
|
+
node.children[2..-1].each do |i|
|
|
142
|
+
pins.push Pin::Reference::Prepend.new(
|
|
143
|
+
location: get_node_location(i),
|
|
144
|
+
closure: cp,
|
|
145
|
+
name: unpack_name(i),
|
|
146
|
+
source: :parser
|
|
147
|
+
)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# @return [void]
|
|
153
|
+
def process_extend
|
|
154
|
+
node.children[2..-1].each do |i|
|
|
155
|
+
loc = get_node_location(node)
|
|
156
|
+
if i.type == :self
|
|
157
|
+
pins.push Pin::Reference::Extend.new(
|
|
158
|
+
location: loc,
|
|
159
|
+
closure: region.closure,
|
|
160
|
+
name: region.closure.full_context.namespace,
|
|
161
|
+
source: :parser
|
|
162
|
+
)
|
|
163
|
+
else
|
|
164
|
+
pins.push Pin::Reference::Extend.new(
|
|
165
|
+
location: loc,
|
|
166
|
+
closure: region.closure,
|
|
167
|
+
name: unpack_name(i),
|
|
168
|
+
source: :parser
|
|
169
|
+
)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# @return [void]
|
|
175
|
+
def process_require
|
|
176
|
+
if node.children[2].is_a?(AST::Node) && node.children[2].type == :str
|
|
177
|
+
path = node.children[2].children[0].to_s
|
|
178
|
+
pins.push Pin::Reference::Require.new(get_node_location(node), path, source: :parser)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# @return [void]
|
|
183
|
+
def process_autoload
|
|
184
|
+
if node.children[3].is_a?(AST::Node) && node.children[3].type == :str
|
|
185
|
+
path = node.children[3].children[0].to_s
|
|
186
|
+
pins.push Pin::Reference::Require.new(get_node_location(node), path, source: :parser)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# @return [void]
|
|
191
|
+
def process_module_function
|
|
192
|
+
if node.children[2].nil?
|
|
193
|
+
# @todo Smelly instance variable access
|
|
194
|
+
region.instance_variable_set(:@visibility, :module_function)
|
|
195
|
+
elsif node.children[2].type == :sym || node.children[2].type == :str
|
|
196
|
+
node.children[2..-1].each do |x|
|
|
197
|
+
cn = x.children[0].to_s
|
|
198
|
+
# @type [Pin::Method, nil]
|
|
199
|
+
ref = pins.find { |p| p.is_a?(Pin::Method) && p.namespace == region.closure.full_context.namespace && p.name == cn }
|
|
200
|
+
unless ref.nil?
|
|
201
|
+
pins.delete ref
|
|
202
|
+
mm = Solargraph::Pin::Method.new(
|
|
203
|
+
location: ref.location,
|
|
204
|
+
closure: ref.closure,
|
|
205
|
+
name: ref.name,
|
|
206
|
+
parameters: ref.parameters,
|
|
207
|
+
comments: ref.comments,
|
|
208
|
+
scope: :class,
|
|
209
|
+
visibility: :public,
|
|
210
|
+
node: ref.node,
|
|
211
|
+
source: :parser
|
|
212
|
+
)
|
|
213
|
+
cm = Solargraph::Pin::Method.new(
|
|
214
|
+
location: ref.location,
|
|
215
|
+
closure: ref.closure,
|
|
216
|
+
name: ref.name,
|
|
217
|
+
parameters: ref.parameters,
|
|
218
|
+
comments: ref.comments,
|
|
219
|
+
scope: :instance,
|
|
220
|
+
visibility: :private,
|
|
221
|
+
node: ref.node,
|
|
222
|
+
source: :parser)
|
|
223
|
+
pins.push mm, cm
|
|
224
|
+
pins.select{|pin| pin.is_a?(Pin::InstanceVariable) && pin.closure.path == ref.path}.each do |ivar|
|
|
225
|
+
pins.delete ivar
|
|
226
|
+
pins.push Solargraph::Pin::InstanceVariable.new(
|
|
227
|
+
location: ivar.location,
|
|
228
|
+
closure: cm,
|
|
229
|
+
name: ivar.name,
|
|
230
|
+
comments: ivar.comments,
|
|
231
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1114
|
|
232
|
+
assignment: ivar.assignment,
|
|
233
|
+
source: :parser
|
|
234
|
+
)
|
|
235
|
+
pins.push Solargraph::Pin::InstanceVariable.new(
|
|
236
|
+
location: ivar.location,
|
|
237
|
+
closure: mm,
|
|
238
|
+
name: ivar.name,
|
|
239
|
+
comments: ivar.comments,
|
|
240
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1114
|
|
241
|
+
assignment: ivar.assignment,
|
|
242
|
+
source: :parser
|
|
243
|
+
)
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
elsif node.children[2].type == :def
|
|
248
|
+
NodeProcessor.process node.children[2], region.update(visibility: :module_function), pins, locals
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# @return [void]
|
|
253
|
+
def process_private_constant
|
|
254
|
+
if node.children[2] && (node.children[2].type == :sym || node.children[2].type == :str)
|
|
255
|
+
cn = node.children[2].children[0].to_s
|
|
256
|
+
ref = pins.select{|p| [Solargraph::Pin::Namespace, Solargraph::Pin::Constant].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == cn}.first
|
|
257
|
+
# HACK: Smelly instance variable access
|
|
258
|
+
ref.instance_variable_set(:@visibility, :private) unless ref.nil?
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# @return [void]
|
|
263
|
+
def process_alias_method
|
|
264
|
+
loc = get_node_location(node)
|
|
265
|
+
pins.push Solargraph::Pin::MethodAlias.new(
|
|
266
|
+
location: get_node_location(node),
|
|
267
|
+
closure: region.closure,
|
|
268
|
+
name: node.children[2].children[0].to_s,
|
|
269
|
+
original: node.children[3].children[0].to_s,
|
|
270
|
+
scope: region.scope || :instance,
|
|
271
|
+
source: :parser
|
|
272
|
+
)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# @return [Boolean]
|
|
276
|
+
def process_private_class_method
|
|
277
|
+
if node.children[2].type == :sym || node.children[2].type == :str
|
|
278
|
+
ref = pins.select { |p| p.is_a?(Pin::Method) && p.namespace == region.closure.full_context.namespace && p.name == node.children[2].children[0].to_s }.first
|
|
279
|
+
# HACK: Smelly instance variable access
|
|
280
|
+
ref.instance_variable_set(:@visibility, :private) unless ref.nil?
|
|
281
|
+
false
|
|
282
|
+
else
|
|
283
|
+
process_children region.update(scope: :class, visibility: :private)
|
|
284
|
+
true
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
end
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Parser
|
|
5
|
-
module ParserGem
|
|
6
|
-
module NodeProcessors
|
|
7
|
-
class WhileNode < Parser::NodeProcessor::Base
|
|
8
|
-
include ParserGem::NodeMethods
|
|
9
|
-
|
|
10
|
-
def process
|
|
11
|
-
location = get_node_location(node)
|
|
12
|
-
# Note - this should not be considered a block, as the
|
|
13
|
-
# while statement doesn't create a closure - e.g.,
|
|
14
|
-
# variables created inside can be seen from outside as
|
|
15
|
-
# well
|
|
16
|
-
pins.push Solargraph::Pin::While.new(
|
|
17
|
-
location: location,
|
|
18
|
-
closure: region.closure,
|
|
19
|
-
node: node,
|
|
20
|
-
comments: comments_for(node),
|
|
21
|
-
source: :parser,
|
|
22
|
-
)
|
|
23
|
-
process_children region
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Parser
|
|
5
|
+
module ParserGem
|
|
6
|
+
module NodeProcessors
|
|
7
|
+
class WhileNode < Parser::NodeProcessor::Base
|
|
8
|
+
include ParserGem::NodeMethods
|
|
9
|
+
|
|
10
|
+
def process
|
|
11
|
+
location = get_node_location(node)
|
|
12
|
+
# Note - this should not be considered a block, as the
|
|
13
|
+
# while statement doesn't create a closure - e.g.,
|
|
14
|
+
# variables created inside can be seen from outside as
|
|
15
|
+
# well
|
|
16
|
+
pins.push Solargraph::Pin::While.new(
|
|
17
|
+
location: location,
|
|
18
|
+
closure: region.closure,
|
|
19
|
+
node: node,
|
|
20
|
+
comments: comments_for(node),
|
|
21
|
+
source: :parser,
|
|
22
|
+
)
|
|
23
|
+
process_children region
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|