ruff-vscode
Use `ruff.interpreter` from workspace settings
#553
Merged

Use `ruff.interpreter` from workspace settings #553

dhruvmanila merged 1 commit into main from dhruv/interpreter
dhruvmanila
dhruvmanila306 days ago (edited 305 days ago)

Summary

This PR updates the scope of ruff.interpreter setting from window to resource in order to resolve the variables such as ${workspaceFolder} if present.

In #551, what happens is that the Python extension fails to resolve the environment corresponding to that interpreter which causes the hang. The bug present in #551 was there for a very long time but it got visible because of e665ec7. Before that commit, the extension would just move ahead and use the interpreter from the Python extension but now we explicitly stop moving ahead if it fails to resolve the environment corresponding to the interpreter.

For reference, the vscode-black-formatter extension also updated the scope of ruff.interpreter to be resource in microsoft/vscode-black-formatter@5f2fc61.

fixes: #551

Test Plan

Relative paths are unresolved

{
  "ruff.importStrategy": "fromEnvironment",
  "ruff.interpreter": [".venv/bin/python"]
}

Logs:

2024-07-24 08:50:37.182 [info] Using interpreter: .venv/bin/python
2024-07-24 08:50:39.240 [error] Unable to find any Python environment for the interpreter path: .venv/bin/python

Preview for the status bar:

Screenshot 2024-07-24 at 08 51 15

Using VS Code specific variables

{
  "ruff.importStrategy": "fromEnvironment",
  "ruff.interpreter": ["${workspaceFolder}/.venv/bin/python"]
}

Logs:

2024-07-24 08:51:43.272 [info] Using interpreter: /Users/dhruv/playground/ruff/.venv/bin/python
2024-07-24 08:51:43.306 [info] Using the Ruff binary: /Users/dhruv/playground/ruff/.venv/bin/ruff
2024-07-24 08:51:43.310 [info] Resolved 'ruff.nativeServer: auto' to use the native server
2024-07-24 08:51:43.313 [info] Found Ruff 0.5.4 at /Users/dhruv/playground/ruff/.venv/bin/ruff
2024-07-24 08:51:43.313 [info] Server run command: /Users/dhruv/playground/ruff/.venv/bin/ruff server
2024-07-24 08:51:43.313 [info] Server: Start requested.
dhruvmanila dhruvmanila force pushed from 56a098c5 to 6b70a822 305 days ago
dhruvmanila dhruvmanila force pushed from 6b70a822 to 78dd0ae2 305 days ago
dhruvmanila
dhruvmanila commented on 2024-07-24
src/extension.ts
263266 traceLog(`Python extension loading`);
264267
await initializePython(context.subscriptions);
265268
traceLog(`Python extension loaded`);
dhruvmanila305 days ago (edited 305 days ago)

This was a bug that would hang the extension when ruff.interpreter is provided and the workspace is trusted. We would never call the runServer in that case.

dhruvmanila dhruvmanila force pushed from 78dd0ae2 to 7e25f698 305 days ago
dhruvmanila dhruvmanila force pushed from 7e25f698 to dec965c3 305 days ago
dhruvmanila dhruvmanila marked this pull request as ready for review 305 days ago
dhruvmanila dhruvmanila requested a review from charliermarsh charliermarsh 305 days ago
charliermarsh
charliermarsh approved these changes on 2024-07-24
charliermarsh
charliermarsh305 days ago

Before that commit, the extension would just move ahead and use the interpreter from the Python extension but now we explicitly stop moving ahead if it fails to resolve the environment corresponding to the interpreter.

Do we need to fall back to the interpreter from the Python extension?

dhruvmanila
dhruvmanila305 days ago (edited 305 days ago)

Do we need to fall back to the interpreter from the Python extension?

We do fall back to that, it's just moved to settings.ts when we get the workspace settings: https://github.com/astral-sh/ruff-vscode/pull/553/files#diff-3a5b47a3d2e56af22ee3eeb11a7ac02b69ac7b6bf52f9b48a870acd00da9f39a (getInterpreterDetails)

Base automatically changed from dhruv/reduce-api to main 305 days ago
dhruvmanila Use `ruff.interpreter` from workspace settings
15550577
dhruvmanila dhruvmanila force pushed from dec965c3 to 15550577 305 days ago
dhruvmanila dhruvmanila merged c089b5a0 into main 305 days ago
dhruvmanila dhruvmanila deleted the dhruv/interpreter branch 305 days ago

Login to write a write a comment.

Login via GitHub

Reviewers
Assignees
No one assigned
Labels
Milestone