Skip to content

Commit 8657407

Browse files
authored
Filter constant completion suggestions to only include constants (#3654)
1 parent dba7666 commit 8657407

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/ruby_indexer/lib/ruby_indexer/index.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ def constant_completion_candidates(name, nesting)
291291

292292
# Top level constants
293293
entries.concat(@entries_tree.search(name))
294+
295+
# Filter only constants since methods may have names that look like constants
296+
entries.each do |definitions|
297+
definitions.select! do |entry|
298+
entry.is_a?(Entry::Constant) || entry.is_a?(Entry::ConstantAlias) ||
299+
entry.is_a?(Entry::Namespace) || entry.is_a?(Entry::UnresolvedConstantAlias)
300+
end
301+
end
302+
294303
entries.uniq!
295304
entries #: as Array[Array[Entry::Constant | Entry::ConstantAlias | Entry::Namespace | Entry::UnresolvedConstantAlias]]
296305
end

lib/ruby_indexer/test/index_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,18 @@ class Baz
19831983
assert_equal(["XQRK"], result.map { |entries| entries.first&.name })
19841984
end
19851985

1986+
def test_constant_completion_does_not_confuse_uppercase_methods
1987+
index(<<~RUBY)
1988+
class Foo
1989+
def Qux
1990+
end
1991+
end
1992+
RUBY
1993+
1994+
candidates = @index.constant_completion_candidates("Q", [])
1995+
refute_includes(candidates.flat_map { |entries| entries.map(&:name) }, "Qux")
1996+
end
1997+
19861998
def test_constant_completion_candidates_for_empty_name
19871999
index(<<~RUBY)
19882000
module Foo

0 commit comments

Comments
 (0)