ruby-lsp 0.23.11 → 0.23.17
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/README.md +2 -2
- data/VERSION +1 -1
- data/exe/ruby-lsp-launcher +20 -11
- data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +1 -1
- data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +3 -5
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +82 -116
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +134 -183
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +9 -10
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +97 -217
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +139 -281
- data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +18 -19
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +23 -55
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +47 -61
- data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +17 -19
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +7 -11
- data/lib/ruby_indexer/test/class_variables_test.rb +14 -14
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +65 -40
- data/lib/ruby_indexer/test/configuration_test.rb +48 -7
- data/lib/ruby_indexer/test/constant_test.rb +34 -34
- data/lib/ruby_indexer/test/enhancements_test.rb +1 -1
- data/lib/ruby_indexer/test/index_test.rb +146 -135
- data/lib/ruby_indexer/test/instance_variables_test.rb +37 -37
- data/lib/ruby_indexer/test/method_test.rb +149 -123
- data/lib/ruby_indexer/test/prefix_tree_test.rb +13 -13
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +68 -73
- data/lib/ruby_indexer/test/test_case.rb +9 -3
- data/lib/ruby_indexer/test/uri_test.rb +15 -2
- data/lib/ruby_lsp/addon.rb +44 -71
- data/lib/ruby_lsp/base_server.rb +29 -32
- data/lib/ruby_lsp/client_capabilities.rb +10 -12
- data/lib/ruby_lsp/document.rb +40 -54
- data/lib/ruby_lsp/erb_document.rb +37 -41
- data/lib/ruby_lsp/global_state.rb +52 -57
- data/lib/ruby_lsp/internal.rb +2 -0
- data/lib/ruby_lsp/listeners/code_lens.rb +82 -89
- data/lib/ruby_lsp/listeners/completion.rb +67 -73
- data/lib/ruby_lsp/listeners/definition.rb +44 -58
- data/lib/ruby_lsp/listeners/document_highlight.rb +123 -150
- data/lib/ruby_lsp/listeners/document_link.rb +50 -70
- data/lib/ruby_lsp/listeners/document_symbol.rb +38 -52
- data/lib/ruby_lsp/listeners/folding_ranges.rb +40 -43
- data/lib/ruby_lsp/listeners/hover.rb +92 -110
- data/lib/ruby_lsp/listeners/inlay_hints.rb +4 -11
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +54 -56
- data/lib/ruby_lsp/listeners/signature_help.rb +12 -27
- data/lib/ruby_lsp/listeners/spec_style.rb +155 -0
- data/lib/ruby_lsp/listeners/test_discovery.rb +89 -0
- data/lib/ruby_lsp/listeners/test_style.rb +167 -90
- data/lib/ruby_lsp/node_context.rb +12 -39
- data/lib/ruby_lsp/rbs_document.rb +9 -7
- data/lib/ruby_lsp/requests/code_action_resolve.rb +63 -59
- data/lib/ruby_lsp/requests/code_actions.rb +14 -26
- data/lib/ruby_lsp/requests/code_lens.rb +20 -19
- data/lib/ruby_lsp/requests/completion.rb +7 -20
- data/lib/ruby_lsp/requests/completion_resolve.rb +6 -6
- data/lib/ruby_lsp/requests/definition.rb +7 -17
- data/lib/ruby_lsp/requests/diagnostics.rb +8 -11
- data/lib/ruby_lsp/requests/discover_tests.rb +18 -5
- data/lib/ruby_lsp/requests/document_highlight.rb +5 -15
- data/lib/ruby_lsp/requests/document_link.rb +6 -17
- data/lib/ruby_lsp/requests/document_symbol.rb +5 -8
- data/lib/ruby_lsp/requests/folding_ranges.rb +7 -15
- data/lib/ruby_lsp/requests/formatting.rb +6 -9
- data/lib/ruby_lsp/requests/go_to_relevant_file.rb +85 -0
- data/lib/ruby_lsp/requests/hover.rb +10 -20
- data/lib/ruby_lsp/requests/inlay_hints.rb +6 -17
- data/lib/ruby_lsp/requests/on_type_formatting.rb +32 -40
- data/lib/ruby_lsp/requests/prepare_rename.rb +4 -9
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +5 -15
- data/lib/ruby_lsp/requests/range_formatting.rb +5 -6
- data/lib/ruby_lsp/requests/references.rb +9 -53
- data/lib/ruby_lsp/requests/rename.rb +20 -46
- data/lib/ruby_lsp/requests/request.rb +8 -19
- data/lib/ruby_lsp/requests/selection_ranges.rb +6 -6
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +16 -35
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +7 -8
- data/lib/ruby_lsp/requests/signature_help.rb +8 -26
- data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
- data/lib/ruby_lsp/requests/support/common.rb +15 -55
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +27 -35
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +11 -14
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +22 -34
- data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
- data/lib/ruby_lsp/requests/support/sorbet.rb +29 -38
- data/lib/ruby_lsp/requests/support/source_uri.rb +20 -32
- data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +12 -19
- data/lib/ruby_lsp/requests/support/test_item.rb +16 -14
- data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +5 -6
- data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -4
- data/lib/ruby_lsp/response_builders/collection_response_builder.rb +5 -5
- data/lib/ruby_lsp/response_builders/document_symbol.rb +14 -19
- data/lib/ruby_lsp/response_builders/hover.rb +11 -14
- data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +60 -88
- data/lib/ruby_lsp/response_builders/signature_help.rb +5 -6
- data/lib/ruby_lsp/response_builders/test_collection.rb +43 -10
- data/lib/ruby_lsp/ruby_document.rb +24 -92
- data/lib/ruby_lsp/scope.rb +7 -11
- data/lib/ruby_lsp/scripts/compose_bundle.rb +6 -4
- data/lib/ruby_lsp/server.rb +182 -99
- data/lib/ruby_lsp/setup_bundler.rb +65 -60
- data/lib/ruby_lsp/static_docs.rb +11 -7
- data/lib/ruby_lsp/store.rb +29 -47
- data/lib/ruby_lsp/test_helper.rb +2 -12
- data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +191 -0
- data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +105 -0
- data/lib/ruby_lsp/test_reporters/test_unit_reporter.rb +94 -0
- data/lib/ruby_lsp/type_inferrer.rb +13 -14
- data/lib/ruby_lsp/utils.rb +92 -83
- metadata +9 -3
@@ -3,8 +3,6 @@
|
|
3
3
|
|
4
4
|
module RubyIndexer
|
5
5
|
class ReferenceFinder
|
6
|
-
extend T::Sig
|
7
|
-
|
8
6
|
class Target
|
9
7
|
extend T::Helpers
|
10
8
|
|
@@ -12,12 +10,10 @@ module RubyIndexer
|
|
12
10
|
end
|
13
11
|
|
14
12
|
class ConstTarget < Target
|
15
|
-
|
16
|
-
|
17
|
-
sig { returns(String) }
|
13
|
+
#: String
|
18
14
|
attr_reader :fully_qualified_name
|
19
15
|
|
20
|
-
|
16
|
+
#: (String fully_qualified_name) -> void
|
21
17
|
def initialize(fully_qualified_name)
|
22
18
|
super()
|
23
19
|
@fully_qualified_name = fully_qualified_name
|
@@ -25,12 +21,10 @@ module RubyIndexer
|
|
25
21
|
end
|
26
22
|
|
27
23
|
class MethodTarget < Target
|
28
|
-
|
29
|
-
|
30
|
-
sig { returns(String) }
|
24
|
+
#: String
|
31
25
|
attr_reader :method_name
|
32
26
|
|
33
|
-
|
27
|
+
#: (String method_name) -> void
|
34
28
|
def initialize(method_name)
|
35
29
|
super()
|
36
30
|
@method_name = method_name
|
@@ -38,12 +32,10 @@ module RubyIndexer
|
|
38
32
|
end
|
39
33
|
|
40
34
|
class InstanceVariableTarget < Target
|
41
|
-
|
42
|
-
|
43
|
-
sig { returns(String) }
|
35
|
+
#: String
|
44
36
|
attr_reader :name
|
45
37
|
|
46
|
-
|
38
|
+
#: (String name) -> void
|
47
39
|
def initialize(name)
|
48
40
|
super()
|
49
41
|
@name = name
|
@@ -51,18 +43,16 @@ module RubyIndexer
|
|
51
43
|
end
|
52
44
|
|
53
45
|
class Reference
|
54
|
-
|
55
|
-
|
56
|
-
sig { returns(String) }
|
46
|
+
#: String
|
57
47
|
attr_reader :name
|
58
48
|
|
59
|
-
|
49
|
+
#: Prism::Location
|
60
50
|
attr_reader :location
|
61
51
|
|
62
|
-
|
52
|
+
#: bool
|
63
53
|
attr_reader :declaration
|
64
54
|
|
65
|
-
|
55
|
+
#: (String name, Prism::Location location, declaration: bool) -> void
|
66
56
|
def initialize(name, location, declaration:)
|
67
57
|
@name = name
|
68
58
|
@location = location
|
@@ -70,22 +60,14 @@ module RubyIndexer
|
|
70
60
|
end
|
71
61
|
end
|
72
62
|
|
73
|
-
|
74
|
-
params(
|
75
|
-
target: Target,
|
76
|
-
index: RubyIndexer::Index,
|
77
|
-
dispatcher: Prism::Dispatcher,
|
78
|
-
uri: URI::Generic,
|
79
|
-
include_declarations: T::Boolean,
|
80
|
-
).void
|
81
|
-
end
|
63
|
+
#: (Target target, RubyIndexer::Index index, Prism::Dispatcher dispatcher, URI::Generic uri, ?include_declarations: bool) -> void
|
82
64
|
def initialize(target, index, dispatcher, uri, include_declarations: true)
|
83
65
|
@target = target
|
84
66
|
@index = index
|
85
67
|
@uri = uri
|
86
68
|
@include_declarations = include_declarations
|
87
|
-
@stack =
|
88
|
-
@references =
|
69
|
+
@stack = [] #: Array[String]
|
70
|
+
@references = [] #: Array[Reference]
|
89
71
|
|
90
72
|
dispatcher.register(
|
91
73
|
self,
|
@@ -119,34 +101,34 @@ module RubyIndexer
|
|
119
101
|
)
|
120
102
|
end
|
121
103
|
|
122
|
-
|
104
|
+
#: -> Array[Reference]
|
123
105
|
def references
|
124
106
|
return @references if @include_declarations
|
125
107
|
|
126
108
|
@references.reject(&:declaration)
|
127
109
|
end
|
128
110
|
|
129
|
-
|
111
|
+
#: (Prism::ClassNode node) -> void
|
130
112
|
def on_class_node_enter(node)
|
131
113
|
@stack << node.constant_path.slice
|
132
114
|
end
|
133
115
|
|
134
|
-
|
116
|
+
#: (Prism::ClassNode node) -> void
|
135
117
|
def on_class_node_leave(node)
|
136
118
|
@stack.pop
|
137
119
|
end
|
138
120
|
|
139
|
-
|
121
|
+
#: (Prism::ModuleNode node) -> void
|
140
122
|
def on_module_node_enter(node)
|
141
123
|
@stack << node.constant_path.slice
|
142
124
|
end
|
143
125
|
|
144
|
-
|
126
|
+
#: (Prism::ModuleNode node) -> void
|
145
127
|
def on_module_node_leave(node)
|
146
128
|
@stack.pop
|
147
129
|
end
|
148
130
|
|
149
|
-
|
131
|
+
#: (Prism::SingletonClassNode node) -> void
|
150
132
|
def on_singleton_class_node_enter(node)
|
151
133
|
expression = node.expression
|
152
134
|
return unless expression.is_a?(Prism::SelfNode)
|
@@ -154,12 +136,12 @@ module RubyIndexer
|
|
154
136
|
@stack << "<Class:#{@stack.last}>"
|
155
137
|
end
|
156
138
|
|
157
|
-
|
139
|
+
#: (Prism::SingletonClassNode node) -> void
|
158
140
|
def on_singleton_class_node_leave(node)
|
159
141
|
@stack.pop
|
160
142
|
end
|
161
143
|
|
162
|
-
|
144
|
+
#: (Prism::ConstantPathNode node) -> void
|
163
145
|
def on_constant_path_node_enter(node)
|
164
146
|
name = Index.constant_name(node)
|
165
147
|
return unless name
|
@@ -167,7 +149,7 @@ module RubyIndexer
|
|
167
149
|
collect_constant_references(name, node.location)
|
168
150
|
end
|
169
151
|
|
170
|
-
|
152
|
+
#: (Prism::ConstantReadNode node) -> void
|
171
153
|
def on_constant_read_node_enter(node)
|
172
154
|
name = Index.constant_name(node)
|
173
155
|
return unless name
|
@@ -175,7 +157,7 @@ module RubyIndexer
|
|
175
157
|
collect_constant_references(name, node.location)
|
176
158
|
end
|
177
159
|
|
178
|
-
|
160
|
+
#: (Prism::MultiWriteNode node) -> void
|
179
161
|
def on_multi_write_node_enter(node)
|
180
162
|
[*node.lefts, *node.rest, *node.rights].each do |target|
|
181
163
|
case target
|
@@ -185,7 +167,7 @@ module RubyIndexer
|
|
185
167
|
end
|
186
168
|
end
|
187
169
|
|
188
|
-
|
170
|
+
#: (Prism::ConstantPathWriteNode node) -> void
|
189
171
|
def on_constant_path_write_node_enter(node)
|
190
172
|
target = node.target
|
191
173
|
return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
|
@@ -196,7 +178,7 @@ module RubyIndexer
|
|
196
178
|
collect_constant_references(name, target.location)
|
197
179
|
end
|
198
180
|
|
199
|
-
|
181
|
+
#: (Prism::ConstantPathOrWriteNode node) -> void
|
200
182
|
def on_constant_path_or_write_node_enter(node)
|
201
183
|
target = node.target
|
202
184
|
return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
|
@@ -207,7 +189,7 @@ module RubyIndexer
|
|
207
189
|
collect_constant_references(name, target.location)
|
208
190
|
end
|
209
191
|
|
210
|
-
|
192
|
+
#: (Prism::ConstantPathOperatorWriteNode node) -> void
|
211
193
|
def on_constant_path_operator_write_node_enter(node)
|
212
194
|
target = node.target
|
213
195
|
return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
|
@@ -218,7 +200,7 @@ module RubyIndexer
|
|
218
200
|
collect_constant_references(name, target.location)
|
219
201
|
end
|
220
202
|
|
221
|
-
|
203
|
+
#: (Prism::ConstantPathAndWriteNode node) -> void
|
222
204
|
def on_constant_path_and_write_node_enter(node)
|
223
205
|
target = node.target
|
224
206
|
return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
|
@@ -229,27 +211,27 @@ module RubyIndexer
|
|
229
211
|
collect_constant_references(name, target.location)
|
230
212
|
end
|
231
213
|
|
232
|
-
|
214
|
+
#: (Prism::ConstantWriteNode node) -> void
|
233
215
|
def on_constant_write_node_enter(node)
|
234
216
|
collect_constant_references(node.name.to_s, node.name_loc)
|
235
217
|
end
|
236
218
|
|
237
|
-
|
219
|
+
#: (Prism::ConstantOrWriteNode node) -> void
|
238
220
|
def on_constant_or_write_node_enter(node)
|
239
221
|
collect_constant_references(node.name.to_s, node.name_loc)
|
240
222
|
end
|
241
223
|
|
242
|
-
|
224
|
+
#: (Prism::ConstantAndWriteNode node) -> void
|
243
225
|
def on_constant_and_write_node_enter(node)
|
244
226
|
collect_constant_references(node.name.to_s, node.name_loc)
|
245
227
|
end
|
246
228
|
|
247
|
-
|
229
|
+
#: (Prism::ConstantOperatorWriteNode node) -> void
|
248
230
|
def on_constant_operator_write_node_enter(node)
|
249
231
|
collect_constant_references(node.name.to_s, node.name_loc)
|
250
232
|
end
|
251
233
|
|
252
|
-
|
234
|
+
#: (Prism::DefNode node) -> void
|
253
235
|
def on_def_node_enter(node)
|
254
236
|
if @target.is_a?(MethodTarget) && (name = node.name.to_s) == @target.method_name
|
255
237
|
@references << Reference.new(name, node.name_loc, declaration: true)
|
@@ -260,53 +242,57 @@ module RubyIndexer
|
|
260
242
|
end
|
261
243
|
end
|
262
244
|
|
263
|
-
|
245
|
+
#: (Prism::DefNode node) -> void
|
264
246
|
def on_def_node_leave(node)
|
265
247
|
if node.receiver.is_a?(Prism::SelfNode)
|
266
248
|
@stack.pop
|
267
249
|
end
|
268
250
|
end
|
269
251
|
|
270
|
-
|
252
|
+
#: (Prism::InstanceVariableReadNode node) -> void
|
271
253
|
def on_instance_variable_read_node_enter(node)
|
272
254
|
collect_instance_variable_references(node.name.to_s, node.location, false)
|
273
255
|
end
|
274
256
|
|
275
|
-
|
257
|
+
#: (Prism::InstanceVariableWriteNode node) -> void
|
276
258
|
def on_instance_variable_write_node_enter(node)
|
277
259
|
collect_instance_variable_references(node.name.to_s, node.name_loc, true)
|
278
260
|
end
|
279
261
|
|
280
|
-
|
262
|
+
#: (Prism::InstanceVariableAndWriteNode node) -> void
|
281
263
|
def on_instance_variable_and_write_node_enter(node)
|
282
264
|
collect_instance_variable_references(node.name.to_s, node.name_loc, true)
|
283
265
|
end
|
284
266
|
|
285
|
-
|
267
|
+
#: (Prism::InstanceVariableOperatorWriteNode node) -> void
|
286
268
|
def on_instance_variable_operator_write_node_enter(node)
|
287
269
|
collect_instance_variable_references(node.name.to_s, node.name_loc, true)
|
288
270
|
end
|
289
271
|
|
290
|
-
|
272
|
+
#: (Prism::InstanceVariableOrWriteNode node) -> void
|
291
273
|
def on_instance_variable_or_write_node_enter(node)
|
292
274
|
collect_instance_variable_references(node.name.to_s, node.name_loc, true)
|
293
275
|
end
|
294
276
|
|
295
|
-
|
277
|
+
#: (Prism::InstanceVariableTargetNode node) -> void
|
296
278
|
def on_instance_variable_target_node_enter(node)
|
297
279
|
collect_instance_variable_references(node.name.to_s, node.location, true)
|
298
280
|
end
|
299
281
|
|
300
|
-
|
282
|
+
#: (Prism::CallNode node) -> void
|
301
283
|
def on_call_node_enter(node)
|
302
284
|
if @target.is_a?(MethodTarget) && (name = node.name.to_s) == @target.method_name
|
303
|
-
@references << Reference.new(
|
285
|
+
@references << Reference.new(
|
286
|
+
name,
|
287
|
+
node.message_loc, #: as !nil
|
288
|
+
declaration: false,
|
289
|
+
)
|
304
290
|
end
|
305
291
|
end
|
306
292
|
|
307
293
|
private
|
308
294
|
|
309
|
-
|
295
|
+
#: (String name, Prism::Location location) -> void
|
310
296
|
def collect_constant_references(name, location)
|
311
297
|
return unless @target.is_a?(ConstTarget)
|
312
298
|
|
@@ -335,7 +321,7 @@ module RubyIndexer
|
|
335
321
|
@references << Reference.new(name, location, declaration: declaration)
|
336
322
|
end
|
337
323
|
|
338
|
-
|
324
|
+
#: (String name, Prism::Location location, bool declaration) -> void
|
339
325
|
def collect_instance_variable_references(name, location, declaration)
|
340
326
|
return unless @target.is_a?(InstanceVariableTarget) && name == @target.name
|
341
327
|
|
@@ -1,35 +1,33 @@
|
|
1
1
|
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require "uri"
|
5
|
+
|
4
6
|
module URI
|
5
7
|
class Generic
|
6
|
-
extend T::Sig
|
7
|
-
|
8
8
|
# Avoid a deprecation warning with Ruby 3.4 where the default parser was changed to RFC3986.
|
9
9
|
# This condition must remain even after support for 3.4 has been dropped for users that have
|
10
10
|
# `uri` in their lockfile, decoupling it from the ruby version.
|
11
|
-
PARSER = T.let(const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER, RFC2396_Parser)
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
# NOTE: We also define this in the shim
|
13
|
+
PARSER = const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
path: String,
|
19
|
-
fragment: T.nilable(String),
|
20
|
-
scheme: String,
|
21
|
-
load_path_entry: T.nilable(String),
|
22
|
-
).returns(URI::Generic)
|
23
|
-
end
|
15
|
+
class << self
|
16
|
+
#: (path: String, ?fragment: String?, ?scheme: String, ?load_path_entry: String?) -> URI::Generic
|
24
17
|
def from_path(path:, fragment: nil, scheme: "file", load_path_entry: nil)
|
18
|
+
# This unsafe regex is the same one used in the URI::RFC2396_REGEXP class with the exception of the fact that we
|
19
|
+
# do not include colon as a safe character. VS Code URIs always escape colons and we need to ensure we do the
|
20
|
+
# same to avoid inconsistencies in our URIs, which are used to identify resources
|
21
|
+
unsafe_regex = %r{[^\-_.!~*'()a-zA-Z\d;/?@&=+$,\[\]]}
|
22
|
+
|
25
23
|
# On Windows, if the path begins with the disk name, we need to add a leading slash to make it a valid URI
|
26
24
|
escaped_path = if /^[A-Z]:/i.match?(path)
|
27
|
-
PARSER.escape("/#{path}")
|
25
|
+
PARSER.escape("/#{path}", unsafe_regex)
|
28
26
|
elsif path.start_with?("//?/")
|
29
27
|
# Some paths on Windows start with "//?/". This is a special prefix that allows for long file paths
|
30
|
-
PARSER.escape(path.delete_prefix("//?"))
|
28
|
+
PARSER.escape(path.delete_prefix("//?"), unsafe_regex)
|
31
29
|
else
|
32
|
-
PARSER.escape(path)
|
30
|
+
PARSER.escape(path, unsafe_regex)
|
33
31
|
end
|
34
32
|
|
35
33
|
uri = build(scheme: scheme, path: escaped_path, fragment: fragment)
|
@@ -42,10 +40,10 @@ module URI
|
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
45
|
-
|
43
|
+
#: String?
|
46
44
|
attr_accessor :require_path
|
47
45
|
|
48
|
-
|
46
|
+
#: (String load_path_entry) -> void
|
49
47
|
def add_require_path_from_load_entry(load_path_entry)
|
50
48
|
path = to_standardized_path
|
51
49
|
return unless path
|
@@ -53,7 +51,7 @@ module URI
|
|
53
51
|
self.require_path = path.delete_prefix("#{load_path_entry}/").delete_suffix(".rb")
|
54
52
|
end
|
55
53
|
|
56
|
-
|
54
|
+
#: -> String?
|
57
55
|
def to_standardized_path
|
58
56
|
parsed_path = path
|
59
57
|
return unless parsed_path
|
@@ -5,30 +5,26 @@ module RubyIndexer
|
|
5
5
|
# Represents the visibility scope in a Ruby namespace. This keeps track of whether methods are in a public, private or
|
6
6
|
# protected section, and whether they are module functions.
|
7
7
|
class VisibilityScope
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
class << self
|
11
|
-
|
12
|
-
|
13
|
-
sig { returns(T.attached_class) }
|
9
|
+
#: -> instance
|
14
10
|
def module_function_scope
|
15
|
-
new(module_func: true, visibility:
|
11
|
+
new(module_func: true, visibility: :private)
|
16
12
|
end
|
17
13
|
|
18
|
-
|
14
|
+
#: -> instance
|
19
15
|
def public_scope
|
20
16
|
new
|
21
17
|
end
|
22
18
|
end
|
23
19
|
|
24
|
-
|
20
|
+
#: Symbol
|
25
21
|
attr_reader :visibility
|
26
22
|
|
27
|
-
|
23
|
+
#: bool
|
28
24
|
attr_reader :module_func
|
29
25
|
|
30
|
-
|
31
|
-
def initialize(visibility:
|
26
|
+
#: (?visibility: Symbol, ?module_func: bool) -> void
|
27
|
+
def initialize(visibility: :public, module_func: false)
|
32
28
|
@visibility = visibility
|
33
29
|
@module_func = module_func
|
34
30
|
end
|
@@ -14,8 +14,8 @@ module RubyIndexer
|
|
14
14
|
|
15
15
|
assert_entry("@@bar", Entry::ClassVariable, "/fake/path/foo.rb:1-2:1-7")
|
16
16
|
|
17
|
-
entry =
|
18
|
-
owner =
|
17
|
+
entry = @index["@@bar"]&.first #: as Entry::ClassVariable
|
18
|
+
owner = entry.owner #: as !nil
|
19
19
|
assert_instance_of(Entry::Class, owner)
|
20
20
|
assert_equal("Foo", owner.name)
|
21
21
|
end
|
@@ -50,13 +50,13 @@ module RubyIndexer
|
|
50
50
|
assert_entry("@@foo", Entry::ClassVariable, "/fake/path/foo.rb:1-2:1-7")
|
51
51
|
assert_entry("@@bar", Entry::ClassVariable, "/fake/path/foo.rb:1-9:1-14")
|
52
52
|
|
53
|
-
entry =
|
54
|
-
owner =
|
53
|
+
entry = @index["@@foo"]&.first #: as Entry::ClassVariable
|
54
|
+
owner = entry.owner #: as !nil
|
55
55
|
assert_instance_of(Entry::Class, owner)
|
56
56
|
assert_equal("Foo", owner.name)
|
57
57
|
|
58
|
-
entry =
|
59
|
-
owner =
|
58
|
+
entry = @index["@@bar"]&.first #: as Entry::ClassVariable
|
59
|
+
owner = entry.owner #: as !nil
|
60
60
|
assert_instance_of(Entry::Class, owner)
|
61
61
|
assert_equal("Foo", owner.name)
|
62
62
|
end
|
@@ -83,10 +83,10 @@ module RubyIndexer
|
|
83
83
|
|
84
84
|
def test_top_level_class_variable
|
85
85
|
index(<<~RUBY)
|
86
|
-
|
86
|
+
@@foo = 123
|
87
87
|
RUBY
|
88
88
|
|
89
|
-
entry =
|
89
|
+
entry = @index["@@foo"]&.first #: as Entry::ClassVariable
|
90
90
|
assert_nil(entry.owner)
|
91
91
|
end
|
92
92
|
|
@@ -99,8 +99,8 @@ module RubyIndexer
|
|
99
99
|
end
|
100
100
|
RUBY
|
101
101
|
|
102
|
-
entry =
|
103
|
-
owner =
|
102
|
+
entry = @index["@@bar"]&.first #: as Entry::ClassVariable
|
103
|
+
owner = entry.owner #: as !nil
|
104
104
|
assert_instance_of(Entry::Class, owner)
|
105
105
|
assert_equal("Foo", owner.name)
|
106
106
|
end
|
@@ -114,8 +114,8 @@ module RubyIndexer
|
|
114
114
|
end
|
115
115
|
RUBY
|
116
116
|
|
117
|
-
entry =
|
118
|
-
owner =
|
117
|
+
entry = @index["@@bar"]&.first #: as Entry::ClassVariable
|
118
|
+
owner = entry.owner #: as !nil
|
119
119
|
assert_instance_of(Entry::Class, owner)
|
120
120
|
assert_equal("Foo", owner.name)
|
121
121
|
end
|
@@ -131,8 +131,8 @@ module RubyIndexer
|
|
131
131
|
end
|
132
132
|
RUBY
|
133
133
|
|
134
|
-
entry =
|
135
|
-
owner =
|
134
|
+
entry = @index["@@bar"]&.first #: as Entry::ClassVariable
|
135
|
+
owner = entry.owner #: as !nil
|
136
136
|
assert_instance_of(Entry::Class, owner)
|
137
137
|
assert_equal("Foo", owner.name)
|
138
138
|
end
|