astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
945 stars 45 forks source link

Rewrite `bundled/tool/ruff_server.py` to typescript #479

Open T-256 opened 1 month ago

T-256 commented 1 month ago

IF we could convert this file into typescript, then extension wouldn't need Python installation/activation on target system at all. Currently Ruff extension needs python interpreter to start the server.

_Originally posted by @T-256 in https://github.com/astral-sh/ruff-vscode/pull/443#discussion_r1611696376_

T-256 commented 1 month ago

IMO, then we can also drop ms-python.python dependency since we don't need Python interpreter anymore.

https://github.com/astral-sh/ruff-vscode/blob/da06307c428fe6e8c8dc5e720af6f4e3d9ad2239/src/extension.ts#L161-L164

At there we could use ms-python.python as optional dep instead of mandatory dep.

MichaReiser commented 1 month ago

I'm not sure if removing the ms-python.python dependency is desired in the long term, or at least, not without implementing our own python selector.

I suspect that we'll soon need to call into Python from Ruff to discover the module search paths and possibly more. But we could make ms-python.python an optional dependency.

charliermarsh commented 1 month ago

Note that we have to call into Python if we want broad coverage for all system Pythons. Otherwise, there's no way to (completely) reliably get the path to the scripts directory.

T-256 commented 1 month ago

I'm not sure if removing the ms-python.python dependency is desired in the long term, or at least, not without implementing our own python selector.

I suspect that we'll soon need to call into Python from Ruff to discover the module search paths and possibly more. But we could make ms-python.python an optional dependency.

Exactly, in addition I think, at this point Ruff itself has well defined its config selector (based on Extension settings which then fallbacks to pyproject.toml/ruff.toml either on workspace dir or its parent dir). IIUC, in this extension, Python discovery is mainly used to pass target version of python to ruff. we could rely on project.required-python or tool.ruff.target-version instead.

Otherwise, there's no way to (completely) reliably get the path to the scripts directory.

IIUC, we use scripts directory to find if Ruff binary available locally into that. This is good. What I suggested is to drop ms-python.python as hard dependency. which means if user already installed ms-python.python we can still get scripts directory and when not installed, this extension will lookup on $PATH only.