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,264 +0,0 @@
|
|
|
1
|
-
# typed: true
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require_relative "test_case"
|
|
5
|
-
|
|
6
|
-
module RubyIndexer
|
|
7
|
-
class InstanceVariableTest < TestCase
|
|
8
|
-
def test_instance_variable_write
|
|
9
|
-
index(<<~RUBY)
|
|
10
|
-
module Foo
|
|
11
|
-
class Bar
|
|
12
|
-
def initialize
|
|
13
|
-
# Hello
|
|
14
|
-
@a = 1
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
RUBY
|
|
19
|
-
|
|
20
|
-
assert_entry("@a", Entry::InstanceVariable, "/fake/path/foo.rb:4-6:4-8")
|
|
21
|
-
|
|
22
|
-
entry = @index["@a"]&.first #: as Entry::InstanceVariable
|
|
23
|
-
owner = entry.owner
|
|
24
|
-
assert_instance_of(Entry::Class, owner)
|
|
25
|
-
assert_equal("Foo::Bar", owner&.name)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def test_instance_variable_with_multibyte_characters
|
|
29
|
-
index(<<~RUBY)
|
|
30
|
-
class Foo
|
|
31
|
-
def initialize
|
|
32
|
-
@あ = 1
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
RUBY
|
|
36
|
-
|
|
37
|
-
assert_entry("@あ", Entry::InstanceVariable, "/fake/path/foo.rb:2-4:2-6")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def test_instance_variable_and_write
|
|
41
|
-
index(<<~RUBY)
|
|
42
|
-
module Foo
|
|
43
|
-
class Bar
|
|
44
|
-
def initialize
|
|
45
|
-
# Hello
|
|
46
|
-
@a &&= value
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
RUBY
|
|
51
|
-
|
|
52
|
-
assert_entry("@a", Entry::InstanceVariable, "/fake/path/foo.rb:4-6:4-8")
|
|
53
|
-
|
|
54
|
-
entry = @index["@a"]&.first #: as Entry::InstanceVariable
|
|
55
|
-
owner = entry.owner
|
|
56
|
-
assert_instance_of(Entry::Class, owner)
|
|
57
|
-
assert_equal("Foo::Bar", owner&.name)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def test_instance_variable_operator_write
|
|
61
|
-
index(<<~RUBY)
|
|
62
|
-
module Foo
|
|
63
|
-
class Bar
|
|
64
|
-
def initialize
|
|
65
|
-
# Hello
|
|
66
|
-
@a += value
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
RUBY
|
|
71
|
-
|
|
72
|
-
assert_entry("@a", Entry::InstanceVariable, "/fake/path/foo.rb:4-6:4-8")
|
|
73
|
-
|
|
74
|
-
entry = @index["@a"]&.first #: as Entry::InstanceVariable
|
|
75
|
-
owner = entry.owner
|
|
76
|
-
assert_instance_of(Entry::Class, owner)
|
|
77
|
-
assert_equal("Foo::Bar", owner&.name)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def test_instance_variable_or_write
|
|
81
|
-
index(<<~RUBY)
|
|
82
|
-
module Foo
|
|
83
|
-
class Bar
|
|
84
|
-
def initialize
|
|
85
|
-
# Hello
|
|
86
|
-
@a ||= value
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
RUBY
|
|
91
|
-
|
|
92
|
-
assert_entry("@a", Entry::InstanceVariable, "/fake/path/foo.rb:4-6:4-8")
|
|
93
|
-
|
|
94
|
-
entry = @index["@a"]&.first #: as Entry::InstanceVariable
|
|
95
|
-
owner = entry.owner
|
|
96
|
-
assert_instance_of(Entry::Class, owner)
|
|
97
|
-
assert_equal("Foo::Bar", owner&.name)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def test_instance_variable_target
|
|
101
|
-
index(<<~RUBY)
|
|
102
|
-
module Foo
|
|
103
|
-
class Bar
|
|
104
|
-
def initialize
|
|
105
|
-
# Hello
|
|
106
|
-
@a, @b = [1, 2]
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
RUBY
|
|
111
|
-
|
|
112
|
-
assert_entry("@a", Entry::InstanceVariable, "/fake/path/foo.rb:4-6:4-8")
|
|
113
|
-
assert_entry("@b", Entry::InstanceVariable, "/fake/path/foo.rb:4-10:4-12")
|
|
114
|
-
|
|
115
|
-
entry = @index["@a"]&.first #: as Entry::InstanceVariable
|
|
116
|
-
owner = entry.owner
|
|
117
|
-
assert_instance_of(Entry::Class, owner)
|
|
118
|
-
assert_equal("Foo::Bar", owner&.name)
|
|
119
|
-
|
|
120
|
-
entry = @index["@b"]&.first #: as Entry::InstanceVariable
|
|
121
|
-
owner = entry.owner
|
|
122
|
-
assert_instance_of(Entry::Class, owner)
|
|
123
|
-
assert_equal("Foo::Bar", owner&.name)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
def test_empty_name_instance_variables
|
|
127
|
-
index(<<~RUBY)
|
|
128
|
-
module Foo
|
|
129
|
-
class Bar
|
|
130
|
-
def initialize
|
|
131
|
-
@ = 123
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
RUBY
|
|
136
|
-
|
|
137
|
-
refute_entry("@")
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def test_class_instance_variables
|
|
141
|
-
index(<<~RUBY)
|
|
142
|
-
module Foo
|
|
143
|
-
class Bar
|
|
144
|
-
@a = 123
|
|
145
|
-
|
|
146
|
-
class << self
|
|
147
|
-
def hello
|
|
148
|
-
@b = 123
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
@c = 123
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
RUBY
|
|
156
|
-
|
|
157
|
-
assert_entry("@a", Entry::InstanceVariable, "/fake/path/foo.rb:2-4:2-6")
|
|
158
|
-
|
|
159
|
-
entry = @index["@a"]&.first #: as Entry::InstanceVariable
|
|
160
|
-
owner = entry.owner
|
|
161
|
-
assert_instance_of(Entry::SingletonClass, owner)
|
|
162
|
-
assert_equal("Foo::Bar::<Class:Bar>", owner&.name)
|
|
163
|
-
|
|
164
|
-
assert_entry("@b", Entry::InstanceVariable, "/fake/path/foo.rb:6-8:6-10")
|
|
165
|
-
|
|
166
|
-
entry = @index["@b"]&.first #: as Entry::InstanceVariable
|
|
167
|
-
owner = entry.owner
|
|
168
|
-
assert_instance_of(Entry::SingletonClass, owner)
|
|
169
|
-
assert_equal("Foo::Bar::<Class:Bar>", owner&.name)
|
|
170
|
-
|
|
171
|
-
assert_entry("@c", Entry::InstanceVariable, "/fake/path/foo.rb:9-6:9-8")
|
|
172
|
-
|
|
173
|
-
entry = @index["@c"]&.first #: as Entry::InstanceVariable
|
|
174
|
-
owner = entry.owner
|
|
175
|
-
assert_instance_of(Entry::SingletonClass, owner)
|
|
176
|
-
assert_equal("Foo::Bar::<Class:Bar>::<Class:<Class:Bar>>", owner&.name)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def test_top_level_instance_variables
|
|
180
|
-
index(<<~RUBY)
|
|
181
|
-
@a = 123
|
|
182
|
-
RUBY
|
|
183
|
-
|
|
184
|
-
entry = @index["@a"]&.first #: as Entry::InstanceVariable
|
|
185
|
-
assert_nil(entry.owner)
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
def test_class_instance_variables_inside_self_method
|
|
189
|
-
index(<<~RUBY)
|
|
190
|
-
class Foo
|
|
191
|
-
def self.bar
|
|
192
|
-
@a = 123
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
RUBY
|
|
196
|
-
|
|
197
|
-
entry = @index["@a"]&.first #: as Entry::InstanceVariable
|
|
198
|
-
owner = entry.owner
|
|
199
|
-
assert_instance_of(Entry::SingletonClass, owner)
|
|
200
|
-
assert_equal("Foo::<Class:Foo>", owner&.name)
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
def test_instance_variable_inside_dynamic_method_declaration
|
|
204
|
-
index(<<~RUBY)
|
|
205
|
-
class Foo
|
|
206
|
-
def something.bar
|
|
207
|
-
@a = 123
|
|
208
|
-
end
|
|
209
|
-
end
|
|
210
|
-
RUBY
|
|
211
|
-
|
|
212
|
-
# If the surrounding method is being defined on any dynamic value that isn't `self`, then we attribute the
|
|
213
|
-
# instance variable to the wrong owner since there's no way to understand that statically
|
|
214
|
-
entry = @index["@a"]&.first #: as Entry::InstanceVariable
|
|
215
|
-
owner = entry.owner
|
|
216
|
-
assert_instance_of(Entry::Class, owner)
|
|
217
|
-
assert_equal("Foo", owner&.name)
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
def test_module_function_does_not_impact_instance_variables
|
|
221
|
-
# One possible way of implementing `module_function` would be to push a fake singleton class to the stack, so that
|
|
222
|
-
# methods are inserted into it. However, that would be incorrect because it would then bind instance variables to
|
|
223
|
-
# the wrong type. This test is here to prevent that from happening.
|
|
224
|
-
index(<<~RUBY)
|
|
225
|
-
module Foo
|
|
226
|
-
module_function
|
|
227
|
-
|
|
228
|
-
def something; end
|
|
229
|
-
|
|
230
|
-
@a = 123
|
|
231
|
-
end
|
|
232
|
-
RUBY
|
|
233
|
-
|
|
234
|
-
entry = @index["@a"]&.first #: as Entry::InstanceVariable
|
|
235
|
-
owner = entry.owner
|
|
236
|
-
assert_instance_of(Entry::SingletonClass, owner)
|
|
237
|
-
assert_equal("Foo::<Class:Foo>", owner&.name)
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
def test_class_instance_variable_comments
|
|
241
|
-
index(<<~RUBY)
|
|
242
|
-
class Foo
|
|
243
|
-
# Documentation for @a
|
|
244
|
-
@a = "Hello" #: String
|
|
245
|
-
@b = "World" # trailing comment
|
|
246
|
-
@c = "!"
|
|
247
|
-
end
|
|
248
|
-
end
|
|
249
|
-
RUBY
|
|
250
|
-
|
|
251
|
-
assert_entry("@a", Entry::InstanceVariable, "/fake/path/foo.rb:2-4:2-6")
|
|
252
|
-
entry = @index["@a"]&.first #: as Entry::InstanceVariable
|
|
253
|
-
assert_equal("Documentation for @a", entry.comments)
|
|
254
|
-
|
|
255
|
-
assert_entry("@b", Entry::InstanceVariable, "/fake/path/foo.rb:3-4:3-6")
|
|
256
|
-
entry = @index["@b"]&.first #: as Entry::InstanceVariable
|
|
257
|
-
assert_empty(entry.comments)
|
|
258
|
-
|
|
259
|
-
assert_entry("@c", Entry::InstanceVariable, "/fake/path/foo.rb:4-4:4-6")
|
|
260
|
-
entry = @index["@c"]&.first #: as Entry::InstanceVariable
|
|
261
|
-
assert_empty(entry.comments)
|
|
262
|
-
end
|
|
263
|
-
end
|
|
264
|
-
end
|