Skip to content

Commit

Permalink
rubocop linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ChallaHalla committed Dec 11, 2024
1 parent c08b6e0 commit 9e302f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
22 changes: 11 additions & 11 deletions lib/ruby_lsp/ruby_lsp_rails/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def handle_active_record_where_completions(node)
return if resolved_class.nil?

arguments = node.arguments&.arguments
existing_args = T.let({},T::Hash[String, T::Boolean])
existing_args = T.let({}, T::Hash[String, T::Boolean])
if arguments.present?
existing_args = get_call_node_arguments(arguments: arguments)
end
Expand All @@ -69,19 +69,19 @@ def handle_active_record_where_completions(node)
def get_call_node_arguments(arguments:)
existing_args = {}
arguments.each do |argument|
if argument.is_a?(Prism::KeywordHashNode)
argument.elements.each do |e|
if e.is_a?(Prism::AssocNode)
key = e.key
if key.is_a?(Prism::SymbolNode)
id = key.value
existing_args[id] = true
end
next unless argument.is_a?(Prism::KeywordHashNode)

argument.elements.each do |e|
next unless e.is_a?(Prism::AssocNode)

key = e.key
if key.is_a?(Prism::SymbolNode)
id = key.value
existing_args[id] = true
end
end
end
end
existing_args
existing_args
end
end
end
Expand Down
11 changes: 5 additions & 6 deletions test/ruby_lsp_rails/completion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class CompletionTest < ActiveSupport::TestCase
test "Does not suggest column if it already exists within .where as an arg and parantheses are not closed" do
response = generate_completions_for_source(<<~RUBY, { line: 1, character: 28 })
# typed: false
User.where(id:, first_name:,
User.where(id:, first_name:,#{" "}
RUBY

columns = [ "last_name", "age", "created_at", "updated_at", "country_id", "active" ]
columns = ["last_name", "age", "created_at", "updated_at", "country_id", "active"]
assert_equal(columns.size, response.size)

columns.each_with_index do |column, i|
Expand All @@ -51,7 +51,7 @@ class CompletionTest < ActiveSupport::TestCase
User.where(id:, first_name:, )
RUBY

columns = [ "last_name", "age", "created_at", "updated_at", "country_id", "active" ]
columns = ["last_name", "age", "created_at", "updated_at", "country_id", "active"]
assert_equal(columns.size, response.size)

columns.each_with_index do |column, i|
Expand All @@ -61,15 +61,14 @@ class CompletionTest < ActiveSupport::TestCase
end

test "Does not provide suggestions when typing argument values" do
response = generate_completions_for_source(<<~RUBY, { line: 1, character: 14})
response = generate_completions_for_source(<<~RUBY, { line: 1, character: 14 })
# typed: false
User.where(id:
User.where(id:#{" "}
RUBY

assert_equal(0, response.size)
end


private

def generate_completions_for_source(source, position)
Expand Down

0 comments on commit 9e302f7

Please sign in to comment.