Skip to content

Commit

Permalink
rename method for indexing arguments of call node
Browse files Browse the repository at this point in the history
  • Loading branch information
ChallaHalla committed Dec 12, 2024
1 parent 62284ef commit 7077b8b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/ruby_lsp/ruby_lsp_rails/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ def handle_active_record_where_completions(node)
return if resolved_class.nil?

arguments = T.must(@node_context.call_node).arguments&.arguments
existing_args = T.let({}, T::Hash[String, T::Boolean])
indexed_call_node_args = T.let({}, T::Hash[String, Prism::Node])

if arguments&.is_a?(Array)
existing_args = get_call_node_arguments(arguments: arguments)
return if existing_args.values.any? { |v| v == node }
indexed_call_node_args = index_call_node_args(arguments: arguments)
binding.irb
return if indexed_call_node_args.values.any? { |v| v == node }
end

resolved_class[:columns].each do |column|
next unless column[0].start_with?(node.name.to_s)
next if existing_args.key?(column[0])
next if indexed_call_node_args.key?(column[0])

@response_builder << Interface::CompletionItem.new(
label: column[0],
Expand All @@ -68,9 +69,9 @@ def handle_active_record_where_completions(node)
end
end

sig { params(arguments: T::Array[Prism::Node]).returns(T::Hash[String, T::Boolean]) }
def get_call_node_arguments(arguments:)
existing_args = {}
sig { params(arguments: T::Array[Prism::Node]).returns(T::Hash[String, Prism::Node]) }
def index_call_node_args(arguments:)
indexed_call_node_args = {}
arguments.each do |argument|
next unless argument.is_a?(Prism::KeywordHashNode)

Expand All @@ -79,11 +80,11 @@ def get_call_node_arguments(arguments:)

key = e.key
if key.is_a?(Prism::SymbolNode)
existing_args[key.value] = e.value
indexed_call_node_args[key.value] = e.value
end
end
end
existing_args
indexed_call_node_args
end
end
end
Expand Down

0 comments on commit 7077b8b

Please sign in to comment.