Skip to content

Commit

Permalink
Account for private constants in workspace symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Sep 15, 2023
1 parent 1b8672b commit 0a1d9fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ruby_lsp/requests/workspace_symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions test/requests/workspace_symbol_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0a1d9fd

Please sign in to comment.