8000 fixes #31. · kstrauser/python-lsp-ruff@072b23e · GitHub
[go: up one dir, main page]

Skip to content

Commit 072b23e

Browse files
committed
Creates "disable for this line" code actions for all ruff-related errors.
1 parent d1c229a commit 072b23e

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

pylsp_ruff/plugin.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -193,26 +193,25 @@ def pylsp_code_actions(
193193

194194
_context = converter.structure(context, CodeActionContext)
195195
diagnostics = _context.diagnostics
196-
diagnostics_with_fixes = [d for d in diagnostics if d.data]
197196

198197
code_actions = []
199198
has_organize_imports = False
200199

201-
for diagnostic in diagnostics_with_fixes:
202-
fix = converter.structure(diagnostic.data, RuffFix)
203-
204-
if diagnostic.code == "I001":
205-
code_actions.append(
206-
create_organize_imports_code_action(document, diagnostic, fix)
207-
)
208-
has_organize_imports = True
209-
else:
210-
code_actions.extend(
211-
[
200+
for diagnostic in diagnostics:
201+
code_actions.append(create_disable_code_action(document, diagnostic))
202+
203+
if diagnostic.data: # Has fix
204+
fix = converter.structure(diagnostic.data, RuffFix)
205+
206+
if diagnostic.code == "I001":
207+
code_actions.append(
208+
create_organize_imports_code_action(document, diagnostic, fix)
209+
)
210+
has_organize_imports = True
211+
else:
212+
code_actions.append(
212213
create_fix_code_action(document, diagnostic, fix),
213-
create_disable_code_action(document, diagnostic),
214-
]
215-
)
214+
)
216215

217216
checks = run_ruff_check(workspace, document)
218217
checks_with_fixes = [c for c in checks if c.fix]
@@ -222,8 +221,11 @@ def pylsp_code_actions(
222221
check = checks_organize_imports[0]
223222
fix = check.fix # type: ignore
224223
diagnostic = create_diagnostic(check)
225-
code_actions.append(
226-
create_organize_imports_code_action(document, diagnostic, fix),
224+
code_actions.extend(
225+
[
226+
create_organize_imports_code_action(document, diagnostic, fix),
227+
create_disable_code_action(document, diagnostic),
228+
]
227229
)
228230

229231
if checks_with_fixes:

tests/test_code_actions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def f():
5353
codeactions_import = [
5454
"Ruff: Organize imports",
5555
"Ruff: Fix All",
56+
"Ruff (I001): Disable for this line",
5657
]
5758

5859

0 commit comments

Comments
 (0)
0