ruby-lsp 0.23.11 → 0.23.12
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 +12 -11
- data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +3 -5
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +52 -77
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +61 -144
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +8 -6
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +73 -182
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +48 -181
- data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +12 -14
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +21 -44
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +40 -58
- data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +9 -16
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +5 -9
- data/lib/ruby_indexer/test/configuration_test.rb +32 -2
- data/lib/ruby_indexer/test/method_test.rb +2 -2
- data/lib/ruby_lsp/addon.rb +32 -67
- data/lib/ruby_lsp/base_server.rb +10 -10
- data/lib/ruby_lsp/client_capabilities.rb +4 -6
- data/lib/ruby_lsp/document.rb +21 -32
- data/lib/ruby_lsp/erb_document.rb +17 -27
- data/lib/ruby_lsp/global_state.rb +30 -32
- data/lib/ruby_lsp/internal.rb +2 -0
- data/lib/ruby_lsp/listeners/code_lens.rb +21 -39
- data/lib/ruby_lsp/listeners/completion.rb +34 -53
- data/lib/ruby_lsp/listeners/definition.rb +35 -49
- data/lib/ruby_lsp/listeners/document_highlight.rb +60 -69
- data/lib/ruby_lsp/listeners/document_link.rb +9 -19
- data/lib/ruby_lsp/listeners/document_symbol.rb +34 -48
- data/lib/ruby_lsp/listeners/folding_ranges.rb +31 -38
- data/lib/ruby_lsp/listeners/hover.rb +37 -47
- data/lib/ruby_lsp/listeners/inlay_hints.rb +3 -10
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +29 -35
- data/lib/ruby_lsp/listeners/signature_help.rb +4 -23
- data/lib/ruby_lsp/listeners/spec_style.rb +199 -0
- data/lib/ruby_lsp/listeners/test_style.rb +136 -30
- data/lib/ruby_lsp/node_context.rb +8 -35
- data/lib/ruby_lsp/rbs_document.rb +7 -5
- data/lib/ruby_lsp/requests/code_action_resolve.rb +10 -10
- data/lib/ruby_lsp/requests/code_actions.rb +5 -14
- data/lib/ruby_lsp/requests/code_lens.rb +4 -13
- data/lib/ruby_lsp/requests/completion.rb +4 -15
- data/lib/ruby_lsp/requests/completion_resolve.rb +4 -4
- data/lib/ruby_lsp/requests/definition.rb +4 -12
- data/lib/ruby_lsp/requests/diagnostics.rb +6 -9
- data/lib/ruby_lsp/requests/discover_tests.rb +15 -3
- data/lib/ruby_lsp/requests/document_highlight.rb +3 -11
- data/lib/ruby_lsp/requests/document_link.rb +4 -13
- data/lib/ruby_lsp/requests/document_symbol.rb +4 -7
- data/lib/ruby_lsp/requests/folding_ranges.rb +4 -7
- data/lib/ruby_lsp/requests/formatting.rb +4 -7
- data/lib/ruby_lsp/requests/go_to_relevant_file.rb +87 -0
- data/lib/ruby_lsp/requests/hover.rb +6 -16
- data/lib/ruby_lsp/requests/inlay_hints.rb +4 -13
- data/lib/ruby_lsp/requests/on_type_formatting.rb +17 -24
- data/lib/ruby_lsp/requests/prepare_rename.rb +3 -8
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +4 -13
- data/lib/ruby_lsp/requests/range_formatting.rb +3 -4
- data/lib/ruby_lsp/requests/references.rb +5 -35
- data/lib/ruby_lsp/requests/rename.rb +9 -35
- data/lib/ruby_lsp/requests/request.rb +5 -17
- data/lib/ruby_lsp/requests/selection_ranges.rb +3 -3
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +6 -23
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +4 -5
- data/lib/ruby_lsp/requests/signature_help.rb +6 -24
- data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
- data/lib/ruby_lsp/requests/support/common.rb +12 -49
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +12 -14
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +7 -10
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +9 -15
- data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
- data/lib/ruby_lsp/requests/support/sorbet.rb +1 -7
- data/lib/ruby_lsp/requests/support/source_uri.rb +5 -16
- data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +7 -10
- data/lib/ruby_lsp/requests/support/test_item.rb +14 -13
- data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +4 -5
- data/lib/ruby_lsp/requests/workspace_symbol.rb +3 -3
- data/lib/ruby_lsp/response_builders/collection_response_builder.rb +4 -4
- data/lib/ruby_lsp/response_builders/document_symbol.rb +8 -11
- data/lib/ruby_lsp/response_builders/hover.rb +5 -5
- data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +18 -40
- data/lib/ruby_lsp/response_builders/signature_help.rb +4 -5
- data/lib/ruby_lsp/response_builders/test_collection.rb +5 -9
- data/lib/ruby_lsp/ruby_document.rb +15 -40
- data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +106 -0
- data/lib/ruby_lsp/scope.rb +6 -10
- data/lib/ruby_lsp/server.rb +125 -74
- data/lib/ruby_lsp/setup_bundler.rb +22 -15
- data/lib/ruby_lsp/store.rb +12 -28
- data/lib/ruby_lsp/test_helper.rb +3 -12
- data/lib/ruby_lsp/test_reporter.rb +71 -0
- data/lib/ruby_lsp/test_unit_test_runner.rb +96 -0
- data/lib/ruby_lsp/type_inferrer.rb +9 -13
- data/lib/ruby_lsp/utils.rb +27 -65
- metadata +8 -3
@@ -3,16 +3,14 @@
|
|
3
3
|
|
4
4
|
module RubyIndexer
|
5
5
|
class RBSIndexer
|
6
|
-
extend T::Sig
|
7
|
-
|
8
6
|
HAS_UNTYPED_FUNCTION = T.let(!!defined?(RBS::Types::UntypedFunction), T::Boolean)
|
9
7
|
|
10
|
-
|
8
|
+
#: (Index index) -> void
|
11
9
|
def initialize(index)
|
12
10
|
@index = index
|
13
11
|
end
|
14
12
|
|
15
|
-
|
13
|
+
#: -> void
|
16
14
|
def index_ruby_core
|
17
15
|
loader = RBS::EnvironmentLoader.new
|
18
16
|
RBS::Environment.from_loader(loader).resolve_type_names
|
@@ -22,12 +20,7 @@ module RubyIndexer
|
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
25
|
-
|
26
|
-
params(
|
27
|
-
pathname: Pathname,
|
28
|
-
declarations: T::Array[RBS::AST::Declarations::Base],
|
29
|
-
).void
|
30
|
-
end
|
23
|
+
#: (Pathname pathname, Array[RBS::AST::Declarations::Base] declarations) -> void
|
31
24
|
def process_signature(pathname, declarations)
|
32
25
|
declarations.each do |declaration|
|
33
26
|
process_declaration(declaration, pathname)
|
@@ -36,7 +29,7 @@ module RubyIndexer
|
|
36
29
|
|
37
30
|
private
|
38
31
|
|
39
|
-
|
32
|
+
#: (RBS::AST::Declarations::Base declaration, Pathname pathname) -> void
|
40
33
|
def process_declaration(declaration, pathname)
|
41
34
|
case declaration
|
42
35
|
when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module
|
@@ -51,9 +44,7 @@ module RubyIndexer
|
|
51
44
|
end
|
52
45
|
end
|
53
46
|
|
54
|
-
|
55
|
-
params(declaration: T.any(RBS::AST::Declarations::Class, RBS::AST::Declarations::Module), pathname: Pathname).void
|
56
|
-
end
|
47
|
+
#: ((RBS::AST::Declarations::Class | RBS::AST::Declarations::Module) declaration, Pathname pathname) -> void
|
57
48
|
def handle_class_or_module_declaration(declaration, pathname)
|
58
49
|
nesting = [declaration.name.name.to_s]
|
59
50
|
uri = URI::Generic.from_path(path: pathname.to_s)
|
@@ -83,7 +74,7 @@ module RubyIndexer
|
|
83
74
|
end
|
84
75
|
end
|
85
76
|
|
86
|
-
|
77
|
+
#: (RBS::Location rbs_location) -> RubyIndexer::Location
|
87
78
|
def to_ruby_indexer_location(rbs_location)
|
88
79
|
RubyIndexer::Location.new(
|
89
80
|
rbs_location.start_line,
|
@@ -93,12 +84,7 @@ module RubyIndexer
|
|
93
84
|
)
|
94
85
|
end
|
95
86
|
|
96
|
-
|
97
|
-
params(
|
98
|
-
declaration: T.any(RBS::AST::Declarations::Class, RBS::AST::Declarations::Module),
|
99
|
-
entry: Entry::Namespace,
|
100
|
-
).void
|
101
|
-
end
|
87
|
+
#: ((RBS::AST::Declarations::Class | RBS::AST::Declarations::Module) declaration, Entry::Namespace entry) -> void
|
102
88
|
def add_declaration_mixins_to_entry(declaration, entry)
|
103
89
|
declaration.each_mixin do |mixin|
|
104
90
|
name = mixin.name.name.to_s
|
@@ -114,7 +100,7 @@ module RubyIndexer
|
|
114
100
|
end
|
115
101
|
end
|
116
102
|
|
117
|
-
|
103
|
+
#: (RBS::AST::Members::MethodDefinition member, Entry::Namespace owner) -> void
|
118
104
|
def handle_method(member, owner)
|
119
105
|
name = member.name.name
|
120
106
|
uri = URI::Generic.from_path(path: member.location.buffer.name)
|
@@ -144,7 +130,7 @@ module RubyIndexer
|
|
144
130
|
))
|
145
131
|
end
|
146
132
|
|
147
|
-
|
133
|
+
#: (RBS::AST::Members::MethodDefinition member) -> Array[Entry::Signature]
|
148
134
|
def signatures(member)
|
149
135
|
member.overloads.map do |overload|
|
150
136
|
parameters = process_overload(overload)
|
@@ -152,7 +138,7 @@ module RubyIndexer
|
|
152
138
|
end
|
153
139
|
end
|
154
140
|
|
155
|
-
|
141
|
+
#: (RBS::AST::Members::MethodDefinition::Overload overload) -> Array[Entry::Parameter]
|
156
142
|
def process_overload(overload)
|
157
143
|
function = overload.method_type.type
|
158
144
|
|
@@ -173,7 +159,7 @@ module RubyIndexer
|
|
173
159
|
end
|
174
160
|
end
|
175
161
|
|
176
|
-
|
162
|
+
#: (RBS::Types::Function function) -> Array[Entry::Parameter]
|
177
163
|
def parse_arguments(function)
|
178
164
|
parameters = []
|
179
165
|
parameters.concat(process_required_and_optional_positionals(function))
|
@@ -185,7 +171,7 @@ module RubyIndexer
|
|
185
171
|
parameters
|
186
172
|
end
|
187
173
|
|
188
|
-
|
174
|
+
#: (RBS::Types::Function function) -> Array[Entry::RequiredParameter]
|
189
175
|
def process_required_and_optional_positionals(function)
|
190
176
|
argument_offset = 0
|
191
177
|
|
@@ -209,14 +195,14 @@ module RubyIndexer
|
|
209
195
|
required + optional
|
210
196
|
end
|
211
197
|
|
212
|
-
|
198
|
+
#: (RBS::Types::Function function) -> Array[Entry::OptionalParameter]
|
213
199
|
def process_trailing_positionals(function)
|
214
200
|
function.trailing_positionals.map do |param|
|
215
201
|
Entry::OptionalParameter.new(name: param.name)
|
216
202
|
end
|
217
203
|
end
|
218
204
|
|
219
|
-
|
205
|
+
#: (RBS::Types::Function function) -> Entry::RestParameter
|
220
206
|
def process_rest_positionals(function)
|
221
207
|
rest = function.rest_positionals
|
222
208
|
|
@@ -225,21 +211,21 @@ module RubyIndexer
|
|
225
211
|
Entry::RestParameter.new(name: rest_name)
|
226
212
|
end
|
227
213
|
|
228
|
-
|
214
|
+
#: (RBS::Types::Function function) -> Array[Entry::KeywordParameter]
|
229
215
|
def process_required_keywords(function)
|
230
216
|
function.required_keywords.map do |name, _param|
|
231
217
|
Entry::KeywordParameter.new(name: name)
|
232
218
|
end
|
233
219
|
end
|
234
220
|
|
235
|
-
|
221
|
+
#: (RBS::Types::Function function) -> Array[Entry::OptionalKeywordParameter]
|
236
222
|
def process_optional_keywords(function)
|
237
223
|
function.optional_keywords.map do |name, _param|
|
238
224
|
Entry::OptionalKeywordParameter.new(name: name)
|
239
225
|
end
|
240
226
|
end
|
241
227
|
|
242
|
-
|
228
|
+
#: (RBS::Types::Function function) -> Entry::KeywordRestParameter
|
243
229
|
def process_rest_keywords(function)
|
244
230
|
param = function.rest_keywords
|
245
231
|
|
@@ -262,7 +248,7 @@ module RubyIndexer
|
|
262
248
|
# Complex::I = ... # Complex::I is a top-level constant
|
263
249
|
#
|
264
250
|
# And we need to handle their nesting differently.
|
265
|
-
|
251
|
+
#: (RBS::AST::Declarations::Constant declaration, Array[String] nesting, URI::Generic uri) -> void
|
266
252
|
def handle_constant(declaration, nesting, uri)
|
267
253
|
fully_qualified_name = [*nesting, declaration.name.name.to_s].join("::")
|
268
254
|
@index.add(Entry::Constant.new(
|
@@ -273,7 +259,7 @@ module RubyIndexer
|
|
273
259
|
))
|
274
260
|
end
|
275
261
|
|
276
|
-
|
262
|
+
#: (RBS::AST::Declarations::Global declaration, Pathname pathname) -> void
|
277
263
|
def handle_global_variable(declaration, pathname)
|
278
264
|
name = declaration.name.to_s
|
279
265
|
uri = URI::Generic.from_path(path: pathname.to_s)
|
@@ -288,7 +274,7 @@ module RubyIndexer
|
|
288
274
|
))
|
289
275
|
end
|
290
276
|
|
291
|
-
|
277
|
+
#: (RBS::AST::Members::Alias member, Entry::Namespace owner_entry) -> void
|
292
278
|
def handle_signature_alias(member, owner_entry)
|
293
279
|
uri = URI::Generic.from_path(path: member.location.buffer.name)
|
294
280
|
comments = comments_to_string(member)
|
@@ -305,16 +291,7 @@ module RubyIndexer
|
|
305
291
|
@index.add(entry)
|
306
292
|
end
|
307
293
|
|
308
|
-
|
309
|
-
params(declaration: T.any(
|
310
|
-
RBS::AST::Declarations::Class,
|
311
|
-
RBS::AST::Declarations::Module,
|
312
|
-
RBS::AST::Declarations::Constant,
|
313
|
-
RBS::AST::Declarations::Global,
|
314
|
-
RBS::AST::Members::MethodDefinition,
|
315
|
-
RBS::AST::Members::Alias,
|
316
|
-
)).returns(T.nilable(String))
|
317
|
-
end
|
294
|
+
#: ((RBS::AST::Declarations::Class | RBS::AST::Declarations::Module | RBS::AST::Declarations::Constant | RBS::AST::Declarations::Global | RBS::AST::Members::MethodDefinition | RBS::AST::Members::Alias) declaration) -> String?
|
318
295
|
def comments_to_string(declaration)
|
319
296
|
declaration.comment&.string
|
320
297
|
end
|
@@ -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,15 +60,7 @@ 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
|
@@ -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,44 +242,44 @@ 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
285
|
@references << Reference.new(name, T.must(node.message_loc), declaration: false)
|
@@ -306,7 +288,7 @@ module RubyIndexer
|
|
306
288
|
|
307
289
|
private
|
308
290
|
|
309
|
-
|
291
|
+
#: (String name, Prism::Location location) -> void
|
310
292
|
def collect_constant_references(name, location)
|
311
293
|
return unless @target.is_a?(ConstTarget)
|
312
294
|
|
@@ -335,7 +317,7 @@ module RubyIndexer
|
|
335
317
|
@references << Reference.new(name, location, declaration: declaration)
|
336
318
|
end
|
337
319
|
|
338
|
-
|
320
|
+
#: (String name, Prism::Location location, bool declaration) -> void
|
339
321
|
def collect_instance_variable_references(name, location, declaration)
|
340
322
|
return unless @target.is_a?(InstanceVariableTarget) && name == @target.name
|
341
323
|
|
@@ -1,26 +1,19 @@
|
|
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)
|
25
18
|
# On Windows, if the path begins with the disk name, we need to add a leading slash to make it a valid URI
|
26
19
|
escaped_path = if /^[A-Z]:/i.match?(path)
|
@@ -42,10 +35,10 @@ module URI
|
|
42
35
|
end
|
43
36
|
end
|
44
37
|
|
45
|
-
|
38
|
+
#: String?
|
46
39
|
attr_accessor :require_path
|
47
40
|
|
48
|
-
|
41
|
+
#: (String load_path_entry) -> void
|
49
42
|
def add_require_path_from_load_entry(load_path_entry)
|
50
43
|
path = to_standardized_path
|
51
44
|
return unless path
|
@@ -53,7 +46,7 @@ module URI
|
|
53
46
|
self.require_path = path.delete_prefix("#{load_path_entry}/").delete_suffix(".rb")
|
54
47
|
end
|
55
48
|
|
56
|
-
|
49
|
+
#: -> String?
|
57
50
|
def to_standardized_path
|
58
51
|
parsed_path = path
|
59
52
|
return unless parsed_path
|
@@ -5,29 +5,25 @@ 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
11
|
new(module_func: true, visibility: Entry::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
|
+
#: Entry::Visibility
|
25
21
|
attr_reader :visibility
|
26
22
|
|
27
|
-
|
23
|
+
#: bool
|
28
24
|
attr_reader :module_func
|
29
25
|
|
30
|
-
|
26
|
+
#: (?visibility: Entry::Visibility, ?module_func: bool) -> void
|
31
27
|
def initialize(visibility: Entry::Visibility::PUBLIC, module_func: false)
|
32
28
|
@visibility = visibility
|
33
29
|
@module_func = module_func
|
@@ -12,7 +12,7 @@ module RubyIndexer
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_load_configuration_executes_configure_block
|
15
|
-
@config.apply_config({ "excluded_patterns" => ["**/fixtures
|
15
|
+
@config.apply_config({ "excluded_patterns" => ["**/fixtures/**/*"] })
|
16
16
|
uris = @config.indexable_uris
|
17
17
|
|
18
18
|
bundle_path = Bundler.bundle_path.join("gems")
|
@@ -39,7 +39,11 @@ module RubyIndexer
|
|
39
39
|
next if lazy_spec.name == "ruby-lsp"
|
40
40
|
|
41
41
|
spec = Gem::Specification.find_by_name(lazy_spec.name)
|
42
|
-
|
42
|
+
|
43
|
+
test_uris = uris.select do |uri|
|
44
|
+
File.fnmatch?(File.join(spec.full_gem_path, "test/**/*"), uri.full_path, File::Constants::FNM_PATHNAME)
|
45
|
+
end
|
46
|
+
assert_empty(test_uris)
|
43
47
|
rescue Gem::MissingSpecError
|
44
48
|
# Transitive dependencies might be missing when running tests on Windows
|
45
49
|
end
|
@@ -235,5 +239,31 @@ module RubyIndexer
|
|
235
239
|
end
|
236
240
|
end
|
237
241
|
end
|
242
|
+
|
243
|
+
def test_indexables_include_non_test_files_in_test_directories
|
244
|
+
# In order to linearize test parent classes and accurately detect the framework being used, then intermediate
|
245
|
+
# parent classes _must_ also be indexed. Otherwise, we have no way of linearizing the rest of the ancestors to
|
246
|
+
# determine what the test class ultimately inherits from.
|
247
|
+
#
|
248
|
+
# Therefore, we need to ensure that test files are excluded, but non test files inside test directories have to be
|
249
|
+
# indexed
|
250
|
+
FileUtils.touch("test/test_case.rb")
|
251
|
+
|
252
|
+
uris = @config.indexable_uris
|
253
|
+
project_paths = uris.filter_map do |uri|
|
254
|
+
path = uri.full_path
|
255
|
+
next if path.start_with?(Bundler.bundle_path.to_s) || path.start_with?(RbConfig::CONFIG["rubylibdir"])
|
256
|
+
|
257
|
+
Pathname.new(path).relative_path_from(Dir.pwd).to_s
|
258
|
+
end
|
259
|
+
|
260
|
+
begin
|
261
|
+
assert_includes(project_paths, "test/requests/support/expectations_test_runner.rb")
|
262
|
+
assert_includes(project_paths, "test/test_helper.rb")
|
263
|
+
assert_includes(project_paths, "test/test_case.rb")
|
264
|
+
ensure
|
265
|
+
FileUtils.rm("test/test_case.rb")
|
266
|
+
end
|
267
|
+
end
|
238
268
|
end
|
239
269
|
end
|
@@ -926,14 +926,14 @@ module RubyIndexer
|
|
926
926
|
|
927
927
|
private
|
928
928
|
|
929
|
-
|
929
|
+
#: (Entry::Method entry, String call_string) -> void
|
930
930
|
def assert_signature_matches(entry, call_string)
|
931
931
|
sig = T.must(entry.signatures.first)
|
932
932
|
arguments = parse_prism_args(call_string)
|
933
933
|
assert(sig.matches?(arguments), "Expected #{call_string} to match #{entry.name}#{entry.decorated_parameters}")
|
934
934
|
end
|
935
935
|
|
936
|
-
|
936
|
+
#: (Entry::Method entry, String call_string) -> void
|
937
937
|
def refute_signature_matches(entry, call_string)
|
938
938
|
sig = T.must(entry.signatures.first)
|
939
939
|
arguments = parse_prism_args(call_string)
|