diff --git a/lib/ruby_lsp/listeners/completion.rb b/lib/ruby_lsp/listeners/completion.rb index da976619d..30e3c7126 100644 --- a/lib/ruby_lsp/listeners/completion.rb +++ b/lib/ruby_lsp/listeners/completion.rb @@ -110,13 +110,14 @@ def on_constant_read_node_enter(node) name = constant_name(node) return if name.nil? + range = range_from_location(node.location) candidates = @index.constant_completion_candidates(name, @node_context.nesting) candidates.each do |entries| complete_name = T.must(entries.first).name @response_builder << build_entry_completion( complete_name, name, - range_from_location(node.location), + range, entries, top_level?(complete_name), ) @@ -335,6 +336,7 @@ def handle_instance_variable_completion(name, location) type = @type_inferrer.infer_receiver_type(@node_context) return unless type + range = range_from_location(location) @index.instance_variable_completion_candidates(name, type.name).each do |entry| variable_name = entry.name @@ -346,7 +348,7 @@ def handle_instance_variable_completion(name, location) label: variable_name, label_details: label_details, text_edit: Interface::TextEdit.new( - range: range_from_location(location), + range: range, new_text: variable_name, ), kind: Constant::CompletionItemKind::FIELD,