solargraph 0.58.1 → 0.59.0.dev.1
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 +40 -36
- data/.github/workflows/rspec.yml +45 -13
- data/.github/workflows/typecheck.yml +2 -2
- data/.rubocop_todo.yml +27 -49
- data/README.md +3 -3
- data/Rakefile +1 -0
- data/lib/solargraph/api_map/cache.rb +110 -110
- data/lib/solargraph/api_map/constants.rb +289 -279
- data/lib/solargraph/api_map/index.rb +204 -193
- data/lib/solargraph/api_map/source_to_yard.rb +109 -97
- data/lib/solargraph/api_map/store.rb +387 -384
- data/lib/solargraph/api_map.rb +1000 -945
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +242 -228
- data/lib/solargraph/complex_type/unique_type.rb +632 -482
- data/lib/solargraph/complex_type.rb +549 -444
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +93 -91
- data/lib/solargraph/convention/data_definition.rb +108 -105
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +62 -61
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +103 -102
- data/lib/solargraph/convention/struct_definition.rb +168 -164
- data/lib/solargraph/diagnostics/require_not_found.rb +54 -53
- data/lib/solargraph/diagnostics/rubocop.rb +119 -118
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +70 -68
- data/lib/solargraph/diagnostics/type_check.rb +56 -55
- data/lib/solargraph/doc_map.rb +200 -439
- data/lib/solargraph/equality.rb +34 -34
- data/lib/solargraph/gem_pins.rb +97 -98
- data/lib/solargraph/language_server/host/dispatch.rb +131 -130
- data/lib/solargraph/language_server/host/message_worker.rb +113 -112
- data/lib/solargraph/language_server/host/sources.rb +100 -99
- data/lib/solargraph/language_server/host.rb +883 -878
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +109 -114
- data/lib/solargraph/language_server/message/extended/document.rb +24 -23
- data/lib/solargraph/language_server/message/text_document/completion.rb +58 -56
- data/lib/solargraph/language_server/message/text_document/definition.rb +42 -40
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +28 -26
- data/lib/solargraph/language_server/message/text_document/formatting.rb +150 -148
- data/lib/solargraph/language_server/message/text_document/hover.rb +60 -58
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +25 -24
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +27 -25
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +25 -23
- data/lib/solargraph/library.rb +729 -683
- data/lib/solargraph/location.rb +87 -82
- data/lib/solargraph/logging.rb +57 -37
- data/lib/solargraph/parser/comment_ripper.rb +76 -69
- data/lib/solargraph/parser/flow_sensitive_typing.rb +483 -255
- data/lib/solargraph/parser/node_processor/base.rb +122 -92
- data/lib/solargraph/parser/node_processor.rb +63 -62
- data/lib/solargraph/parser/parser_gem/class_methods.rb +167 -149
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +191 -166
- data/lib/solargraph/parser/parser_gem/node_methods.rb +506 -486
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -22
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +61 -59
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +24 -15
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +46 -46
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +60 -53
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +53 -23
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +41 -40
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +30 -29
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +61 -59
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -98
- data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -17
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +39 -38
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +53 -52
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +296 -291
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +33 -29
- data/lib/solargraph/parser/parser_gem/node_processors.rb +74 -70
- data/lib/solargraph/parser/region.rb +75 -69
- data/lib/solargraph/parser/snippet.rb +17 -17
- data/lib/solargraph/pin/base.rb +761 -729
- data/lib/solargraph/pin/base_variable.rb +418 -126
- data/lib/solargraph/pin/block.rb +126 -104
- data/lib/solargraph/pin/breakable.rb +13 -9
- data/lib/solargraph/pin/callable.rb +278 -231
- data/lib/solargraph/pin/closure.rb +68 -72
- data/lib/solargraph/pin/common.rb +94 -79
- data/lib/solargraph/pin/compound_statement.rb +55 -0
- data/lib/solargraph/pin/conversions.rb +124 -123
- data/lib/solargraph/pin/delegated_method.rb +131 -120
- data/lib/solargraph/pin/documenting.rb +115 -114
- data/lib/solargraph/pin/instance_variable.rb +38 -34
- data/lib/solargraph/pin/keyword.rb +16 -20
- data/lib/solargraph/pin/local_variable.rb +31 -75
- data/lib/solargraph/pin/method.rb +720 -672
- data/lib/solargraph/pin/method_alias.rb +42 -34
- data/lib/solargraph/pin/namespace.rb +121 -115
- data/lib/solargraph/pin/parameter.rb +338 -275
- data/lib/solargraph/pin/proxy_type.rb +40 -39
- data/lib/solargraph/pin/reference/override.rb +47 -47
- data/lib/solargraph/pin/reference/superclass.rb +17 -15
- data/lib/solargraph/pin/reference.rb +41 -39
- data/lib/solargraph/pin/search.rb +62 -61
- data/lib/solargraph/pin/signature.rb +69 -61
- data/lib/solargraph/pin/symbol.rb +53 -53
- data/lib/solargraph/pin/until.rb +18 -18
- data/lib/solargraph/pin/while.rb +18 -18
- data/lib/solargraph/pin.rb +46 -44
- data/lib/solargraph/pin_cache.rb +665 -245
- data/lib/solargraph/position.rb +118 -119
- data/lib/solargraph/range.rb +112 -112
- data/lib/solargraph/rbs_map/conversions.rb +846 -823
- data/lib/solargraph/rbs_map/core_map.rb +65 -58
- data/lib/solargraph/rbs_map/stdlib_map.rb +72 -43
- data/lib/solargraph/rbs_map.rb +217 -163
- data/lib/solargraph/shell.rb +397 -352
- data/lib/solargraph/source/chain/call.rb +372 -337
- data/lib/solargraph/source/chain/constant.rb +28 -26
- data/lib/solargraph/source/chain/hash.rb +35 -34
- data/lib/solargraph/source/chain/if.rb +29 -28
- data/lib/solargraph/source/chain/instance_variable.rb +34 -13
- data/lib/solargraph/source/chain/literal.rb +53 -48
- data/lib/solargraph/source/chain/or.rb +31 -23
- data/lib/solargraph/source/chain.rb +294 -291
- data/lib/solargraph/source/change.rb +89 -82
- data/lib/solargraph/source/cursor.rb +172 -166
- data/lib/solargraph/source/source_chainer.rb +204 -194
- data/lib/solargraph/source/updater.rb +59 -55
- data/lib/solargraph/source.rb +524 -498
- data/lib/solargraph/source_map/clip.rb +237 -226
- data/lib/solargraph/source_map/data.rb +37 -34
- data/lib/solargraph/source_map/mapper.rb +282 -259
- data/lib/solargraph/source_map.rb +220 -212
- data/lib/solargraph/type_checker/problem.rb +34 -32
- data/lib/solargraph/type_checker/rules.rb +157 -84
- data/lib/solargraph/type_checker.rb +895 -814
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +257 -255
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +98 -97
- data/lib/solargraph/workspace.rb +362 -220
- data/lib/solargraph/yard_map/helpers.rb +45 -44
- data/lib/solargraph/yard_map/mapper/to_method.rb +134 -130
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +32 -31
- data/lib/solargraph/yard_map/mapper.rb +84 -79
- data/lib/solargraph/yardoc.rb +97 -87
- data/lib/solargraph.rb +126 -105
- data/rbs/fills/rubygems/0/dependency.rbs +193 -0
- data/rbs/fills/tuple/tuple.rbs +28 -0
- data/rbs/shims/ast/0/node.rbs +5 -0
- data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
- data/rbs_collection.yaml +1 -1
- data/solargraph.gemspec +2 -1
- metadata +22 -17
- data/lib/solargraph/type_checker/checks.rb +0 -124
- data/lib/solargraph/type_checker/param_def.rb +0 -37
- data/lib/solargraph/yard_map/to_method.rb +0 -89
- data/sig/shims/ast/0/node.rbs +0 -5
- /data/{sig → rbs}/shims/ast/2.4/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/ast/2.4/ast.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/builders/default.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/parser.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/polyfill.rbs +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/thor.rbs +0 -0
|
@@ -1,259 +1,282 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
class SourceMap
|
|
5
|
-
# The Mapper generates pins and other data for SourceMaps.
|
|
6
|
-
#
|
|
7
|
-
# This class is used internally by the SourceMap class. Users should not
|
|
8
|
-
# normally need to call it directly.
|
|
9
|
-
#
|
|
10
|
-
class Mapper
|
|
11
|
-
# include Source::NodeMethods
|
|
12
|
-
|
|
13
|
-
private_class_method :new
|
|
14
|
-
|
|
15
|
-
DIRECTIVE_REGEXP = /(@\!method|@\!attribute|@\!visibility|@\!domain|@\!macro|@\!parse|@\!override)/.freeze
|
|
16
|
-
|
|
17
|
-
# Generate the data.
|
|
18
|
-
#
|
|
19
|
-
# @param source [Source]
|
|
20
|
-
# @return [Array]
|
|
21
|
-
def map source
|
|
22
|
-
@source = source
|
|
23
|
-
@filename = source.filename
|
|
24
|
-
@code = source.code
|
|
25
|
-
@comments = source.comments
|
|
26
|
-
@pins, @locals = Parser.map(source)
|
|
27
|
-
@
|
|
28
|
-
@
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
#
|
|
33
|
-
# Solargraph.logger.warn e.
|
|
34
|
-
#
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# @param
|
|
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
|
-
parse
|
|
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
|
-
pins.push
|
|
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
|
-
end
|
|
244
|
-
|
|
245
|
-
# @
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
class SourceMap
|
|
5
|
+
# The Mapper generates pins and other data for SourceMaps.
|
|
6
|
+
#
|
|
7
|
+
# This class is used internally by the SourceMap class. Users should not
|
|
8
|
+
# normally need to call it directly.
|
|
9
|
+
#
|
|
10
|
+
class Mapper
|
|
11
|
+
# include Source::NodeMethods
|
|
12
|
+
|
|
13
|
+
private_class_method :new
|
|
14
|
+
|
|
15
|
+
DIRECTIVE_REGEXP = /(@\!method|@\!attribute|@\!visibility|@\!domain|@\!macro|@\!parse|@\!override)/.freeze
|
|
16
|
+
|
|
17
|
+
# Generate the data.
|
|
18
|
+
#
|
|
19
|
+
# @param source [Source]
|
|
20
|
+
# @return [Array]
|
|
21
|
+
def map source
|
|
22
|
+
@source = source
|
|
23
|
+
@filename = source.filename
|
|
24
|
+
@code = source.code
|
|
25
|
+
@comments = source.comments
|
|
26
|
+
@pins, @locals = Parser.map(source)
|
|
27
|
+
# @param p [Solargraph::Pin::Base]
|
|
28
|
+
@pins.each { |p| p.source = :code }
|
|
29
|
+
@locals.each { |l| l.source = :code }
|
|
30
|
+
process_comment_directives
|
|
31
|
+
[@pins, @locals]
|
|
32
|
+
# rescue Exception => e
|
|
33
|
+
# Solargraph.logger.warn "Error mapping #{source.filename}: [#{e.class}] #{e.message}"
|
|
34
|
+
# Solargraph.logger.warn e.backtrace.join("\n")
|
|
35
|
+
# [[], []]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @param filename [String]
|
|
39
|
+
# @param code [String]
|
|
40
|
+
# @return [Array]
|
|
41
|
+
def unmap filename, code
|
|
42
|
+
s = Position.new(0, 0)
|
|
43
|
+
e = Position.from_offset(code, code.length)
|
|
44
|
+
location = Location.new(filename, Range.new(s, e))
|
|
45
|
+
[[Pin::Namespace.new(location: location, name: '', source: :source_map)], []]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class << self
|
|
49
|
+
# @param source [Source]
|
|
50
|
+
# @return [Array]
|
|
51
|
+
def map source
|
|
52
|
+
# @sg-ignore Need to add nil check here
|
|
53
|
+
return new.unmap(source.filename, source.code) unless source.parsed?
|
|
54
|
+
new.map source
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# @return [Array<Solargraph::Pin::Base>]
|
|
59
|
+
def pins
|
|
60
|
+
# @type [Array<Solargraph::Pin::Base>]
|
|
61
|
+
@pins ||= []
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# @param position [Solargraph::Position]
|
|
65
|
+
# @return [Solargraph::Pin::Closure]
|
|
66
|
+
def closure_at(position)
|
|
67
|
+
# @sg-ignore Need to add nil check here
|
|
68
|
+
pins.select{|pin| pin.is_a?(Pin::Closure) and pin.location.range.contain?(position)}.last
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# @param source_position [Position]
|
|
72
|
+
# @param comment_position [Position]
|
|
73
|
+
# @param comment [String]
|
|
74
|
+
# @return [void]
|
|
75
|
+
def process_comment source_position, comment_position, comment
|
|
76
|
+
return unless comment.encode('UTF-8', invalid: :replace, replace: '?') =~ DIRECTIVE_REGEXP
|
|
77
|
+
cmnt = remove_inline_comment_hashes(comment)
|
|
78
|
+
parse = Solargraph::Source.parse_docstring(cmnt)
|
|
79
|
+
last_line = 0
|
|
80
|
+
# @param d [YARD::Tags::Directive]
|
|
81
|
+
parse.directives.each do |d|
|
|
82
|
+
line_num = find_directive_line_number(cmnt, d.tag.tag_name, last_line)
|
|
83
|
+
pos = Solargraph::Position.new(comment_position.line + line_num - 1, comment_position.column)
|
|
84
|
+
process_directive(source_position, pos, d)
|
|
85
|
+
last_line = line_num + 1
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# @param comment [String]
|
|
90
|
+
# @param tag [String]
|
|
91
|
+
# @param start [Integer]
|
|
92
|
+
# @return [Integer]
|
|
93
|
+
def find_directive_line_number comment, tag, start
|
|
94
|
+
# Avoid overruning the index
|
|
95
|
+
return start unless start < comment.lines.length
|
|
96
|
+
# @sg-ignore Need to add nil check here
|
|
97
|
+
num = comment.lines[start..-1].find_index do |line|
|
|
98
|
+
# Legacy method directives might be `@method` instead of `@!method`
|
|
99
|
+
# @todo Legacy syntax should probably emit a warning
|
|
100
|
+
line.include?("@!#{tag}") || (tag == 'method' && line.include?("@#{tag}"))
|
|
101
|
+
end
|
|
102
|
+
# @sg-ignore Need to add nil check here
|
|
103
|
+
num.to_i + start
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# @param source_position [Position]
|
|
107
|
+
# @param comment_position [Position]
|
|
108
|
+
# @param directive [YARD::Tags::Directive]
|
|
109
|
+
# @return [void]
|
|
110
|
+
def process_directive source_position, comment_position, directive
|
|
111
|
+
# @sg-ignore Need to add nil check here
|
|
112
|
+
docstring = Solargraph::Source.parse_docstring(directive.tag.text).to_docstring
|
|
113
|
+
location = Location.new(@filename, Range.new(comment_position, comment_position))
|
|
114
|
+
case directive.tag.tag_name
|
|
115
|
+
when 'method'
|
|
116
|
+
namespace = closure_at(source_position) || @pins.first
|
|
117
|
+
# @todo Missed nil violation
|
|
118
|
+
# @todo Need to add nil check here
|
|
119
|
+
if namespace.location.range.start.line < comment_position.line
|
|
120
|
+
namespace = closure_at(comment_position)
|
|
121
|
+
end
|
|
122
|
+
begin
|
|
123
|
+
src = Solargraph::Source.load_string("def #{directive.tag.name};end", @source.filename)
|
|
124
|
+
region = Parser::Region.new(source: src, closure: namespace)
|
|
125
|
+
# @type [Array<Pin::Method>]
|
|
126
|
+
method_gen_pins = Parser.process_node(src.node, region).first.select { |pin| pin.is_a?(Pin::Method) }
|
|
127
|
+
gen_pin = method_gen_pins.last
|
|
128
|
+
return if gen_pin.nil?
|
|
129
|
+
# Move the location to the end of the line so it gets recognized
|
|
130
|
+
# as originating from a comment
|
|
131
|
+
shifted = Solargraph::Position.new(comment_position.line, @code.lines[comment_position.line].to_s.chomp.length)
|
|
132
|
+
# @todo: Smelly instance variable access
|
|
133
|
+
gen_pin.instance_variable_set(:@comments, docstring.all.to_s)
|
|
134
|
+
gen_pin.instance_variable_set(:@location, Solargraph::Location.new(@filename, Range.new(shifted, shifted)))
|
|
135
|
+
gen_pin.instance_variable_set(:@explicit, false)
|
|
136
|
+
@pins.push gen_pin
|
|
137
|
+
rescue Parser::SyntaxError => e
|
|
138
|
+
# @todo Handle error in directive
|
|
139
|
+
end
|
|
140
|
+
when 'attribute'
|
|
141
|
+
return if directive.tag.name.nil?
|
|
142
|
+
namespace = closure_at(source_position)
|
|
143
|
+
t = (directive.tag.types.nil? || directive.tag.types.empty?) ? nil : directive.tag.types.flatten.join('')
|
|
144
|
+
if t.nil? || t.include?('r')
|
|
145
|
+
pins.push Solargraph::Pin::Method.new(
|
|
146
|
+
location: location,
|
|
147
|
+
closure: namespace,
|
|
148
|
+
name: directive.tag.name,
|
|
149
|
+
comments: docstring.all.to_s,
|
|
150
|
+
scope: namespace.is_a?(Pin::Singleton) ? :class : :instance,
|
|
151
|
+
visibility: :public,
|
|
152
|
+
explicit: false,
|
|
153
|
+
attribute: true,
|
|
154
|
+
source: :source_map
|
|
155
|
+
)
|
|
156
|
+
end
|
|
157
|
+
if t.nil? || t.include?('w')
|
|
158
|
+
method_pin = Solargraph::Pin::Method.new(
|
|
159
|
+
location: location,
|
|
160
|
+
closure: namespace,
|
|
161
|
+
name: "#{directive.tag.name}=",
|
|
162
|
+
comments: docstring.all.to_s,
|
|
163
|
+
scope: namespace.is_a?(Pin::Singleton) ? :class : :instance,
|
|
164
|
+
visibility: :public,
|
|
165
|
+
attribute: true,
|
|
166
|
+
source: :source_map
|
|
167
|
+
)
|
|
168
|
+
pins.push method_pin
|
|
169
|
+
method_pin.parameters.push Pin::Parameter.new(name: 'value', decl: :arg, closure: pins.last, source: :source_map)
|
|
170
|
+
if pins.last.return_type.defined?
|
|
171
|
+
pins.last.docstring.add_tag YARD::Tags::Tag.new(:param, '', pins.last.return_type.to_s.split(', '), 'value')
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
when 'visibility'
|
|
175
|
+
|
|
176
|
+
kind = directive.tag.text&.to_sym
|
|
177
|
+
# @sg-ignore Need to look at Tuple#include? handling
|
|
178
|
+
return unless [:private, :protected, :public].include?(kind)
|
|
179
|
+
|
|
180
|
+
name = directive.tag.name
|
|
181
|
+
closure = closure_at(source_position) || @pins.first
|
|
182
|
+
# @todo Missed nil violation
|
|
183
|
+
# @todo Need to add nil check here
|
|
184
|
+
if closure.location.range.start.line < comment_position.line
|
|
185
|
+
closure = closure_at(comment_position)
|
|
186
|
+
end
|
|
187
|
+
if closure.is_a?(Pin::Method) && no_empty_lines?(comment_position.line, source_position.line)
|
|
188
|
+
# @todo Smelly instance variable access
|
|
189
|
+
closure.instance_variable_set(:@visibility, kind)
|
|
190
|
+
else
|
|
191
|
+
matches = pins.select{ |pin| pin.is_a?(Pin::Method) && pin.name == name && pin.namespace == namespace && pin.context.scope == namespace.is_a?(Pin::Singleton) ? :class : :instance }
|
|
192
|
+
matches.each do |pin|
|
|
193
|
+
# @todo Smelly instance variable access
|
|
194
|
+
pin.instance_variable_set(:@visibility, kind)
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
when 'parse'
|
|
199
|
+
begin
|
|
200
|
+
ns = closure_at(source_position)
|
|
201
|
+
# @sg-ignore Need to add nil check here
|
|
202
|
+
src = Solargraph::Source.load_string(directive.tag.text, @source.filename)
|
|
203
|
+
region = Parser::Region.new(source: src, closure: ns)
|
|
204
|
+
# @todo These pins may need to be marked not explicit
|
|
205
|
+
index = @pins.length
|
|
206
|
+
loff = if @code.lines[comment_position.line].strip.end_with?('@!parse')
|
|
207
|
+
comment_position.line + 1
|
|
208
|
+
else
|
|
209
|
+
comment_position.line
|
|
210
|
+
end
|
|
211
|
+
locals = []
|
|
212
|
+
ivars = []
|
|
213
|
+
Parser.process_node(src.node, region, @pins, locals, ivars)
|
|
214
|
+
@pins.concat ivars
|
|
215
|
+
# @sg-ignore Need to add nil check here
|
|
216
|
+
@pins[index..-1].each do |p|
|
|
217
|
+
# @todo Smelly instance variable access
|
|
218
|
+
p.location.range.start.instance_variable_set(:@line, p.location.range.start.line + loff)
|
|
219
|
+
p.location.range.ending.instance_variable_set(:@line, p.location.range.ending.line + loff)
|
|
220
|
+
end
|
|
221
|
+
rescue Parser::SyntaxError => e
|
|
222
|
+
# @todo Handle parser errors in !parse directives
|
|
223
|
+
end
|
|
224
|
+
when 'domain'
|
|
225
|
+
namespace = closure_at(source_position) || Pin::ROOT_PIN
|
|
226
|
+
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
227
|
+
namespace.domains.concat directive.tag.types unless directive.tag.types.nil?
|
|
228
|
+
when 'override'
|
|
229
|
+
# @sg-ignore Need to add nil check here
|
|
230
|
+
pins.push Pin::Reference::Override.new(location, directive.tag.name, docstring.tags,
|
|
231
|
+
source: :source_map)
|
|
232
|
+
when 'macro'
|
|
233
|
+
# @todo Handle macros
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# @param line1 [Integer]
|
|
238
|
+
# @param line2 [Integer]
|
|
239
|
+
# @sg-ignore Need to add nil check here
|
|
240
|
+
def no_empty_lines?(line1, line2)
|
|
241
|
+
# @sg-ignore Need to add nil check here
|
|
242
|
+
@code.lines[line1..line2].none? { |line| line.strip.empty? }
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
# @param comment [String]
|
|
246
|
+
# @return [String]
|
|
247
|
+
def remove_inline_comment_hashes comment
|
|
248
|
+
ctxt = ''
|
|
249
|
+
num = nil
|
|
250
|
+
started = false
|
|
251
|
+
comment.lines.each { |l|
|
|
252
|
+
# Trim the comment and minimum leading whitespace
|
|
253
|
+
p = l.encode('UTF-8', invalid: :replace, replace: '?').gsub(/^#+/, '')
|
|
254
|
+
if num.nil? && !p.strip.empty?
|
|
255
|
+
num = p.index(/[^ ]/)
|
|
256
|
+
started = true
|
|
257
|
+
elsif started && !p.strip.empty?
|
|
258
|
+
cur = p.index(/[^ ]/)
|
|
259
|
+
# @sg-ignore Need to add nil check here
|
|
260
|
+
num = cur if cur < num
|
|
261
|
+
end
|
|
262
|
+
ctxt += "#{p[num..-1]}" if started
|
|
263
|
+
}
|
|
264
|
+
ctxt
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# @return [void]
|
|
268
|
+
def process_comment_directives
|
|
269
|
+
return unless @code.encode('UTF-8', invalid: :replace, replace: '?') =~ DIRECTIVE_REGEXP
|
|
270
|
+
code_lines = @code.lines
|
|
271
|
+
@source.associated_comments.each do |line, comments|
|
|
272
|
+
src_pos = line ? Position.new(line, code_lines[line].to_s.chomp.index(/[^\s]/) || 0) : Position.new(code_lines.length, 0)
|
|
273
|
+
# @sg-ignore Need to add nil check here
|
|
274
|
+
com_pos = Position.new(line + 1 - comments.lines.length, 0)
|
|
275
|
+
process_comment(src_pos, com_pos, comments)
|
|
276
|
+
end
|
|
277
|
+
rescue StandardError => e
|
|
278
|
+
raise e.class, "Error processing comment directives in #{@filename}: #{e.message}"
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|