Skip to content

Commit

Permalink
ADd messages
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Dec 31, 2022
1 parent 7259d0b commit 07c7287
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
5 changes: 3 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
3 changes: 1 addition & 2 deletions ruff_lsp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit 07c7287

Please sign in to comment.