Skip to content

Commit

Permalink
Enhancement - Move node range caluclation out of loop in completion l…
Browse files Browse the repository at this point in the history
…istener (#2952)

moved range caluclation out of loop in completion listener
  • Loading branch information
rogancodes authored Dec 4, 2024
1 parent bbc1ccb commit 4a2c7cd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/ruby_lsp/listeners/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down Expand Up @@ -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

Expand All @@ -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,
Expand Down

0 comments on commit 4a2c7cd

Please sign in to comment.