Skip to content
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

Better notification when used Ruff not compatible to extension. #476

Closed
T-256 opened this issue May 23, 2024 · 2 comments · Fixed by #512
Closed

Better notification when used Ruff not compatible to extension. #476

T-256 opened this issue May 23, 2024 · 2 comments · Fixed by #512
Assignees
Labels

Comments

@T-256
Copy link

T-256 commented May 23, 2024

Notifications on using Ruff v0.3.0 with ruff.nativeServer settings enabled:

image

Output

2024-05-23 13:26:39.572 [info] Server: Stop requested
2024-05-23 13:26:39.585 [info] Server run command: c:\Users\User\Desktop\test\.venv\Scripts\python.exe c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py server --preview
2024-05-23 13:26:39.585 [info] Server: Start requested.
2024-05-23 13:26:39.591 [info] 2024-05-23 13:26:39,580 INFO Shutting down the server
2024-05-23 13:26:39,580 INFO Closing the event loop.

2024-05-23 13:26:39.759 [info] Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 90, in <module>
    check_compatibility(ruff, RUFF_VERSION_REQUIREMENT)
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 55, in check_compatibility
    raise RuntimeError(message)
RuntimeError: Ruff >=0.3.5 required, but found 0.3.0 at C:\Users\User\.rye\shims\ruff.EXE

2024-05-23 13:26:39.767 [info] [Error - 1:26:39 PM] Server initialization failed.
2024-05-23 13:26:39.767 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:39.767 [info] [Info  - 1:26:39 PM] Connection to server got closed. Server will restart.
2024-05-23 13:26:39.767 [info] true
2024-05-23 13:26:39.768 [info] [Error - 1:26:39 PM] Ruff client: couldn't create connection to server.
2024-05-23 13:26:39.768 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:39.914 [info] Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 90, in <module>
    check_compatibility(ruff, RUFF_VERSION_REQUIREMENT)
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 55, in check_compatibility
    raise RuntimeError(message)
RuntimeError: Ruff >=0.3.5 required, but found 0.3.0 at C:\Users\User\.rye\shims\ruff.EXE

2024-05-23 13:26:39.923 [info] [Error - 1:26:39 PM] Server initialization failed.
2024-05-23 13:26:39.923 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:39.923 [info] [Info  - 1:26:39 PM] Connection to server got closed. Server will restart.
2024-05-23 13:26:39.923 [info] true
2024-05-23 13:26:39.923 [info] [Error - 1:26:39 PM] Ruff client: couldn't create connection to server.
2024-05-23 13:26:39.924 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:39.924 [error] Server: Start failed: Error: Pending response rejected since connection got disposed
2024-05-23 13:26:40.061 [info] Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 90, in <module>
    check_compatibility(ruff, RUFF_VERSION_REQUIREMENT)
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 55, in check_compatibility
    raise RuntimeError(message)
RuntimeError: Ruff >=0.3.5 required, but found 0.3.0 at C:\Users\User\.rye\shims\ruff.EXE

2024-05-23 13:26:40.069 [info] [Error - 1:26:40 PM] Server initialization failed.
2024-05-23 13:26:40.069 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.069 [info] [Info  - 1:26:40 PM] Connection to server got closed. Server will restart.
2024-05-23 13:26:40.069 [info] true
2024-05-23 13:26:40.069 [info] [Error - 1:26:40 PM] Ruff client: couldn't create connection to server.
2024-05-23 13:26:40.069 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.069 [info] [Error - 1:26:40 PM] Restarting server failed
2024-05-23 13:26:40.069 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.212 [info] Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 90, in <module>
    check_compatibility(ruff, RUFF_VERSION_REQUIREMENT)
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 55, in check_compatibility
    raise RuntimeError(message)
RuntimeError: Ruff >=0.3.5 required, but found 0.3.0 at C:\Users\User\.rye\shims\ruff.EXE

2024-05-23 13:26:40.220 [info] [Error - 1:26:40 PM] Server initialization failed.
2024-05-23 13:26:40.220 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.220 [info] [Info  - 1:26:40 PM] Connection to server got closed. Server will restart.
2024-05-23 13:26:40.220 [info] true
2024-05-23 13:26:40.220 [info] [Error - 1:26:40 PM] Ruff client: couldn't create connection to server.
2024-05-23 13:26:40.220 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.221 [info] [Error - 1:26:40 PM] Restarting server failed
2024-05-23 13:26:40.221 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.360 [info] Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 90, in <module>
    check_compatibility(ruff, RUFF_VERSION_REQUIREMENT)
  File "c:\Users\User\.vscode\extensions\charliermarsh.ruff-2024.22.0-win32-x64\bundled\tool\ruff_server.py", line 55, in check_compatibility
    raise RuntimeError(message)
RuntimeError: Ruff >=0.3.5 required, but found 0.3.0 at C:\Users\User\.rye\shims\ruff.EXE

