diff --git a/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb b/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb index bb30ff340..b8457aff9 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb @@ -138,10 +138,11 @@ def initialize(key, value, parent = nil) #: -> Array[Value] def collect result = [] - result << @value if @leaf + stack = [self] - @children.each_value do |node| - result.concat(node.collect) + while (node = stack.pop) + result.prepend(node.value) if node.leaf + stack.concat(node.children.values) end result diff --git a/lib/ruby_indexer/test/index_test.rb b/lib/ruby_indexer/test/index_test.rb index 8bb6713d0..cbf25d414 100644 --- a/lib/ruby_indexer/test/index_test.rb +++ b/lib/ruby_indexer/test/index_test.rb @@ -1893,7 +1893,7 @@ class Foo assert_equal("==", method.name) candidates = @index.method_completion_candidates("=", "Foo") - assert_equal(["==", "==="], candidates.map(&:name)) + assert_equal(["===", "=="], candidates.map(&:name)) end def test_entries_for diff --git a/lib/ruby_indexer/test/prefix_tree_test.rb b/lib/ruby_indexer/test/prefix_tree_test.rb index 9f3286f6f..95e453bad 100644 --- a/lib/ruby_indexer/test/prefix_tree_test.rb +++ b/lib/ruby_indexer/test/prefix_tree_test.rb @@ -37,9 +37,9 @@ def test_multiple_prefixes tree = PrefixTree[String].new ["fo", "foo"].each { |item| tree.insert(item, item) } - assert_equal(["fo", "foo"], tree.search("")) - assert_equal(["fo", "foo"], tree.search("f")) - assert_equal(["fo", "foo"], tree.search("fo")) + assert_equal(["foo", "fo"], tree.search("")) + assert_equal(["foo", "fo"], tree.search("f")) + assert_equal(["foo", "fo"], tree.search("fo")) assert_equal(["foo"], tree.search("foo")) assert_empty(tree.search("fooo")) end @@ -84,8 +84,8 @@ def test_multiple_prefixes_with_shuffled_order "foo/bar/support/semantic", "foo/bar/support/syntax", "foo/bar/support/source", - "foo/bar/support/runner", "foo/bar/support/runner2", + "foo/bar/support/runner", "foo/bar/support/rails", "foo/bar/support/diagnostic", "foo/bar/support/highlight", diff --git a/test/requests/completion_test.rb b/test/requests/completion_test.rb index fac94acdc..b5fbd2230 100644 --- a/test/requests/completion_test.rb +++ b/test/requests/completion_test.rb @@ -203,7 +203,7 @@ class Baz position: { line: 5, character: 9 }, }) result = server.pop_response.response - assert_equal(["Foo::Bar", "Foo::Bar::Baz"], result.map(&:label)) + assert_equal(["Foo::Bar::Baz", "Foo::Bar"], result.map(&:label)) end end end @@ -695,9 +695,9 @@ def bar }) result = server.pop_response.response - assert_equal(["qux", "qux="], result.map(&:label)) - assert_equal(["qux", "qux="], result.map(&:filter_text)) - assert_equal(["qux", "qux="], result.map { |completion| completion.text_edit.new_text }) + assert_equal(["qux=", "qux"], result.map(&:label)) + assert_equal(["qux=", "qux"], result.map(&:filter_text)) + assert_equal(["qux=", "qux"], result.map { |completion| completion.text_edit.new_text }) end end end @@ -1112,7 +1112,7 @@ def baz }) result = server.pop_response.response - assert_equal(["@@foo", "@@foobar"], result.map(&:label)) + assert_equal(["@@foobar", "@@foo"], result.map(&:label)) assert_equal(["fake.rb", "fake.rb"], result.map { _1.label_details.description }) end end @@ -1138,7 +1138,7 @@ def bar }) result = server.pop_response.response - assert_equal(["@@foo", "@@foobar"], result.map(&:label)) + assert_equal(["@@foobar", "@@foo"], result.map(&:label)) end end @@ -1267,14 +1267,14 @@ def baz position: { line: 7, character: 5 }, }) result = server.pop_response.response - assert_equal(["@foo", "@foobar"], result.map(&:label)) + assert_equal(["@foobar", "@foo"], result.map(&:label)) server.process_message(id: 1, method: "textDocument/completion", params: { textDocument: { uri: uri }, position: { line: 11, character: 5 }, }) result = server.pop_response.response - assert_equal(["@foo", "@foobar"], result.map(&:label)) + assert_equal(["@foobar", "@foo"], result.map(&:label)) assert_equal(["fake.rb", "fake.rb"], result.map { _1.label_details.description }) end end