Skip to content

Commit

Permalink
fix: avoid duplicated completions names
Browse files Browse the repository at this point in the history
  • Loading branch information
snutij committed Oct 21, 2024
1 parent 3b4fb4b commit e46ce5f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ruby_lsp/listeners/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def handle_global_variable_completion(name, location)

range = range_from_location(location)

candidates.flatten.each do |entry|
candidates.flatten.uniq(&:name).each do |entry|
entry_name = entry.name

@response_builder << Interface::CompletionItem.new(
Expand Down
22 changes: 22 additions & 0 deletions test/requests/completion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,28 @@ def test_completion_for_global_variables
end
end

def test_completion_for_global_variables_show_only_uniq_entries
source = <<~RUBY
$qar &&= 1
$qar += 1
$qar ||= 1
$q
RUBY

with_server(source) do |server, uri|
index = server.instance_variable_get(:@global_state).index
RubyIndexer::RBSIndexer.new(index).index_ruby_core

server.process_message(id: 1, method: "textDocument/completion", params: {
textDocument: { uri: uri },
position: { line: 3, character: 2 },
})

result = server.pop_response.response
assert_equal(["$qar"], result.map(&:label))
end
end

def test_completion_for_instance_variables
source = +<<~RUBY
class Foo
Expand Down

0 comments on commit e46ce5f

Please sign in to comment.