From 858783116a7e21d374dbf73bec39dba6c510ff73 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 30 Dec 2022 23:51:14 -0500 Subject: [PATCH] Propagate Ruff's autofix messages (#48) --- ruff_lsp/server.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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(