Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate Ruff's autofix messages #48

Merged
merged 1 commit into from
Dec 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class Location(TypedDict):

class Fix(TypedDict):
content: str
message: str | None
location: Location
end_location: Location

Expand Down Expand Up @@ -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(
Expand Down