Skip to content

Commit

Permalink
Convert the path LSP setting to a list if it is a string (#402)
Browse files Browse the repository at this point in the history
## Summary

I ran into a subtle issue today where I provided a single string path:
```lua
 require('lspconfig').ruff_lsp.setup {
   init_options = {
     settings = {
     path = '~/.pyenv/shims/ruff',
```

Which would result in the following error: 

```
PermissionError: [Errno 13] Permission denied: '/'
``` 

This is because we loop over the path in variable, but of course in
Python, you can loop over a string and get `/` as the first result

```python
for path in settings["path"]:
```

This change will convert the str to a simple list in case the user
provides a single path rather than a list.

## Test Plan

tested locally
  • Loading branch information
PedramNavid committed Mar 5, 2024
1 parent 9ba7324 commit 6a50696
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,8 @@ def _find_ruff_binary_path(settings: WorkspaceSettings) -> str:

if settings["path"]:
# 'path' setting takes priority over everything.
if isinstance(settings["path"], str):
path = [path]
for path in settings["path"]:
path = os.path.expanduser(os.path.expandvars(path))
if os.path.exists(path):
Expand Down

0 comments on commit 6a50696

Please sign in to comment.