Skip to content

Skip directories for view paths #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,13 @@ def add_jump_to_view(node)
.gsub("::", "/")
.downcase

view_uris = Dir.glob("#{@client.rails_root}/app/views/#{controller_name}/#{action_name}*").map! do |path|
view_uris = Dir.glob("#{@client.rails_root}/app/views/#{controller_name}/#{action_name}*").filter_map do |path|
# it's possible we could have a directory with the same name as the action, so we need to skip those
next if File.directory?(path)

URI::Generic.from_path(path: path).to_s
end

return if view_uris.empty?

@response_builder << create_code_lens(
Expand Down
Empty file.
1 change: 1 addition & 0 deletions test/ruby_lsp_rails/code_lens_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def index
view_lens = response[1]

assert_equal("Jump to view", view_lens.command.title)
# NOTE: The `views/users` directory contains a directory named `index` which should not be returned.
assert_equal(
[[
URI::Generic.from_path(path: "#{dummy_root}/app/views/users/index.html.erb").to_s,
Expand Down
Loading