Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/ruby_indexer/lib/ruby_indexer/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,15 @@ def constant_completion_candidates(name, nesting)

# Top level constants
entries.concat(@entries_tree.search(name))

# Filter only constants since methods may have names that look like constants
entries.each do |definitions|
definitions.select! do |entry|
entry.is_a?(Entry::Constant) || entry.is_a?(Entry::ConstantAlias) ||
entry.is_a?(Entry::Namespace) || entry.is_a?(Entry::UnresolvedConstantAlias)
end
end

entries.uniq!
entries #: as Array[Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry::UnresolvedConstantAlias]]
end
Expand Down
12 changes: 12 additions & 0 deletions lib/ruby_indexer/test/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,18 @@ class Baz
assert_equal(["XQRK"], result.map { |entries| entries.first&.name })
end

def test_constant_completion_does_not_confuse_uppercase_methods
index(<<~RUBY)
class Foo
def Qux
end
end
RUBY

candidates = @index.constant_completion_candidates("Q", [])
refute_includes(candidates.flat_map { |entries| entries.map(&:name) }, "Qux")
end

def test_constant_completion_candidates_for_empty_name
index(<<~RUBY)
module Foo
Expand Down