ruby-lsp 0.23.14 → 0.23.15
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/VERSION +1 -1
- data/exe/ruby-lsp-launcher +9 -1
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +1 -1
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +6 -3
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +4 -2
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +59 -29
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +5 -4
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +5 -1
- 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 +6 -4
- 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 +139 -135
- data/lib/ruby_indexer/test/instance_variables_test.rb +37 -37
- data/lib/ruby_indexer/test/method_test.rb +118 -118
- data/lib/ruby_indexer/test/prefix_tree_test.rb +13 -13
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +64 -70
- data/lib/ruby_indexer/test/test_case.rb +2 -2
- data/lib/ruby_lsp/erb_document.rb +12 -4
- data/lib/ruby_lsp/global_state.rb +1 -1
- data/lib/ruby_lsp/listeners/code_lens.rb +3 -3
- data/lib/ruby_lsp/listeners/completion.rb +24 -11
- data/lib/ruby_lsp/listeners/definition.rb +1 -1
- data/lib/ruby_lsp/listeners/document_link.rb +3 -1
- data/lib/ruby_lsp/listeners/document_symbol.rb +3 -3
- data/lib/ruby_lsp/listeners/folding_ranges.rb +8 -4
- data/lib/ruby_lsp/listeners/hover.rb +2 -2
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +12 -5
- data/lib/ruby_lsp/listeners/signature_help.rb +5 -1
- data/lib/ruby_lsp/listeners/spec_style.rb +1 -1
- data/lib/ruby_lsp/listeners/test_style.rb +3 -3
- data/lib/ruby_lsp/requests/code_action_resolve.rb +4 -3
- data/lib/ruby_lsp/requests/completion_resolve.rb +1 -1
- data/lib/ruby_lsp/requests/hover.rb +2 -2
- data/lib/ruby_lsp/requests/on_type_formatting.rb +4 -2
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +1 -2
- data/lib/ruby_lsp/requests/references.rb +2 -1
- data/lib/ruby_lsp/requests/rename.rb +8 -5
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +4 -4
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +1 -1
- data/lib/ruby_lsp/requests/support/common.rb +3 -1
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +2 -2
- data/lib/ruby_lsp/requests/support/source_uri.rb +1 -1
- data/lib/ruby_lsp/response_builders/document_symbol.rb +3 -2
- data/lib/ruby_lsp/response_builders/hover.rb +1 -1
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +1 -1
- data/lib/ruby_lsp/scripts/compose_bundle.rb +6 -4
- data/lib/ruby_lsp/server.rb +12 -4
- data/lib/ruby_lsp/setup_bundler.rb +5 -2
- data/lib/ruby_lsp/static_docs.rb +8 -1
- data/lib/ruby_lsp/store.rb +3 -2
- data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +152 -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 +4 -1
- metadata +6 -6
- data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +0 -109
- data/lib/ruby_lsp/test_reporter.rb +0 -207
- data/lib/ruby_lsp/test_unit_test_runner.rb +0 -98
@@ -6,16 +6,16 @@ require_relative "test_case"
|
|
6
6
|
module RubyIndexer
|
7
7
|
class RBSIndexerTest < TestCase
|
8
8
|
def test_index_core_classes
|
9
|
-
entries = @index["Array"]
|
9
|
+
entries = @index["Array"] #: as !nil
|
10
10
|
refute_nil(entries)
|
11
11
|
# Array is a class but also an instance method on Kernel
|
12
12
|
assert_equal(2, entries.length)
|
13
|
-
entry = entries.find { |entry| entry.is_a?(
|
13
|
+
entry = entries.find { |entry| entry.is_a?(Entry::Class) } #: as Entry::Class
|
14
14
|
assert_match(%r{/gems/rbs-.*/core/array.rbs}, entry.file_path)
|
15
15
|
assert_equal("array.rbs", entry.file_name)
|
16
16
|
assert_equal("Object", entry.parent_class)
|
17
17
|
assert_equal(1, entry.mixin_operations.length)
|
18
|
-
enumerable_include = entry.mixin_operations.first
|
18
|
+
enumerable_include = entry.mixin_operations.first #: as !nil
|
19
19
|
assert_equal("Enumerable", enumerable_include.module_name)
|
20
20
|
|
21
21
|
# Using fixed positions would be fragile, so let's just check some basics.
|
@@ -26,10 +26,10 @@ module RubyIndexer
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_index_core_modules
|
29
|
-
entries = @index["Kernel"]
|
29
|
+
entries = @index["Kernel"] #: as !nil
|
30
30
|
refute_nil(entries)
|
31
31
|
assert_equal(1, entries.length)
|
32
|
-
entry = entries.first
|
32
|
+
entry = entries.first #: as Entry::Module
|
33
33
|
assert_match(%r{/gems/rbs-.*/core/kernel.rbs}, entry.file_path)
|
34
34
|
assert_equal("kernel.rbs", entry.file_name)
|
35
35
|
|
@@ -41,30 +41,23 @@ module RubyIndexer
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_index_core_constants
|
44
|
-
entries = @index["RUBY_VERSION"]
|
44
|
+
entries = @index["RUBY_VERSION"] #: as !nil
|
45
45
|
refute_nil(entries)
|
46
46
|
assert_equal(1, entries.length)
|
47
47
|
|
48
|
-
|
49
|
-
entries = @index["Complex::I"]
|
48
|
+
entries = @index["Complex::I"] #: as !nil
|
50
49
|
refute_nil(entries)
|
51
50
|
assert_equal(1, entries.length)
|
52
51
|
|
53
|
-
|
54
|
-
# ```
|
55
|
-
# module Encoding
|
56
|
-
# US_ASCII = ...
|
57
|
-
# ...
|
58
|
-
# ````
|
59
|
-
entries = @index["Encoding::US_ASCII"]
|
52
|
+
entries = @index["Encoding::US_ASCII"] #: as !nil
|
60
53
|
refute_nil(entries)
|
61
54
|
assert_equal(1, entries.length)
|
62
55
|
end
|
63
56
|
|
64
57
|
def test_index_methods
|
65
|
-
entries = @index["initialize"]
|
58
|
+
entries = @index["initialize"] #: as Array[Entry::Method]
|
66
59
|
refute_nil(entries)
|
67
|
-
entry = entries.find { |entry| entry.owner
|
60
|
+
entry = entries.find { |entry| entry.owner&.name == "Array" } #: as Entry::Method
|
68
61
|
assert_match(%r{/gems/rbs-.*/core/array.rbs}, entry.file_path)
|
69
62
|
assert_equal("array.rbs", entry.file_name)
|
70
63
|
assert_equal(Entry::Visibility::PUBLIC, entry.visibility)
|
@@ -77,11 +70,11 @@ module RubyIndexer
|
|
77
70
|
end
|
78
71
|
|
79
72
|
def test_index_global_declaration
|
80
|
-
entries = @index["$DEBUG"]
|
73
|
+
entries = @index["$DEBUG"] #: as Array[Entry::GlobalVariable]
|
81
74
|
refute_nil(entries)
|
82
75
|
assert_equal(1, entries.length)
|
83
76
|
|
84
|
-
entry = entries.first
|
77
|
+
entry = entries.first #: as Entry::GlobalVariable
|
85
78
|
|
86
79
|
assert_instance_of(Entry::GlobalVariable, entry)
|
87
80
|
assert_equal("$DEBUG", entry.name)
|
@@ -91,10 +84,10 @@ module RubyIndexer
|
|
91
84
|
end
|
92
85
|
|
93
86
|
def test_attaches_correct_owner_to_singleton_methods
|
94
|
-
entries = @index["basename"]
|
87
|
+
entries = @index["basename"] #: as Array[Entry::Method]
|
95
88
|
refute_nil(entries)
|
96
89
|
|
97
|
-
owner = entries.first
|
90
|
+
owner = entries.first&.owner #: as Entry::SingletonClass
|
98
91
|
assert_instance_of(Entry::SingletonClass, owner)
|
99
92
|
assert_equal("File::<Class:File>", owner.name)
|
100
93
|
end
|
@@ -103,47 +96,47 @@ module RubyIndexer
|
|
103
96
|
# NOTE: RBS does not store the name location for classes, modules or methods. This behavior is not exactly what
|
104
97
|
# we would like, but for now we assign the same location to both
|
105
98
|
|
106
|
-
entries = @index["Array"]
|
99
|
+
entries = @index["Array"] #: as Array[Entry::Class]
|
107
100
|
refute_nil(entries)
|
108
|
-
entry = entries.find { |entry| entry.is_a?(Entry::Class) }
|
101
|
+
entry = entries.find { |entry| entry.is_a?(Entry::Class) } #: as Entry::Class
|
109
102
|
|
110
103
|
assert_same(entry.location, entry.name_location)
|
111
104
|
end
|
112
105
|
|
113
106
|
def test_rbs_method_with_required_positionals
|
114
|
-
entries = @index["crypt"]
|
107
|
+
entries = @index["crypt"] #: as Array[Entry::Method]
|
115
108
|
assert_equal(1, entries.length)
|
116
109
|
|
117
|
-
entry = entries.first
|
110
|
+
entry = entries.first #: as Entry::Method
|
118
111
|
signatures = entry.signatures
|
119
112
|
assert_equal(1, signatures.length)
|
120
113
|
|
121
|
-
first_signature = signatures.first
|
114
|
+
first_signature = signatures.first #: as Entry::Signature
|
122
115
|
|
123
116
|
# (::string salt_str) -> ::String
|
124
117
|
|
125
118
|
assert_equal(1, first_signature.parameters.length)
|
126
119
|
assert_kind_of(Entry::RequiredParameter, first_signature.parameters[0])
|
127
|
-
assert_equal(:salt_str, first_signature.parameters[0]
|
120
|
+
assert_equal(:salt_str, first_signature.parameters[0]&.name)
|
128
121
|
end
|
129
122
|
|
130
123
|
def test_rbs_method_with_unnamed_required_positionals
|
131
|
-
entries = @index["try_convert"]
|
132
|
-
entry = entries.find { |entry| entry.owner
|
124
|
+
entries = @index["try_convert"] #: as Array[Entry::Method]
|
125
|
+
entry = entries.find { |entry| entry.owner&.name == "Array::<Class:Array>" } #: as Entry::Method
|
133
126
|
|
134
|
-
parameters = entry.signatures[0]
|
127
|
+
parameters = entry.signatures[0]&.parameters #: as Array[Entry::Parameter]
|
135
128
|
|
136
129
|
assert_equal([:arg0], parameters.map(&:name))
|
137
130
|
assert_kind_of(Entry::RequiredParameter, parameters[0])
|
138
131
|
end
|
139
132
|
|
140
133
|
def test_rbs_method_with_optional_positionals
|
141
|
-
entries = @index["polar"]
|
142
|
-
entry = entries.find { |entry| entry.owner
|
134
|
+
entries = @index["polar"] #: as Array[Entry::Method]
|
135
|
+
entry = entries.find { |entry| entry.owner&.name == "Complex::<Class:Complex>" } #: as Entry::Method
|
143
136
|
|
144
137
|
# def self.polar: (Numeric, ?Numeric) -> Complex
|
145
138
|
|
146
|
-
parameters = entry.signatures[0]
|
139
|
+
parameters = entry.signatures[0]&.parameters #: as Array[Entry::Parameter]
|
147
140
|
|
148
141
|
assert_equal([:arg0, :arg1], parameters.map(&:name))
|
149
142
|
assert_kind_of(Entry::RequiredParameter, parameters[0])
|
@@ -151,27 +144,27 @@ module RubyIndexer
|
|
151
144
|
end
|
152
145
|
|
153
146
|
def test_rbs_method_with_optional_parameter
|
154
|
-
entries = @index["chomp"]
|
147
|
+
entries = @index["chomp"] #: as Array[Entry::Method]
|
155
148
|
assert_equal(1, entries.length)
|
156
149
|
|
157
|
-
entry = entries.first
|
150
|
+
entry = entries.first #: as Entry::Method
|
158
151
|
signatures = entry.signatures
|
159
152
|
assert_equal(1, signatures.length)
|
160
153
|
|
161
|
-
first_signature = signatures.first
|
154
|
+
first_signature = signatures.first #: as Entry::Signature
|
162
155
|
|
163
156
|
# (?::string? separator) -> ::String
|
164
157
|
|
165
158
|
assert_equal(1, first_signature.parameters.length)
|
166
159
|
assert_kind_of(Entry::OptionalParameter, first_signature.parameters[0])
|
167
|
-
assert_equal(:separator, first_signature.parameters[0]
|
160
|
+
assert_equal(:separator, first_signature.parameters[0]&.name)
|
168
161
|
end
|
169
162
|
|
170
163
|
def test_rbs_method_with_required_and_optional_parameters
|
171
|
-
entries = @index["gsub"]
|
164
|
+
entries = @index["gsub"] #: as Array[Entry::Method]
|
172
165
|
assert_equal(1, entries.length)
|
173
166
|
|
174
|
-
entry = entries.first
|
167
|
+
entry = entries.first #: as Entry::Method
|
175
168
|
|
176
169
|
signatures = entry.signatures
|
177
170
|
assert_equal(3, signatures.length)
|
@@ -180,37 +173,37 @@ module RubyIndexer
|
|
180
173
|
# | (::Regexp | ::string pattern) -> ::Enumerator[::String, ::String]
|
181
174
|
# | (::Regexp | ::string pattern) { (::String match) -> ::_ToS } -> ::String
|
182
175
|
|
183
|
-
parameters = signatures[0]
|
176
|
+
parameters = signatures[0]&.parameters #: as !nil
|
184
177
|
assert_equal([:pattern, :replacement], parameters.map(&:name))
|
185
178
|
assert_kind_of(Entry::RequiredParameter, parameters[0])
|
186
179
|
assert_kind_of(Entry::RequiredParameter, parameters[1])
|
187
180
|
|
188
|
-
parameters = signatures[1]
|
181
|
+
parameters = signatures[1]&.parameters #: as !nil
|
189
182
|
assert_equal([:pattern], parameters.map(&:name))
|
190
183
|
assert_kind_of(Entry::RequiredParameter, parameters[0])
|
191
184
|
|
192
|
-
parameters = signatures[2]
|
185
|
+
parameters = signatures[2]&.parameters #: as !nil
|
193
186
|
assert_equal([:pattern, :"<anonymous block>"], parameters.map(&:name))
|
194
187
|
assert_kind_of(Entry::RequiredParameter, parameters[0])
|
195
188
|
assert_kind_of(Entry::BlockParameter, parameters[1])
|
196
189
|
end
|
197
190
|
|
198
191
|
def test_rbs_anonymous_block_parameter
|
199
|
-
entries = @index["open"]
|
200
|
-
entry = entries.find { |entry| entry.owner
|
192
|
+
entries = @index["open"] #: as Array[Entry::Method]
|
193
|
+
entry = entries.find { |entry| entry.owner&.name == "File::<Class:File>" } #: as Entry::Method
|
201
194
|
|
202
195
|
assert_equal(2, entry.signatures.length)
|
203
196
|
|
204
197
|
# (::String name, ?::String mode, ?::Integer perm) -> ::IO?
|
205
198
|
# | [T] (::String name, ?::String mode, ?::Integer perm) { (::IO) -> T } -> T
|
206
199
|
|
207
|
-
parameters = entry.signatures[0]
|
200
|
+
parameters = entry.signatures[0]&.parameters #: as !nil
|
208
201
|
assert_equal([:file_name, :mode, :perm], parameters.map(&:name))
|
209
202
|
assert_kind_of(Entry::RequiredParameter, parameters[0])
|
210
203
|
assert_kind_of(Entry::OptionalParameter, parameters[1])
|
211
204
|
assert_kind_of(Entry::OptionalParameter, parameters[2])
|
212
205
|
|
213
|
-
parameters = entry.signatures[1]
|
206
|
+
parameters = entry.signatures[1]&.parameters #: as !nil
|
214
207
|
assert_equal([:file_name, :mode, :perm, :"<anonymous block>"], parameters.map(&:name))
|
215
208
|
assert_kind_of(Entry::RequiredParameter, parameters[0])
|
216
209
|
assert_kind_of(Entry::OptionalParameter, parameters[1])
|
@@ -219,10 +212,10 @@ module RubyIndexer
|
|
219
212
|
end
|
220
213
|
|
221
214
|
def test_rbs_method_with_rest_positionals
|
222
|
-
entries = @index["count"]
|
223
|
-
entry = entries.find { |entry| entry.owner
|
215
|
+
entries = @index["count"] #: as Array[Entry::Method]
|
216
|
+
entry = entries.find { |entry| entry.owner&.name == "String" } #: as Entry::Method
|
224
217
|
|
225
|
-
parameters = entry.signatures.first
|
218
|
+
parameters = entry.signatures.first&.parameters #: as !nil
|
226
219
|
assert_equal(1, entry.signatures.length)
|
227
220
|
|
228
221
|
# (::String::selector selector_0, *::String::selector more_selectors) -> ::Integer
|
@@ -233,8 +226,8 @@ module RubyIndexer
|
|
233
226
|
end
|
234
227
|
|
235
228
|
def test_rbs_method_with_trailing_positionals
|
236
|
-
entries = @index["select"]
|
237
|
-
entry = entries.find { |entry| entry.owner
|
229
|
+
entries = @index["select"] #: as Array[Entry::Method]
|
230
|
+
entry = entries.find { |entry| entry.owner&.name == "IO::<Class:IO>" } #: as !nil
|
238
231
|
|
239
232
|
signatures = entry.signatures
|
240
233
|
assert_equal(2, signatures.length)
|
@@ -242,13 +235,13 @@ module RubyIndexer
|
|
242
235
|
# def self.select: [X, Y, Z] (::Array[X & io]? read_array, ?::Array[Y & io]? write_array, ?::Array[Z & io]? error_array) -> [ Array[X], Array[Y], Array[Z] ] # rubocop:disable Layout/LineLength
|
243
236
|
# | [X, Y, Z] (::Array[X & io]? read_array, ?::Array[Y & io]? write_array, ?::Array[Z & io]? error_array, Time::_Timeout? timeout) -> [ Array[X], Array[Y], Array[Z] ]? # rubocop:disable Layout/LineLength
|
244
237
|
|
245
|
-
parameters = signatures[0]
|
238
|
+
parameters = signatures[0]&.parameters #: as !nil
|
246
239
|
assert_equal([:read_array, :write_array, :error_array], parameters.map(&:name))
|
247
240
|
assert_kind_of(Entry::RequiredParameter, parameters[0])
|
248
241
|
assert_kind_of(Entry::OptionalParameter, parameters[1])
|
249
242
|
assert_kind_of(Entry::OptionalParameter, parameters[2])
|
250
243
|
|
251
|
-
parameters = signatures[1]
|
244
|
+
parameters = signatures[1]&.parameters #: as !nil
|
252
245
|
assert_equal([:read_array, :write_array, :error_array, :timeout], parameters.map(&:name))
|
253
246
|
assert_kind_of(Entry::RequiredParameter, parameters[0])
|
254
247
|
assert_kind_of(Entry::OptionalParameter, parameters[1])
|
@@ -257,8 +250,8 @@ module RubyIndexer
|
|
257
250
|
end
|
258
251
|
|
259
252
|
def test_rbs_method_with_optional_keywords
|
260
|
-
entries = @index["step"]
|
261
|
-
entry = entries.find { |entry| entry.owner
|
253
|
+
entries = @index["step"] #: as Array[Entry::Method]
|
254
|
+
entry = entries.find { |entry| entry.owner&.name == "Numeric" } #: as !nil
|
262
255
|
|
263
256
|
signatures = entry.signatures
|
264
257
|
assert_equal(4, signatures.length)
|
@@ -268,24 +261,24 @@ module RubyIndexer
|
|
268
261
|
# | (?by: ::Numeric, ?to: ::Numeric) { (::Numeric) -> void } -> self
|
269
262
|
# | (?by: ::Numeric, ?to: ::Numeric) -> ::Enumerator[::Numeric, self]
|
270
263
|
|
271
|
-
parameters = signatures[0]
|
264
|
+
parameters = signatures[0]&.parameters #: as !nil
|
272
265
|
assert_equal([:limit, :step, :"<anonymous block>"], parameters.map(&:name))
|
273
266
|
assert_kind_of(Entry::OptionalParameter, parameters[0])
|
274
267
|
assert_kind_of(Entry::OptionalParameter, parameters[1])
|
275
268
|
assert_kind_of(Entry::BlockParameter, parameters[2])
|
276
269
|
|
277
|
-
parameters = signatures[1]
|
270
|
+
parameters = signatures[1]&.parameters #: as !nil
|
278
271
|
assert_equal([:limit, :step], parameters.map(&:name))
|
279
272
|
assert_kind_of(Entry::OptionalParameter, parameters[0])
|
280
273
|
assert_kind_of(Entry::OptionalParameter, parameters[1])
|
281
274
|
|
282
|
-
parameters = signatures[2]
|
275
|
+
parameters = signatures[2]&.parameters #: as !nil
|
283
276
|
assert_equal([:by, :to, :"<anonymous block>"], parameters.map(&:name))
|
284
277
|
assert_kind_of(Entry::OptionalKeywordParameter, parameters[0])
|
285
278
|
assert_kind_of(Entry::OptionalKeywordParameter, parameters[1])
|
286
279
|
assert_kind_of(Entry::BlockParameter, parameters[2])
|
287
280
|
|
288
|
-
parameters = signatures[3]
|
281
|
+
parameters = signatures[3]&.parameters #: as !nil
|
289
282
|
assert_equal([:by, :to], parameters.map(&:name))
|
290
283
|
assert_kind_of(Entry::OptionalKeywordParameter, parameters[0])
|
291
284
|
assert_kind_of(Entry::OptionalKeywordParameter, parameters[1])
|
@@ -308,14 +301,14 @@ module RubyIndexer
|
|
308
301
|
end
|
309
302
|
|
310
303
|
def test_rbs_method_with_rest_keywords
|
311
|
-
entries = @index["method_missing"]
|
312
|
-
entry = entries.find { |entry| entry.owner
|
304
|
+
entries = @index["method_missing"] #: as Array[Entry::Method]
|
305
|
+
entry = entries.find { |entry| entry.owner&.name == "BasicObject" } #: as !nil
|
313
306
|
signatures = entry.signatures
|
314
307
|
assert_equal(1, signatures.length)
|
315
308
|
|
316
309
|
# (Symbol, *untyped, **untyped) ?{ (*untyped, **untyped) -> untyped } -> untyped
|
317
310
|
|
318
|
-
parameters = signatures[0]
|
311
|
+
parameters = signatures[0]&.parameters #: as !nil
|
319
312
|
assert_equal([:arg0, :"<anonymous splat>", :"<anonymous keyword splat>"], parameters.map(&:name))
|
320
313
|
assert_kind_of(Entry::RequiredParameter, parameters[0])
|
321
314
|
assert_kind_of(Entry::RestParameter, parameters[1])
|
@@ -348,24 +341,24 @@ module RubyIndexer
|
|
348
341
|
def test_signature_alias
|
349
342
|
# In RBS, an alias means that two methods have the same signature.
|
350
343
|
# It does not mean the same thing as a Ruby alias.
|
351
|
-
any_entries = @index["any?"]
|
344
|
+
any_entries = @index["any?"] #: as Array[Entry::UnresolvedMethodAlias]
|
352
345
|
|
353
|
-
assert_equal(["Array", "Enumerable", "Hash"], any_entries.map { _1.owner
|
346
|
+
assert_equal(["Array", "Enumerable", "Hash"], any_entries.map { _1.owner&.name })
|
354
347
|
|
355
|
-
entry = any_entries.find { |entry| entry.owner
|
348
|
+
entry = any_entries.find { |entry| entry.owner&.name == "Array" } #: as !nil
|
356
349
|
|
357
350
|
assert_kind_of(RubyIndexer::Entry::UnresolvedMethodAlias, entry)
|
358
351
|
assert_equal("any?", entry.name)
|
359
352
|
assert_equal("all?", entry.old_name)
|
360
|
-
assert_equal("Array", entry.owner
|
361
|
-
assert(entry.file_path
|
353
|
+
assert_equal("Array", entry.owner&.name)
|
354
|
+
assert(entry.file_path&.end_with?("core/array.rbs"))
|
362
355
|
refute_empty(entry.comments)
|
363
356
|
end
|
364
357
|
|
365
358
|
def test_indexing_untyped_functions
|
366
|
-
entries = @index.resolve_method("call", "Method")
|
359
|
+
entries = @index.resolve_method("call", "Method") #: as Array[Entry::Method]
|
367
360
|
|
368
|
-
parameters = entries.first
|
361
|
+
parameters = entries.first&.signatures&.first&.parameters #: as !nil
|
369
362
|
assert_equal(1, parameters.length)
|
370
363
|
assert_instance_of(Entry::ForwardingParameter, parameters.first)
|
371
364
|
end
|
@@ -379,7 +372,8 @@ module RubyIndexer
|
|
379
372
|
indexer = RubyIndexer::RBSIndexer.new(index)
|
380
373
|
pathname = Pathname.new("/file.rbs")
|
381
374
|
indexer.process_signature(pathname, declarations)
|
382
|
-
entry =
|
375
|
+
entry = index[method_name] #: as !nil
|
376
|
+
.first
|
383
377
|
T.cast(entry, Entry::Method).signatures
|
384
378
|
end
|
385
379
|
end
|
@@ -18,11 +18,11 @@ module RubyIndexer
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def assert_entry(expected_name, type, expected_location, visibility: nil)
|
21
|
-
entries = @index[expected_name]
|
21
|
+
entries = @index[expected_name] #: as !nil
|
22
22
|
refute_nil(entries, "Expected #{expected_name} to be indexed")
|
23
23
|
refute_empty(entries, "Expected #{expected_name} to be indexed")
|
24
24
|
|
25
|
-
entry = entries.first
|
25
|
+
entry = entries.first #: as !nil
|
26
26
|
assert_instance_of(type, entry, "Expected #{expected_name} to be a #{type}")
|
27
27
|
|
28
28
|
location = entry.location
|
@@ -111,7 +111,9 @@ module RubyLsp
|
|
111
111
|
push_char(" ")
|
112
112
|
end
|
113
113
|
else
|
114
|
-
push_char(
|
114
|
+
push_char(
|
115
|
+
char, #: as !nil
|
116
|
+
)
|
115
117
|
end
|
116
118
|
when "-"
|
117
119
|
if @inside_ruby && next_char == "%" &&
|
@@ -120,7 +122,9 @@ module RubyLsp
|
|
120
122
|
push_char(" ")
|
121
123
|
@inside_ruby = false
|
122
124
|
else
|
123
|
-
push_char(
|
125
|
+
push_char(
|
126
|
+
char, #: as !nil
|
127
|
+
)
|
124
128
|
end
|
125
129
|
when "%"
|
126
130
|
if @inside_ruby && next_char == ">"
|
@@ -128,7 +132,9 @@ module RubyLsp
|
|
128
132
|
@current_pos += 1
|
129
133
|
push_char(" ")
|
130
134
|
else
|
131
|
-
push_char(
|
135
|
+
push_char(
|
136
|
+
char, #: as !nil
|
137
|
+
)
|
132
138
|
end
|
133
139
|
when "\r"
|
134
140
|
@ruby << char
|
@@ -143,7 +149,9 @@ module RubyLsp
|
|
143
149
|
@ruby << char
|
144
150
|
@host_language << char
|
145
151
|
else
|
146
|
-
push_char(
|
152
|
+
push_char(
|
153
|
+
char, #: as !nil
|
154
|
+
)
|
147
155
|
end
|
148
156
|
end
|
149
157
|
|
@@ -208,7 +208,7 @@ module RubyLsp
|
|
208
208
|
|
209
209
|
#: (?group_stack: Array[String], ?spec_name: String?, ?method_name: String?) -> String
|
210
210
|
def generate_test_command(group_stack: [], spec_name: nil, method_name: nil)
|
211
|
-
path =
|
211
|
+
path = @path #: as !nil
|
212
212
|
command = BASE_COMMAND
|
213
213
|
command += " -Itest" if File.fnmatch?("**/test/**/*", path, File::FNM_PATHNAME)
|
214
214
|
command += " -Ispec" if File.fnmatch?("**/spec/**/*", path, File::FNM_PATHNAME)
|
@@ -233,7 +233,7 @@ module RubyLsp
|
|
233
233
|
# the best we can do is match everything to the right of it.
|
234
234
|
# Tests are classes, dynamic references are only a thing for modules,
|
235
235
|
# so there must be something to the left of the available path.
|
236
|
-
dynamic_stack =
|
236
|
+
dynamic_stack = group_stack[last_dynamic_reference_index + 1..] #: as !nil
|
237
237
|
|
238
238
|
if method_name
|
239
239
|
" --name " + "/::#{Shellwords.escape(dynamic_stack.join("::")) + "#" + Shellwords.escape(method_name)}$/"
|
@@ -257,7 +257,7 @@ module RubyLsp
|
|
257
257
|
|
258
258
|
#: (Array[String] group_stack, String? method_name) -> String
|
259
259
|
def generate_test_unit_command(group_stack, method_name)
|
260
|
-
group_name =
|
260
|
+
group_name = group_stack.last #: as !nil
|
261
261
|
command = " --testcase " + "/#{Shellwords.escape(group_name)}/"
|
262
262
|
|
263
263
|
if method_name
|
@@ -108,7 +108,8 @@ module RubyLsp
|
|
108
108
|
range = range_from_location(node.location)
|
109
109
|
candidates = @index.constant_completion_candidates(name, @node_context.nesting)
|
110
110
|
candidates.each do |entries|
|
111
|
-
complete_name =
|
111
|
+
complete_name = entries.first #: as !nil
|
112
|
+
.name
|
112
113
|
@response_builder << build_entry_completion(
|
113
114
|
complete_name,
|
114
115
|
name,
|
@@ -155,7 +156,7 @@ module RubyLsp
|
|
155
156
|
|
156
157
|
if name
|
157
158
|
start_loc = node.location
|
158
|
-
end_loc =
|
159
|
+
end_loc = node.call_operator_loc #: as !nil
|
159
160
|
|
160
161
|
constant_path_completion(
|
161
162
|
"#{name}::",
|
@@ -296,7 +297,9 @@ module RubyLsp
|
|
296
297
|
namespace_entries = @index.resolve(aliased_namespace, nesting)
|
297
298
|
return unless namespace_entries
|
298
299
|
|
299
|
-
|
300
|
+
namespace_name = namespace_entries.first #: as !nil
|
301
|
+
.name
|
302
|
+
real_namespace = @index.follow_aliased_namespace(namespace_name)
|
300
303
|
|
301
304
|
candidates = @index.constant_completion_candidates(
|
302
305
|
"#{real_namespace}::#{incomplete_name}",
|
@@ -305,7 +308,7 @@ module RubyLsp
|
|
305
308
|
candidates.each do |entries|
|
306
309
|
# The only time we may have a private constant reference from outside of the namespace is if we're dealing
|
307
310
|
# with ConstantPath and the entry name doesn't start with the current nesting
|
308
|
-
first_entry =
|
311
|
+
first_entry = entries.first #: as !nil
|
309
312
|
next if first_entry.private? && !first_entry.name.start_with?("#{nesting}::")
|
310
313
|
|
311
314
|
entry_name = first_entry.name
|
@@ -324,7 +327,7 @@ module RubyLsp
|
|
324
327
|
name,
|
325
328
|
range,
|
326
329
|
entries,
|
327
|
-
top_level_reference || top_level?(
|
330
|
+
top_level_reference || top_level?(first_entry.name),
|
328
331
|
)
|
329
332
|
end
|
330
333
|
end
|
@@ -429,7 +432,10 @@ module RubyLsp
|
|
429
432
|
matched_uris = @index.search_require_paths(path_node_to_complete.content)
|
430
433
|
|
431
434
|
matched_uris.map!(&:require_path).sort!.each do |path|
|
432
|
-
@response_builder << build_completion(
|
435
|
+
@response_builder << build_completion(
|
436
|
+
path, #: as !nil
|
437
|
+
path_node_to_complete,
|
438
|
+
)
|
433
439
|
end
|
434
440
|
end
|
435
441
|
|
@@ -486,7 +492,9 @@ module RubyLsp
|
|
486
492
|
method_name = @trigger_character == "." ? nil : name
|
487
493
|
|
488
494
|
range = if method_name
|
489
|
-
range_from_location(
|
495
|
+
range_from_location(
|
496
|
+
node.message_loc, #: as !nil
|
497
|
+
)
|
490
498
|
else
|
491
499
|
loc = node.call_operator_loc
|
492
500
|
|
@@ -531,7 +539,9 @@ module RubyLsp
|
|
531
539
|
|
532
540
|
#: (Prism::CallNode node, String name) -> void
|
533
541
|
def add_local_completions(node, name)
|
534
|
-
range = range_from_location(
|
542
|
+
range = range_from_location(
|
543
|
+
node.message_loc, #: as !nil
|
544
|
+
)
|
535
545
|
|
536
546
|
@node_context.locals_for_scope.each do |local|
|
537
547
|
local_name = local.to_s
|
@@ -551,7 +561,9 @@ module RubyLsp
|
|
551
561
|
|
552
562
|
#: (Prism::CallNode node, String name) -> void
|
553
563
|
def add_keyword_completions(node, name)
|
554
|
-
range = range_from_location(
|
564
|
+
range = range_from_location(
|
565
|
+
node.message_loc, #: as !nil
|
566
|
+
)
|
555
567
|
|
556
568
|
KEYWORDS.each do |keyword|
|
557
569
|
next unless keyword.start_with?(name)
|
@@ -584,7 +596,7 @@ module RubyLsp
|
|
584
596
|
|
585
597
|
#: (String real_name, String incomplete_name, Interface::Range range, Array[RubyIndexer::Entry] entries, bool top_level) -> Interface::CompletionItem
|
586
598
|
def build_entry_completion(real_name, incomplete_name, range, entries, top_level)
|
587
|
-
first_entry =
|
599
|
+
first_entry = entries.first #: as !nil
|
588
600
|
kind = case first_entry
|
589
601
|
when RubyIndexer::Entry::Class
|
590
602
|
Constant::CompletionItemKind::CLASS
|
@@ -675,7 +687,8 @@ module RubyLsp
|
|
675
687
|
def top_level?(entry_name)
|
676
688
|
nesting = @node_context.nesting
|
677
689
|
nesting.length.downto(0) do |i|
|
678
|
-
prefix =
|
690
|
+
prefix = nesting[0...i] #: as !nil
|
691
|
+
.join("::")
|
679
692
|
full_name = prefix.empty? ? entry_name : "#{prefix}::#{entry_name}"
|
680
693
|
next if full_name == entry_name
|
681
694
|
|
@@ -382,7 +382,7 @@ module RubyLsp
|
|
382
382
|
|
383
383
|
# We should only allow jumping to the definition of private constants if the constant is defined in the same
|
384
384
|
# namespace as the reference
|
385
|
-
first_entry =
|
385
|
+
first_entry = entries.first #: as !nil
|
386
386
|
return if first_entry.private? && first_entry.name != "#{@node_context.fully_qualified_name}::#{value}"
|
387
387
|
|
388
388
|
entries.each do |entry|
|
@@ -318,7 +318,7 @@ module RubyLsp
|
|
318
318
|
name: name,
|
319
319
|
kind: Constant::SymbolKind::METHOD,
|
320
320
|
range_location: new_name_node.location,
|
321
|
-
selection_range_location:
|
321
|
+
selection_range_location: new_name_node.value_loc, #: as !nil
|
322
322
|
)
|
323
323
|
end
|
324
324
|
|
@@ -357,7 +357,7 @@ module RubyLsp
|
|
357
357
|
name: name,
|
358
358
|
kind: Constant::SymbolKind::FIELD,
|
359
359
|
range_location: argument.location,
|
360
|
-
selection_range_location:
|
360
|
+
selection_range_location: argument.value_loc, #: as !nil
|
361
361
|
)
|
362
362
|
elsif argument.is_a?(Prism::StringNode)
|
363
363
|
name = argument.content
|
@@ -391,7 +391,7 @@ module RubyLsp
|
|
391
391
|
name: name,
|
392
392
|
kind: Constant::SymbolKind::METHOD,
|
393
393
|
range_location: new_name_argument.location,
|
394
|
-
selection_range_location:
|
394
|
+
selection_range_location: new_name_argument.value_loc, #: as !nil
|
395
395
|
)
|
396
396
|
elsif new_name_argument.is_a?(Prism::StringNode)
|
397
397
|
name = new_name_argument.content
|
@@ -193,8 +193,10 @@ module RubyLsp
|
|
193
193
|
next if chunk.length == 1
|
194
194
|
|
195
195
|
@response_builder << Interface::FoldingRange.new(
|
196
|
-
start_line:
|
197
|
-
|
196
|
+
start_line: chunk.first #: as !nil
|
197
|
+
.location.start_line - 1,
|
198
|
+
end_line: chunk.last #: as !nil
|
199
|
+
.location.end_line - 1,
|
198
200
|
kind: "comment",
|
199
201
|
)
|
200
202
|
end
|
@@ -204,8 +206,10 @@ module RubyLsp
|
|
204
206
|
def emit_requires_range
|
205
207
|
if @requires.length > 1
|
206
208
|
@response_builder << Interface::FoldingRange.new(
|
207
|
-
start_line:
|
208
|
-
|
209
|
+
start_line: @requires.first #: as !nil
|
210
|
+
.location.start_line - 1,
|
211
|
+
end_line: @requires.last #: as !nil
|
212
|
+
.location.end_line - 1,
|
209
213
|
kind: "imports",
|
210
214
|
)
|
211
215
|
end
|