From a7af146d4c2efdc30cabdc5f522a4407e03c6aad Mon Sep 17 00:00:00 2001 From: yaegassy Date: Wed, 4 Jan 2023 16:59:30 +0900 Subject: [PATCH] feat: Prefer to use ruff commands installed in the environment --- ruff_lsp/server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ruff_lsp/server.py b/ruff_lsp/server.py index a08f607..fc1e52a 100755 --- a/ruff_lsp/server.py +++ b/ruff_lsp/server.py @@ -8,6 +8,7 @@ import pathlib import platform import re +import shutil import sys import sysconfig from typing import Any, Sequence, cast @@ -727,7 +728,11 @@ def _executable_path(settings: dict[str, Any]) -> str: # If the interpreter is same as the interpreter running this process, get the # script path directly. path = os.path.join(sysconfig.get_path("scripts"), TOOL_MODULE) - if bundle and not os.path.exists(path): + environment_path = shutil.which("ruff") + if environment_path: + log_to_output(f"Using environment executable: {environment_path}") + path = environment_path + elif bundle and not os.path.exists(path): log_to_output( f"Interpreter executable ({path}) not found; " f"falling back to bundled executable: {bundle}"