2024-05-23 13:26:40.368 [info] [Error - 1:26:40 PM] Server initialization failed.
2024-05-23 13:26:40.368 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.368 [info] [Error - 1:26:40 PM] The Ruff server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
2024-05-23 13:26:40.368 [info] [Error - 1:26:40 PM] Ruff client: couldn't create connection to server.
2024-05-23 13:26:40.368 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-05-23 13:26:40.369 [info] [Error - 1:26:40 PM] Restarting server failed
2024-05-23 13:26:40.369 [info]   Message: Pending response rejected since connection got disposed
  Code: -32097 
@T-256
Copy link
Author

T-256 commented May 24, 2024

Also related to #323. I expected to get Ruff is too old notification at here.

@dhruvmanila
Copy link
Member

Thank you for the feedback! I agree and in general we should look at the messages sent to the UI to improve the user experience.

@snowsignal snowsignal self-assigned this Jun 17, 2024
@dhruvmanila dhruvmanila assigned dhruvmanila and unassigned snowsignal Jul 3, 2024
dhruvmanila added a commit that referenced this issue Jul 4, 2024
## Summary

This PR makes progress towards #476 and #479 by making the following
changes:
* Update the `ruff_server.py` script to limit itself to just getting the
Ruff binary path using `sysconfig`
* Use the `which` dependency and move the logic of locating the Ruff
binary from `PATH` to TypeScript
* Add log messages similar to `ruff-lsp`

## Test Plan

### 1

```json
{
  "ruff.nativeServer": true
}
```
Or
```json
{
  "ruff.nativeServer": true,
  "ruff.importStrategy": "fromEnvironment"
}
```

Logs:

When the `ruff` binary is installed in the current virtual environment:
```
2024-07-03 15:28:35.674 [info] Using the Ruff binary: /Users/dhruv/work/astral/ruff-vscode/.venv/bin/ruff
2024-07-03 15:28:35.675 [info] Server run command: /Users/dhruv/work/astral/ruff-vscode/.venv/bin/ruff server --preview
```

If there's no `ruff` binary in the current virtual environment:
```
2024-07-03 15:25:19.605 [info] Using the Ruff binary: /Users/dhruv/.local/bin/ruff
2024-07-03 15:25:19.606 [info] Server run command: /Users/dhruv/.local/bin/ruff server --preview
```

If the `ruff` binary is only available via `PATH`:
```
2024-07-03 15:32:12.172 [info] Using environment executable: /opt/homebrew/bin/ruff
2024-07-03 15:32:12.173 [info] Server run command: /opt/homebrew/bin/ruff server --preview
```

And, if there's no `ruff` binary anywhere on the system, use the bundled
binary:
```
2024-07-03 15:29:47.948 [info] Falling back to bundled executable: /Users/dhruv/work/astral/ruff-vscode/bundled/libs/bin/ruff
2024-07-03 15:29:47.948 [info] Server run command: /Users/dhruv/work/astral/ruff-vscode/bundled/libs/bin/ruff server --preview
```

### 2

```json
{
  "ruff.nativeServer": true,
  "ruff.importStrategy": "useBundled"
}
```

Logs:
```
2024-07-03 15:26:28.767 [info] Using bundled executable: /Users/dhruv/work/astral/ruff-vscode/bundled/libs/bin/ruff
2024-07-03 15:26:28.767 [info] Server run command: /Users/dhruv/work/astral/ruff-vscode/bundled/libs/bin/ruff server --preview
```

### 3

```json
{
  "ruff.nativeServer": true,
  "ruff.path": ["/Users/dhruv/work/astral/ruff/target/debug/ruff"]
}
```

Logs:
```
2024-07-03 15:27:42.342 [info] Using 'path' setting: /Users/dhruv/work/astral/ruff/target/debug/ruff
2024-07-03 15:27:42.342 [info] Server run command: /Users/dhruv/work/astral/ruff/target/debug/ruff server --preview
```

### 4

```json
{
  "ruff.nativeServer": true,
  "ruff.interpreter": [
    "/Users/dhruv/work/astral/ruff-lsp/.venv/bin/python"
  ]
}
```

Logs:
```
2024-07-03 15:35:23.578 [info] Using the Ruff binary: /Users/dhruv/work/astral/ruff-lsp/.venv/bin/ruff
2024-07-03 15:35:23.578 [info] Server run command: /Users/dhruv/work/astral/ruff-lsp/.venv/bin/ruff server --preview
```

### 5

What if the script failed? I modified the script path in TypeScript code
and we get the following logs:

```
2024-07-03 15:42:41.035 [error] Error while trying to find the Ruff binary: Error: Command failed: /Users/dhruv/work/astral/ruff-lsp/.venv/bin/python /Users/dhruv/work/astral/ruff-vscode/bundled/tool/find_ruff_binary_pat.py
/Users/dhruv/work/astral/ruff-lsp/.venv/bin/python: can't open file '/Users/dhruv/work/astral/ruff-vscode/bundled/tool/find_ruff_binary_pat.py': [Errno 2] No such file or directory

2024-07-03 15:42:41.037 [info] Using environment executable: /Users/dhruv/.local/bin/ruff
2024-07-03 15:42:41.040 [info] Server run command: /Users/dhruv/.local/bin/ruff server --preview
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants