Skip to content

Conversation

cpgo
Copy link

@cpgo cpgo commented Aug 16, 2025

Working on a project that has lots of indexes created via raw sql, for example

execute "CREATE UNIQUE INDEX users_unique_complex ON users (COALESCE(country_id, 0), ltrim(first_name));"

I saw this exception on the lsp logs

/home/user/.asdf/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/ruby-lsp-rails-0.4.8/lib/ruby_lsp/ruby_lsp_rails/hover.rb:100:in 'block in RubyLsp::Rails::Hover#generate_column_content': undefined method 'join' for an instance of String (NoMethodError)

              "- **#{index[:name]}** (#{index[:columns].join(",")})#{uniqueness}"
                                                       ^^^^^

This pr attempts to handle that exception but I'm not familiar with the whole project structure so maybe the issue should be fixed somewhere upstream?

@cpgo cpgo requested a review from a team as a code owner August 16, 2025 14:26
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! Just left a comment trying to understand all of the scenarios involved here

Comment on lines +100 to +108
columns = case index[:columns]
when Array
index[:columns].join(",")
when String
index[:columns]
else
index[:name]
end
"- **#{index[:name]}** (#{columns})#{uniqueness}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to understand the different scenarios here. Array is the case when we have multiple columns associated to the index.

When is it a string? And when would it not be either (when do we reach the else block)?

In the case of the else block, we're essentially showing the index's name twice on the hover, which may not be super useful. Is there any other information for that scenario that we could show?

Copy link
Author

@cpgo cpgo Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the else case is not really necessary, I just added because I'm not super familiar with the possible values here.

When is it a string?

I noticed on one of my applications when indexes contained "complex" sql processing like

execute "CREATE UNIQUE INDEX users_unique_complex ON users (COALESCE(country_id, 0), ltrim(first_name));"

In those cases .join was called on the whole index expression CREATE UNIQUE INDEX... instead of the array of columns

@vinistock vinistock added the bugfix This PR fixes an existing bug label Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR fixes an existing bug cla-needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants