Skip to content

Commit

Permalink
Prevent relative require completion from failing on permissions (#3151)
Browse files Browse the repository at this point in the history
### Motivation

We have some cases in our telemetry where the user typed in a relative require pointing to a directory that the editor doesn't have permission to read.

This will cause an `Errno::EPERM` and currently makes completion crash.

### Implementation

Started rescuing the error. If we can't read the directory, we can't list files.

### Automated Tests

I tried writing a test for this, but for some reason removing all permissions with `FileUtils.chmod` doesn't reproduce. Glob just returns an empty array instead.

Not sure if the behaviour is platform specific, but rather than spending a disproportionate amount of effort writing this one test, I think it's safe to just rescue.
  • Loading branch information
vinistock committed Feb 7, 2025
1 parent 37eb419 commit 1a38cbc
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ruby_lsp/listeners/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ def complete_require_relative(node)
path_node_to_complete,
)
end
rescue Errno::EPERM
# If the user writes a relative require pointing to a path that the editor has no permissions to read, then glob
# might fail with EPERM
end

sig { params(node: Prism::CallNode, name: String).void }
Expand Down

0 comments on commit 1a38cbc

Please sign in to comment.