@@ -180,8 +180,6 @@ class A
180180 end
181181
182182 def test_jumping_to_private_constant_from_different_namespace
183- skip ( "[RUBYDEX] Requires the visibility API" )
184-
185183 source = <<~RUBY
186184 class A
187185 CONST = 123
@@ -201,6 +199,136 @@ class A
201199 end
202200 end
203201
202+ def test_jumping_to_private_method_with_implicit_self
203+ source = <<~RUBY
204+ class A
205+ def bar
206+ foo
207+ end
208+
209+ private
210+
211+ def foo; end
212+ end
213+ RUBY
214+
215+ with_server ( source , stub_no_typechecker : true ) do |server , uri |
216+ server . process_message (
217+ id : 1 ,
218+ method : "textDocument/definition" ,
219+ params : { textDocument : { uri : uri } , position : { character : 4 , line : 2 } } ,
220+ )
221+ response = server . pop_response . response
222+ refute_empty ( response )
223+ assert_equal ( uri . to_s , response . first . attributes [ :targetUri ] )
224+ end
225+ end
226+
227+ def test_does_not_jump_to_private_method_called_with_explicit_external_receiver
228+ source = <<~RUBY
229+ class A
230+ private
231+
232+ def foo; end
233+ end
234+
235+ class B
236+ def bar
237+ a = A.new
238+ a.foo
239+ end
240+ end
241+ RUBY
242+
243+ with_server ( source , stub_no_typechecker : true ) do |server , uri |
244+ server . process_message (
245+ id : 1 ,
246+ method : "textDocument/definition" ,
247+ params : { textDocument : { uri : uri } , position : { character : 6 , line : 9 } } ,
248+ )
249+ assert_empty ( server . pop_response . response )
250+ end
251+ end
252+
253+ def test_jumps_to_protected_method_inside_same_class
254+ source = <<~RUBY
255+ class A
256+ def bar
257+ self.foo
258+ end
259+
260+ protected
261+
262+ def foo; end
263+ end
264+ RUBY
265+
266+ with_server ( source , stub_no_typechecker : true ) do |server , uri |
267+ server . process_message (
268+ id : 1 ,
269+ method : "textDocument/definition" ,
270+ params : { textDocument : { uri : uri } , position : { character : 9 , line : 2 } } ,
271+ )
272+ response = server . pop_response . response
273+ refute_empty ( response )
274+ assert_equal ( uri . to_s , response . first . attributes [ :targetUri ] )
275+ end
276+ end
277+
278+ def test_jumps_to_protected_method_called_from_subclass
279+ source = <<~RUBY
280+ class A
281+ protected
282+
283+ def foo; end
284+ end
285+
286+ class B < A
287+ def bar
288+ a = A.new
289+ a.foo
290+ end
291+ end
292+ RUBY
293+
294+ with_server ( source , stub_no_typechecker : true ) do |server , uri |
295+ server . process_message (
296+ id : 1 ,
297+ method : "textDocument/definition" ,
298+ params : { textDocument : { uri : uri } , position : { character : 6 , line : 9 } } ,
299+ )
300+ response = server . pop_response . response
301+ refute_empty ( response )
302+ assert_equal ( uri . to_s , response . first . attributes [ :targetUri ] )
303+ end
304+ end
305+
306+ def test_does_not_jump_to_protected_method_from_unrelated_class
307+ source = <<~RUBY
308+ class A
309+ protected
310+
311+ def foo; end
312+ end
313+
314+ class C
315+ def bar
316+ a = A.new
317+ a.foo
318+ end
319+ end
320+ RUBY
321+
322+ with_server ( source , stub_no_typechecker : true ) do |server , uri |
323+ server . process_message (
324+ id : 1 ,
325+ method : "textDocument/definition" ,
326+ params : { textDocument : { uri : uri } , position : { character : 6 , line : 9 } } ,
327+ )
328+ assert_empty ( server . pop_response . response )
329+ end
330+ end
331+
204332 def test_definition_addons
205333 source = <<~RUBY
206334 class Target
0 commit comments