Repository: Shopify/ruby-lsp-rails (Ruby)

Issue:
"Jump to view" includes folders as well
### Description

### Ruby LSP Information


### Ruby LSP Information

#### VS Code Version

1.93.1

#### Ruby LSP Extension Version

0.8.1

#### Ruby LSP Server Version

0.18.3

#### Ruby LSP Addons

- Ruby LSP Rails

#### Ruby Version

3.2.5

#### Ruby Version Manager

rbenv

#### Installed Extensions

<details>
<summary>Click to expand</summary>

- copilot (1.233.0)
- copilot-chat (0.20.3)
- haml (1.4.1)
- rainbow-csv (3.12.0)
- ruby-lsp (0.8.1)
</details>

#### Ruby LSP Settings

<details>
<summary>Click to expand</summary>

##### Workspace

```json
{}
```

##### User

```json
{
  "enableExperimentalFeatures": false,
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": false,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": false,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": false,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "auto"
  },
  "customRubyCommand": "",
  "formatter": "auto",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true
}
```

</details>

### Reproduction steps

1. Start the Ruby LSP using VS Code
2. Open a Rails controller file (e.g. `posts`). Choose an action (e.g. `show`) which has a "Jump to View" option.
3. If `views/posts/` has a `show` directory inside it, it will be offered as a possible view, even though it's a folder.

Folders should be skipped when collecting possible views of a Rails action.


Discussion:
Thanks, https://github.com/Shopify/ruby-lsp-rails/pull/464 should solve this.



Patch:
diff --git a/lib/ruby_lsp/ruby_lsp_rails/code_lens.rb b/lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
index 51866b2c..3a7371b0 100644
--- a/lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
+++ b/lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
@@ -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(


Test patch:
diff --git a/test/dummy/app/views/users/index/.keep b/test/dummy/app/views/users/index/.keep
new file mode 100644
index 00000000..e69de29b
diff --git a/test/ruby_lsp_rails/code_lens_test.rb b/test/ruby_lsp_rails/code_lens_test.rb
index 0b6aa358..769dfb53 100644
--- a/test/ruby_lsp_rails/code_lens_test.rb
+++ b/test/ruby_lsp_rails/code_lens_test.rb
@@ -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,