ruby-lsp 0.17.3 → 0.17.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -0
  3. data/VERSION +1 -1
  4. data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +251 -100
  5. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +173 -114
  6. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +337 -77
  7. data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +43 -14
  8. data/lib/ruby_indexer/test/classes_and_modules_test.rb +79 -3
  9. data/lib/ruby_indexer/test/index_test.rb +563 -29
  10. data/lib/ruby_indexer/test/instance_variables_test.rb +84 -7
  11. data/lib/ruby_indexer/test/method_test.rb +75 -25
  12. data/lib/ruby_indexer/test/rbs_indexer_test.rb +38 -2
  13. data/lib/ruby_indexer/test/test_case.rb +1 -5
  14. data/lib/ruby_lsp/addon.rb +13 -1
  15. data/lib/ruby_lsp/document.rb +50 -23
  16. data/lib/ruby_lsp/erb_document.rb +125 -0
  17. data/lib/ruby_lsp/global_state.rb +11 -4
  18. data/lib/ruby_lsp/internal.rb +3 -0
  19. data/lib/ruby_lsp/listeners/completion.rb +69 -34
  20. data/lib/ruby_lsp/listeners/definition.rb +34 -23
  21. data/lib/ruby_lsp/listeners/hover.rb +14 -7
  22. data/lib/ruby_lsp/listeners/signature_help.rb +5 -2
  23. data/lib/ruby_lsp/node_context.rb +6 -1
  24. data/lib/ruby_lsp/requests/code_action_resolve.rb +2 -2
  25. data/lib/ruby_lsp/requests/completion.rb +6 -5
  26. data/lib/ruby_lsp/requests/completion_resolve.rb +7 -4
  27. data/lib/ruby_lsp/requests/definition.rb +4 -3
  28. data/lib/ruby_lsp/requests/formatting.rb +2 -0
  29. data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +88 -0
  30. data/lib/ruby_lsp/requests/selection_ranges.rb +1 -1
  31. data/lib/ruby_lsp/requests/show_syntax_tree.rb +3 -2
  32. data/lib/ruby_lsp/requests/support/common.rb +19 -1
  33. data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +12 -4
  34. data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +87 -0
  35. data/lib/ruby_lsp/requests/workspace_symbol.rb +1 -21
  36. data/lib/ruby_lsp/requests.rb +2 -0
  37. data/lib/ruby_lsp/ruby_document.rb +10 -0
  38. data/lib/ruby_lsp/server.rb +95 -26
  39. data/lib/ruby_lsp/store.rb +23 -8
  40. data/lib/ruby_lsp/test_helper.rb +3 -1
  41. data/lib/ruby_lsp/type_inferrer.rb +86 -0
  42. metadata +10 -6
@@ -461,14 +461,90 @@ module RubyIndexer
461
461
  end
462
462
  RUBY
463
463
 
464
- foo = T.must(@index["Foo"][0])
464
+ foo = T.must(@index["Foo::<Class:Foo>"][0])
465
465
  assert_equal(["A1", "A2", "A3", "A4", "A5", "A6"], foo.mixin_operation_module_names)
466
466
 
467
- qux = T.must(@index["Foo::Qux"][0])
467
+ qux = T.must(@index["Foo::Qux::<Class:Qux>"][0])
468
468
  assert_equal(["Corge", "Corge", "Baz"], qux.mixin_operation_module_names)
469
469
 
470
- constant_path_references = T.must(@index["ConstantPathReferences"][0])
470
+ constant_path_references = T.must(@index["ConstantPathReferences::<Class:ConstantPathReferences>"][0])
471
471
  assert_equal(["Foo::Bar", "Foo::Bar2"], constant_path_references.mixin_operation_module_names)
472
472
  end
473
+
474
+ def test_tracking_singleton_classes
475
+ index(<<~RUBY)
476
+ class Foo; end
477
+ class Foo
478
+ # Some extra comments
479
+ class << self
480
+ end
481
+ end
482
+ RUBY
483
+
484
+ foo = T.must(@index["Foo::<Class:Foo>"].first)
485
+ assert_equal(4, foo.location.start_line)
486
+ assert_equal("Some extra comments", foo.comments.join("\n"))
487
+ end
488
+
489
+ def test_dynamic_singleton_class_blocks
490
+ index(<<~RUBY)
491
+ class Foo
492
+ # Some extra comments
493
+ class << bar
494
+ end
495
+ end
496
+ RUBY
497
+
498
+ singleton = T.must(@index["Foo::<Class:bar>"].first)
499
+
500
+ # Even though this is not correct, we consider any dynamic singleton class block as a regular singleton class.
501
+ # That pattern cannot be properly analyzed statically and assuming that it's always a regular singleton simplifies
502
+ # the implementation considerably.
503
+ assert_equal(3, singleton.location.start_line)
504
+ assert_equal("Some extra comments", singleton.comments.join("\n"))
505
+ end
506
+
507
+ def test_namespaces_inside_singleton_blocks
508
+ index(<<~RUBY)
509
+ class Foo
510
+ class << self
511
+ class Bar
512
+ end
513
+ end
514
+ end
515
+ RUBY
516
+
517
+ assert_entry("Foo::<Class:Foo>::Bar", Entry::Class, "/fake/path/foo.rb:2-4:3-7")
518
+ end
519
+
520
+ def test_name_location_points_to_constant_path_location
521
+ index(<<~RUBY)
522
+ class Foo
523
+ def foo; end
524
+ end
525
+
526
+ module Bar
527
+ def bar; end
528
+ end
529
+ RUBY
530
+
531
+ foo = T.must(@index["Foo"].first)
532
+ refute_equal(foo.location, foo.name_location)
533
+
534
+ name_location = foo.name_location
535
+ assert_equal(1, name_location.start_line)
536
+ assert_equal(1, name_location.end_line)
537
+ assert_equal(6, name_location.start_column)
538
+ assert_equal(9, name_location.end_column)
539
+
540
+ bar = T.must(@index["Bar"].first)
541
+ refute_equal(bar.location, bar.name_location)
542
+
543
+ name_location = bar.name_location
544
+ assert_equal(5, name_location.start_line)
545
+ assert_equal(5, name_location.end_line)
546
+ assert_equal(7, name_location.start_column)
547
+ assert_equal(10, name_location.end_column)
548
+ end
473
549
  end
474
550
  end