diff --git a/requirements-dev.txt b/requirements-dev.txt index 3d73da3..2620eed 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -28,13 +28,13 @@ mypy-extensions==0.4.3 # mypy pathspec==0.10.3 # via black -platformdirs==2.6.0 +platformdirs==2.6.2 # via black pygls==1.0.0 # via ruff-lsp (pyproject.toml) python-lsp-jsonrpc==1.0.0 # via ruff-lsp (pyproject.toml) -ruff==0.0.194 +ruff==0.0.203 # via ruff-lsp (pyproject.toml) tomli==2.0.1 # via @@ -52,6 +52,7 @@ typing-extensions==4.4.0 # cattrs # importlib-metadata # mypy + # platformdirs # ruff-lsp (pyproject.toml) ujson==5.6.0 # via python-lsp-jsonrpc diff --git a/requirements.txt b/requirements.txt index bbb0163..19f1d90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,7 @@ lsprotocol==2022.0.0a9 # via pygls pygls==1.0.0 # via ruff-lsp (pyproject.toml) -ruff==0.0.194 +ruff==0.0.203 # via ruff-lsp (pyproject.toml) typeguard==2.13.3 # via pygls diff --git a/ruff_lsp/server.py b/ruff_lsp/server.py index 6837314..cc8478e 100755 --- a/ruff_lsp/server.py +++ b/ruff_lsp/server.py @@ -236,6 +236,7 @@ class Location(TypedDict): class Fix(TypedDict): content: str + message: str | None location: Location end_location: Location @@ -388,13 +389,19 @@ def code_action(params: CodeActionParams) -> list[CodeAction] | None: for diagnostic in params.context.diagnostics: if diagnostic.source == "Ruff": if diagnostic.data is not None: + fix = cast(Fix, diagnostic.data) + + title: str + if fix.get("message"): + title = f"Ruff: {fix['message']}" + elif diagnostic.code: + title = f"Ruff: Fix {diagnostic.code}" + else: + title = "Ruff: Autofix" + actions.append( CodeAction( - title=( - f"Ruff: Fix {diagnostic.code}" - if diagnostic.code - else "Ruff: Fix" - ), + title=title, kind=CodeActionKind.QuickFix, data=params.text_document.uri, edit=_create_workspace_edit( diff --git a/ruff_lsp/utils.py b/ruff_lsp/utils.py index 72c7e5b..334d43d 100644 --- a/ruff_lsp/utils.py +++ b/ruff_lsp/utils.py @@ -86,8 +86,7 @@ def run_path( result = subprocess.run( argv, encoding="utf-8", - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + capture_output=True, check=False, cwd=cwd, )