From 0a1d9fd5940371db20745649c46bfe02dfded347 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Thu, 14 Sep 2023 08:48:20 -0400 Subject: [PATCH] Account for private constants in workspace symbol --- lib/ruby_lsp/requests/workspace_symbol.rb | 3 +++ test/requests/workspace_symbol_test.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/ruby_lsp/requests/workspace_symbol.rb b/lib/ruby_lsp/requests/workspace_symbol.rb index 8b3822a3fc..10505f8dd3 100644 --- a/lib/ruby_lsp/requests/workspace_symbol.rb +++ b/lib/ruby_lsp/requests/workspace_symbol.rb @@ -45,6 +45,9 @@ def run next end + # We should never show private symbols when searching the entire workspace + next if entry.visibility == :private + kind = kind_for_entry(entry) loc = entry.location diff --git a/test/requests/workspace_symbol_test.rb b/test/requests/workspace_symbol_test.rb index 818e130f8f..cf5d8e07a4 100644 --- a/test/requests/workspace_symbol_test.rb +++ b/test/requests/workspace_symbol_test.rb @@ -95,4 +95,17 @@ def test_finds_default_gem_symbols result = RubyLsp::Requests::WorkspaceSymbol.new("Pathname", @index).run refute_empty(result) end + + def test_does_not_include_private_constants + @index.index_single(RubyIndexer::IndexablePath.new(nil, "/fake.rb"), <<~RUBY) + class Foo + CONSTANT = 1 + private_constant(:CONSTANT) + end + RUBY + + result = RubyLsp::Requests::WorkspaceSymbol.new("Foo::CONSTANT", @index).run + assert_equal(1, result.length) + assert_equal("Foo", T.must(result.first).name) + end end