From 2a2f4fee9dcf21427ebe40e09cd6c2ba5df48fdb Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Tue, 29 Aug 2023 16:52:19 -0400 Subject: [PATCH] Fix test references to index_single --- .../test/classes_and_modules_test.rb | 2 +- lib/ruby_indexer/test/index_test.rb | 18 ++++++++--------- lib/ruby_indexer/test/test_case.rb | 2 +- test/requests/definition_expectations_test.rb | 20 ++++++++++++++----- test/requests/hover_expectations_test.rb | 7 +++++-- test/requests/workspace_symbol_test.rb | 16 +++++++++------ 6 files changed, 41 insertions(+), 24 deletions(-) diff --git a/lib/ruby_indexer/test/classes_and_modules_test.rb b/lib/ruby_indexer/test/classes_and_modules_test.rb index 4a6ff46184..d515012490 100644 --- a/lib/ruby_indexer/test/classes_and_modules_test.rb +++ b/lib/ruby_indexer/test/classes_and_modules_test.rb @@ -139,7 +139,7 @@ class Foo assert_entry("Foo", Index::Entry::Class, "/fake/path/foo.rb:0-0:1-2") - @index.delete("/fake/path/foo.rb") + @index.delete(Indexable.new(nil, "/fake/path/foo.rb")) refute_entry("Foo") assert_empty(@index.instance_variable_get(:@files_to_entries)) end diff --git a/lib/ruby_indexer/test/index_test.rb b/lib/ruby_indexer/test/index_test.rb index bcc3c067c4..68d47e30f6 100644 --- a/lib/ruby_indexer/test/index_test.rb +++ b/lib/ruby_indexer/test/index_test.rb @@ -6,11 +6,11 @@ module RubyIndexer class IndexTest < TestCase def test_deleting_one_entry_for_a_class - @index.index_single("/fake/path/foo.rb", <<~RUBY) + @index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), <<~RUBY) class Foo end RUBY - @index.index_single("/fake/path/other_foo.rb", <<~RUBY) + @index.index_single(Indexable.new(nil, "/fake/path/other_foo.rb"), <<~RUBY) class Foo end RUBY @@ -18,13 +18,13 @@ class Foo entries = @index["Foo"] assert_equal(2, entries.length) - @index.delete("/fake/path/other_foo.rb") + @index.delete(Indexable.new(nil, "/fake/path/other_foo.rb")) entries = @index["Foo"] assert_equal(1, entries.length) end def test_deleting_all_entries_for_a_class - @index.index_single("/fake/path/foo.rb", <<~RUBY) + @index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), <<~RUBY) class Foo end RUBY @@ -32,13 +32,13 @@ class Foo entries = @index["Foo"] assert_equal(1, entries.length) - @index.delete("/fake/path/foo.rb") + @index.delete(Indexable.new(nil, "/fake/path/foo.rb")) entries = @index["Foo"] assert_nil(entries) end def test_index_resolve - @index.index_single("/fake/path/foo.rb", <<~RUBY) + @index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), <<~RUBY) class Bar; end module Foo @@ -72,7 +72,7 @@ class Something end def test_accessing_with_colon_colon_prefix - @index.index_single("/fake/path/foo.rb", <<~RUBY) + @index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), <<~RUBY) class Bar; end module Foo @@ -92,7 +92,7 @@ class Something end def test_fuzzy_search - @index.index_single("/fake/path/foo.rb", <<~RUBY) + @index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), <<~RUBY) class Bar; end module Foo @@ -121,7 +121,7 @@ class Something def test_index_single_ignores_directories FileUtils.mkdir("lib/this_is_a_dir.rb") - @index.index_single("lib/this_is_a_dir.rb") + @index.index_single(Indexable.new(nil, "lib/this_is_a_dir.rb")) ensure FileUtils.rm_r("lib/this_is_a_dir.rb") end diff --git a/lib/ruby_indexer/test/test_case.rb b/lib/ruby_indexer/test/test_case.rb index 58978dfcd9..8ec4a4b9a7 100644 --- a/lib/ruby_indexer/test/test_case.rb +++ b/lib/ruby_indexer/test/test_case.rb @@ -12,7 +12,7 @@ def setup private def index(source) - @index.index_single("/fake/path/foo.rb", source) + @index.index_single(Indexable.new(nil, "/fake/path/foo.rb"), source) end def assert_entry(expected_name, type, expected_location) diff --git a/test/requests/definition_expectations_test.rb b/test/requests/definition_expectations_test.rb index 10d470bc1a..97acae36d6 100644 --- a/test/requests/definition_expectations_test.rb +++ b/test/requests/definition_expectations_test.rb @@ -15,10 +15,15 @@ def run_expectations(source) store.set(uri: URI("file:///folder/fake.rb"), source: source, version: 1) executor = RubyLsp::Executor.new(store, message_queue) - executor.instance_variable_get(:@index).index_single(File.expand_path( - "../../lib/ruby_lsp/event_emitter.rb", - __dir__, - )) + executor.instance_variable_get(:@index).index_single( + RubyIndexer::Indexable.new( + nil, + File.expand_path( + "../../lib/ruby_lsp/event_emitter.rb", + __dir__, + ), + ), + ) begin # We need to pretend that Sorbet is not a dependency or else we can't properly test @@ -62,7 +67,12 @@ def test_jumping_to_default_gems RUBY executor = RubyLsp::Executor.new(store, message_queue) - executor.instance_variable_get(:@index).index_single(T.must(uri.to_standardized_path)) + executor.instance_variable_get(:@index).index_single( + RubyIndexer::Indexable.new( + nil, + T.must(uri.to_standardized_path), + ), + ) response = executor.execute({ method: "textDocument/definition", diff --git a/test/requests/hover_expectations_test.rb b/test/requests/hover_expectations_test.rb index 6aba22f8f5..f0bb8f3ccb 100644 --- a/test/requests/hover_expectations_test.rb +++ b/test/requests/hover_expectations_test.rb @@ -17,7 +17,7 @@ def run_expectations(source) executor = RubyLsp::Executor.new(store, message_queue) index = executor.instance_variable_get(:@index) - index.index_single(uri.to_standardized_path, source) + index.index_single(RubyIndexer::Indexable.new(nil, T.must(uri.to_standardized_path)), source) begin # We need to pretend that Sorbet is not a dependency or else we can't properly test @@ -49,7 +49,10 @@ class Post store.set(uri: uri, source: source, version: 1) executor = RubyLsp::Executor.new(store, message_queue) - executor.instance_variable_get(:@index).index_single(uri.to_standardized_path, source) + executor.instance_variable_get(:@index).index_single( + RubyIndexer::Indexable.new(nil, T.must(uri.to_standardized_path)), + source, + ) response = executor.execute({ method: "textDocument/hover", diff --git a/test/requests/workspace_symbol_test.rb b/test/requests/workspace_symbol_test.rb index 90e9c312b3..53ac224eda 100644 --- a/test/requests/workspace_symbol_test.rb +++ b/test/requests/workspace_symbol_test.rb @@ -14,7 +14,7 @@ def teardown end def test_returns_index_entries_based_on_query - @index.index_single("/fake.rb", <<~RUBY) + @index.index_single(RubyIndexer::Indexable.new(nil, "/fake.rb"), <<~RUBY) class Foo; end module Bar; end @@ -35,7 +35,7 @@ module Bar; end end def test_fuzzy_matches_symbols - @index.index_single("/fake.rb", <<~RUBY) + @index.index_single(RubyIndexer::Indexable.new(nil, "/fake.rb"), <<~RUBY) class Foo; end module Bar; end @@ -57,13 +57,17 @@ module Bar; end def test_matches_only_gem_symbols_if_typechecker_is_present RubyLsp::DependencyDetector.const_set(:HAS_TYPECHECKER, true) + indexable = RubyIndexer::Indexable.new( + nil, + "#{RubyLsp::WORKSPACE_URI.to_standardized_path}/workspace_symbol_foo.rb", + ) - @index.index_single("#{RubyLsp::WORKSPACE_URI.to_standardized_path}/workspace_symbol_foo.rb", <<~RUBY) + @index.index_single(indexable, <<~RUBY) class Foo; end RUBY path = "#{Bundler.bundle_path}/gems/fake-gem-0.1.0/lib/gem_symbol_foo.rb" - @index.index_single(path, <<~RUBY) + @index.index_single(RubyIndexer::Indexable.new(nil, path), <<~RUBY) class Foo; end RUBY @@ -73,7 +77,7 @@ class Foo; end end def test_symbols_include_container_name - @index.index_single("/fake.rb", <<~RUBY) + @index.index_single(RubyIndexer::Indexable.new(nil, "/fake.rb"), <<~RUBY) module Foo class Bar; end end @@ -86,7 +90,7 @@ class Bar; end end def test_finds_default_gem_symbols - @index.index_single("#{RbConfig::CONFIG["rubylibdir"]}/pathname.rb") + @index.index_single(RubyIndexer::Indexable.new(nil, "#{RbConfig::CONFIG["rubylibdir"]}/pathname.rb")) result = RubyLsp::Requests::WorkspaceSymbol.new("Pathname", @index).run refute_empty(result)