ruby-lsp 0.26.5 → 0.26.7
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 +5 -1
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +3 -2
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +7 -1
- data/lib/ruby_lsp/setup_bundler.rb +16 -12
- data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +43 -28
- data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +1 -1
- data/lib/ruby_lsp/test_reporters/test_unit_reporter.rb +1 -1
- metadata +1 -15
- data/lib/ruby_indexer/test/class_variables_test.rb +0 -140
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +0 -790
- data/lib/ruby_indexer/test/configuration_test.rb +0 -277
- data/lib/ruby_indexer/test/constant_test.rb +0 -402
- data/lib/ruby_indexer/test/enhancements_test.rb +0 -325
- data/lib/ruby_indexer/test/global_variable_test.rb +0 -49
- data/lib/ruby_indexer/test/index_test.rb +0 -2273
- data/lib/ruby_indexer/test/instance_variables_test.rb +0 -264
- data/lib/ruby_indexer/test/method_test.rb +0 -990
- data/lib/ruby_indexer/test/prefix_tree_test.rb +0 -150
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +0 -381
- data/lib/ruby_indexer/test/reference_finder_test.rb +0 -395
- data/lib/ruby_indexer/test/test_case.rb +0 -57
- data/lib/ruby_indexer/test/uri_test.rb +0 -85
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
# typed: true
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require_relative "test_case"
|
|
5
|
-
|
|
6
|
-
module RubyIndexer
|
|
7
|
-
class EnhancementTest < TestCase
|
|
8
|
-
def teardown
|
|
9
|
-
super
|
|
10
|
-
Enhancement.clear
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def test_enhancing_indexing_included_hook
|
|
14
|
-
Class.new(Enhancement) do
|
|
15
|
-
def on_call_node_enter(call_node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
|
16
|
-
owner = @listener.current_owner
|
|
17
|
-
return unless owner
|
|
18
|
-
return unless call_node.name == :extend
|
|
19
|
-
|
|
20
|
-
arguments = call_node.arguments&.arguments
|
|
21
|
-
return unless arguments
|
|
22
|
-
|
|
23
|
-
arguments.each do |node|
|
|
24
|
-
next unless node.is_a?(Prism::ConstantReadNode) || node.is_a?(Prism::ConstantPathNode)
|
|
25
|
-
|
|
26
|
-
module_name = node.full_name
|
|
27
|
-
next unless module_name == "ActiveSupport::Concern"
|
|
28
|
-
|
|
29
|
-
@listener.register_included_hook do |index, base|
|
|
30
|
-
class_methods_name = "#{owner.name}::ClassMethods"
|
|
31
|
-
|
|
32
|
-
if index.indexed?(class_methods_name)
|
|
33
|
-
singleton = index.existing_or_new_singleton_class(base.name)
|
|
34
|
-
singleton.mixin_operations << Entry::Include.new(class_methods_name)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
@listener.add_method(
|
|
39
|
-
"new_method",
|
|
40
|
-
call_node.location,
|
|
41
|
-
[Entry::Signature.new([Entry::RequiredParameter.new(name: :a)])],
|
|
42
|
-
)
|
|
43
|
-
rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError,
|
|
44
|
-
Prism::ConstantPathNode::MissingNodesInConstantPathError
|
|
45
|
-
# Do nothing
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
index(<<~RUBY)
|
|
51
|
-
module ActiveSupport
|
|
52
|
-
module Concern
|
|
53
|
-
def self.extended(base)
|
|
54
|
-
base.class_eval("def new_method(a); end")
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
module ActiveRecord
|
|
60
|
-
module Associations
|
|
61
|
-
extend ActiveSupport::Concern
|
|
62
|
-
|
|
63
|
-
module ClassMethods
|
|
64
|
-
def belongs_to(something); end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
class Base
|
|
69
|
-
include Associations
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
class User < ActiveRecord::Base
|
|
74
|
-
end
|
|
75
|
-
RUBY
|
|
76
|
-
|
|
77
|
-
assert_equal(
|
|
78
|
-
[
|
|
79
|
-
"User::<Class:User>",
|
|
80
|
-
"ActiveRecord::Base::<Class:Base>",
|
|
81
|
-
"ActiveRecord::Associations::ClassMethods",
|
|
82
|
-
"Object::<Class:Object>",
|
|
83
|
-
"BasicObject::<Class:BasicObject>",
|
|
84
|
-
"Class",
|
|
85
|
-
"Module",
|
|
86
|
-
"Object",
|
|
87
|
-
"Kernel",
|
|
88
|
-
"BasicObject",
|
|
89
|
-
],
|
|
90
|
-
@index.linearized_ancestors_of("User::<Class:User>"),
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
assert_entry("new_method", Entry::Method, "/fake/path/foo.rb:10-4:10-33")
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def test_enhancing_indexing_configuration_dsl
|
|
97
|
-
Class.new(Enhancement) do
|
|
98
|
-
def on_call_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
|
99
|
-
return unless @listener.current_owner
|
|
100
|
-
|
|
101
|
-
name = node.name
|
|
102
|
-
return unless name == :has_many
|
|
103
|
-
|
|
104
|
-
arguments = node.arguments&.arguments
|
|
105
|
-
return unless arguments
|
|
106
|
-
|
|
107
|
-
association_name = arguments.first
|
|
108
|
-
return unless association_name.is_a?(Prism::SymbolNode)
|
|
109
|
-
|
|
110
|
-
@listener.add_method(
|
|
111
|
-
association_name.value, #: as !nil
|
|
112
|
-
association_name.location,
|
|
113
|
-
[],
|
|
114
|
-
)
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
index(<<~RUBY)
|
|
119
|
-
module ActiveSupport
|
|
120
|
-
module Concern
|
|
121
|
-
def self.extended(base)
|
|
122
|
-
base.class_eval("def new_method(a); end")
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
module ActiveRecord
|
|
128
|
-
module Associations
|
|
129
|
-
extend ActiveSupport::Concern
|
|
130
|
-
|
|
131
|
-
module ClassMethods
|
|
132
|
-
def belongs_to(something); end
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
class Base
|
|
137
|
-
include Associations
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
class User < ActiveRecord::Base
|
|
142
|
-
has_many :posts
|
|
143
|
-
end
|
|
144
|
-
RUBY
|
|
145
|
-
|
|
146
|
-
assert_entry("posts", Entry::Method, "/fake/path/foo.rb:23-11:23-17")
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def test_error_handling_in_on_call_node_enter_enhancement
|
|
150
|
-
Class.new(Enhancement) do
|
|
151
|
-
def on_call_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
|
152
|
-
raise "Error"
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
class << self
|
|
156
|
-
def name
|
|
157
|
-
"TestEnhancement"
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
_stdout, stderr = capture_io do
|
|
163
|
-
index(<<~RUBY)
|
|
164
|
-
module ActiveSupport
|
|
165
|
-
module Concern
|
|
166
|
-
def self.extended(base)
|
|
167
|
-
base.class_eval("def new_method(a); end")
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
RUBY
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
assert_match(
|
|
175
|
-
%r{Indexing error in file:///fake/path/foo\.rb with 'TestEnhancement' on call node enter enhancement},
|
|
176
|
-
stderr,
|
|
177
|
-
)
|
|
178
|
-
# The module should still be indexed
|
|
179
|
-
assert_entry("ActiveSupport::Concern", Entry::Module, "/fake/path/foo.rb:1-2:5-5")
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def test_error_handling_in_on_call_node_leave_enhancement
|
|
183
|
-
Class.new(Enhancement) do
|
|
184
|
-
def on_call_node_leave(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
|
185
|
-
raise "Error"
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
class << self
|
|
189
|
-
def name
|
|
190
|
-
"TestEnhancement"
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
_stdout, stderr = capture_io do
|
|
196
|
-
index(<<~RUBY)
|
|
197
|
-
module ActiveSupport
|
|
198
|
-
module Concern
|
|
199
|
-
def self.extended(base)
|
|
200
|
-
base.class_eval("def new_method(a); end")
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
end
|
|
204
|
-
RUBY
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
assert_match(
|
|
208
|
-
%r{Indexing error in file:///fake/path/foo\.rb with 'TestEnhancement' on call node leave enhancement},
|
|
209
|
-
stderr,
|
|
210
|
-
)
|
|
211
|
-
# The module should still be indexed
|
|
212
|
-
assert_entry("ActiveSupport::Concern", Entry::Module, "/fake/path/foo.rb:1-2:5-5")
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def test_advancing_namespace_stack_from_enhancement
|
|
216
|
-
Class.new(Enhancement) do
|
|
217
|
-
def on_call_node_enter(call_node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
|
218
|
-
owner = @listener.current_owner
|
|
219
|
-
return unless owner
|
|
220
|
-
|
|
221
|
-
case call_node.name
|
|
222
|
-
when :class_methods
|
|
223
|
-
@listener.add_module("ClassMethods", call_node.location, call_node.location)
|
|
224
|
-
when :extend
|
|
225
|
-
arguments = call_node.arguments&.arguments
|
|
226
|
-
return unless arguments
|
|
227
|
-
|
|
228
|
-
arguments.each do |node|
|
|
229
|
-
next unless node.is_a?(Prism::ConstantReadNode) || node.is_a?(Prism::ConstantPathNode)
|
|
230
|
-
|
|
231
|
-
module_name = node.full_name
|
|
232
|
-
next unless module_name == "ActiveSupport::Concern"
|
|
233
|
-
|
|
234
|
-
@listener.register_included_hook do |index, base|
|
|
235
|
-
class_methods_name = "#{owner.name}::ClassMethods"
|
|
236
|
-
|
|
237
|
-
if index.indexed?(class_methods_name)
|
|
238
|
-
singleton = index.existing_or_new_singleton_class(base.name)
|
|
239
|
-
singleton.mixin_operations << Entry::Include.new(class_methods_name)
|
|
240
|
-
end
|
|
241
|
-
end
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
def on_call_node_leave(call_node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
|
247
|
-
return unless call_node.name == :class_methods
|
|
248
|
-
|
|
249
|
-
@listener.pop_namespace_stack
|
|
250
|
-
end
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
index(<<~RUBY)
|
|
254
|
-
module ActiveSupport
|
|
255
|
-
module Concern
|
|
256
|
-
end
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
module MyConcern
|
|
260
|
-
extend ActiveSupport::Concern
|
|
261
|
-
|
|
262
|
-
class_methods do
|
|
263
|
-
def foo; end
|
|
264
|
-
end
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
class User
|
|
268
|
-
include MyConcern
|
|
269
|
-
end
|
|
270
|
-
RUBY
|
|
271
|
-
|
|
272
|
-
assert_equal(
|
|
273
|
-
[
|
|
274
|
-
"User::<Class:User>",
|
|
275
|
-
"MyConcern::ClassMethods",
|
|
276
|
-
"Object::<Class:Object>",
|
|
277
|
-
"BasicObject::<Class:BasicObject>",
|
|
278
|
-
"Class",
|
|
279
|
-
"Module",
|
|
280
|
-
"Object",
|
|
281
|
-
"Kernel",
|
|
282
|
-
"BasicObject",
|
|
283
|
-
],
|
|
284
|
-
@index.linearized_ancestors_of("User::<Class:User>"),
|
|
285
|
-
)
|
|
286
|
-
|
|
287
|
-
refute_nil(@index.resolve_method("foo", "User::<Class:User>"))
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
def test_creating_anonymous_classes_from_enhancement
|
|
291
|
-
Class.new(Enhancement) do
|
|
292
|
-
def on_call_node_enter(call_node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
|
293
|
-
case call_node.name
|
|
294
|
-
when :context
|
|
295
|
-
arguments = call_node.arguments&.arguments
|
|
296
|
-
first_argument = arguments&.first
|
|
297
|
-
return unless first_argument.is_a?(Prism::StringNode)
|
|
298
|
-
|
|
299
|
-
@listener.add_class(
|
|
300
|
-
"<RSpec:#{first_argument.content}>",
|
|
301
|
-
call_node.location,
|
|
302
|
-
first_argument.location,
|
|
303
|
-
)
|
|
304
|
-
when :subject
|
|
305
|
-
@listener.add_method("subject", call_node.location, [])
|
|
306
|
-
end
|
|
307
|
-
end
|
|
308
|
-
|
|
309
|
-
def on_call_node_leave(call_node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
|
|
310
|
-
return unless call_node.name == :context
|
|
311
|
-
|
|
312
|
-
@listener.pop_namespace_stack
|
|
313
|
-
end
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
index(<<~RUBY)
|
|
317
|
-
context "does something" do
|
|
318
|
-
subject { call_whatever }
|
|
319
|
-
end
|
|
320
|
-
RUBY
|
|
321
|
-
|
|
322
|
-
refute_nil(@index.resolve_method("subject", "<RSpec:does something>"))
|
|
323
|
-
end
|
|
324
|
-
end
|
|
325
|
-
end
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# typed: true
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require_relative "test_case"
|
|
5
|
-
|
|
6
|
-
module RubyIndexer
|
|
7
|
-
class GlobalVariableTest < TestCase
|
|
8
|
-
def test_global_variable_and_write
|
|
9
|
-
index(<<~RUBY)
|
|
10
|
-
$foo &&= 1
|
|
11
|
-
RUBY
|
|
12
|
-
|
|
13
|
-
assert_entry("$foo", Entry::GlobalVariable, "/fake/path/foo.rb:0-0:0-4")
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_global_variable_operator_write
|
|
17
|
-
index(<<~RUBY)
|
|
18
|
-
$foo += 1
|
|
19
|
-
RUBY
|
|
20
|
-
|
|
21
|
-
assert_entry("$foo", Entry::GlobalVariable, "/fake/path/foo.rb:0-0:0-4")
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def test_global_variable_or_write
|
|
25
|
-
index(<<~RUBY)
|
|
26
|
-
$foo ||= 1
|
|
27
|
-
RUBY
|
|
28
|
-
|
|
29
|
-
assert_entry("$foo", Entry::GlobalVariable, "/fake/path/foo.rb:0-0:0-4")
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_global_variable_target_node
|
|
33
|
-
index(<<~RUBY)
|
|
34
|
-
$foo, $bar = 1
|
|
35
|
-
RUBY
|
|
36
|
-
|
|
37
|
-
assert_entry("$foo", Entry::GlobalVariable, "/fake/path/foo.rb:0-0:0-4")
|
|
38
|
-
assert_entry("$bar", Entry::GlobalVariable, "/fake/path/foo.rb:0-6:0-10")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def test_global_variable_write
|
|
42
|
-
index(<<~RUBY)
|
|
43
|
-
$foo = 1
|
|
44
|
-
RUBY
|
|
45
|
-
|
|
46
|
-
assert_entry("$foo", Entry::GlobalVariable, "/fake/path/foo.rb:0-0:0-4")
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|