@@ -106,15 +106,15 @@ def pylsp_settings():
106
106
107
107
@hookimpl (hookwrapper = True )
108
108
def pylsp_format_document (workspace : Workspace , document : Document ) -> Generator :
109
- """
110
- Provide formatting through ruff.
109
+ """Provide formatting through ruff.
111
110
112
111
Parameters
113
112
----------
114
113
workspace : pylsp.workspace.Workspace
115
114
Current workspace.
116
115
document : pylsp.workspace.Document
117
116
Document to apply ruff on.
117
+
118
118
"""
119
119
log .debug (f"textDocument/formatting: { document } " )
120
120
outcome = yield
@@ -158,8 +158,7 @@ def pylsp_format_document(workspace: Workspace, document: Document) -> Generator
158
158
159
159
@hookimpl
160
160
def pylsp_lint (workspace : Workspace , document : Document ) -> List [Dict ]:
161
- """
162
- Register ruff as the linter.
161
+ """Register ruff as the linter.
163
162
164
163
Parameters
165
164
----------
@@ -171,6 +170,7 @@ def pylsp_lint(workspace: Workspace, document: Document) -> List[Dict]:
171
170
Returns
172
171
-------
173
172
List of dicts containing the diagnostics.
173
+
174
174
"""
175
175
settings = load_settings (workspace , document .path )
176
176
checks = run_ruff_check (document = document , settings = settings )
@@ -179,8 +179,7 @@ def pylsp_lint(workspace: Workspace, document: Document) -> List[Dict]:
179
179
180
180
181
181
def create_diagnostic (check : RuffCheck , settings : PluginSettings ) -> Diagnostic :
182
- """
183
- Create a LSP diagnostic based on the given RuffCheck object.
182
+ """Create a LSP diagnostic based on the given RuffCheck object.
184
183
185
184
Parameters
186
185
----------
@@ -192,6 +191,7 @@ def create_diagnostic(check: RuffCheck, settings: PluginSettings) -> Diagnostic:
192
191
Returns
193
192
-------
194
193
Diagnostic
194
+
195
195
"""
196
196
# Adapt range to LSP specification (zero-based)
197
197
range = Range (
@@ -248,8 +248,7 @@ def pylsp_code_actions(
248
248
range : Dict ,
249
249
context : Dict ,
250
250
) -> List [Dict ]:
251
- """
252
- Provide code actions through ruff.
251
+ """Provide code actions through ruff.
253
252
254
253
Parameters
255
254
----------
@@ -267,6 +266,7 @@ def pylsp_code_actions(
267
266
Returns
268
267
-------
269
268
List of dicts containing the code actions.
269
+
270
270
"""
271
271
log .debug (f"textDocument/codeAction: { document } { range } { context } " )
272
272
@@ -322,7 +322,7 @@ def pylsp_code_actions(
322
322
]
323
323
)
324
324
325
- if checks_with_fixes :
325
+ if any ([ c . fix . applicability == "safe" for c in checks_with_fixes ]): # type: ignore
326
326
code_actions .append (
327
327
create_fix_all_code_action (document = document , settings = settings ),
328
328
)
@@ -405,7 +405,7 @@ def create_fix_all_code_action(
405
405
document : Document ,
406
406
settings : PluginSettings ,
407
407
) -> CodeAction :
408
- title = "Ruff: Fix All"
408
+ title = "Ruff: Fix All (safe fixes) "
409
409
kind = CodeActionKind .SourceFixAll
410
410
411
411
# No unsafe fixes for 'Fix all', see https://github.com/python-lsp/python-lsp-ruff/issues/55
@@ -487,8 +487,7 @@ def run_ruff(
487
487
fix : bool = False ,
488
488
extra_arguments : Optional [List [str ]] = None ,
489
489
) -> str :
490
- """
491
- Run ruff on the given document and the given arguments.
490
+ """Run ruff on the given document and the given arguments.
492
491
493
492
Parameters
494
493
----------
@@ -509,6 +508,7 @@ def run_ruff(
509
508
Returns
510
509
-------
511
510
String containing the result in json format.
511
+
512
512
"""
513
513
executable = settings .executable
514
514
@@ -545,8 +545,7 @@ def build_check_arguments(
545
545
fix : bool = False ,
546
546
extra_arguments : Optional [List [str ]] = None ,
547
547
) -> List [str ]:
548
- """
549
- Build arguments for ruff check.
548
+ """Build arguments for ruff check.
550
549
551
550
Parameters
552
551
----------
@@ -562,6 +561,7 @@ def build_check_arguments(
562
561
Returns
563
562
-------
564
563
List containing the arguments.
564
+
565
565
"""
566
566
args = []
567
567
# Suppress update announcements
@@ -631,8 +631,7 @@ def build_format_arguments(
631
631
settings : PluginSettings ,
632
632
extra_arguments : Optional [List [str ]] = None ,
633
633
) -> List [str ]:
634
- """
635
- Build arguments for ruff format.
634
+ """Build arguments for ruff format.
636
635
637
636
Parameters
638
637
----------
@@ -646,6 +645,7 @@ def build_format_arguments(
646
645
Returns
647
646
-------
648
647
List containing the arguments.
648
+
649
649
"""
650
650
args = []
651
651
# Suppress update announcements
@@ -681,8 +681,7 @@ def build_format_arguments(
681
681
682
682
683
683
def load_settings (workspace : Workspace , document_path : str ) -> PluginSettings :
684
- """
685
- Load settings from pyproject.toml file in the project path.
684
+ """Load settings from pyproject.toml file in the project path.
686
685
687
686
Parameters
688
687
----------
@@ -694,6 +693,7 @@ def load_settings(workspace: Workspace, document_path: str) -> PluginSettings:
694
693
Returns
695
694
-------
696
695
PluginSettings read via lsp.
696
+
697
697
"""
698
698
config = workspace ._config
699
699
_plugin_settings = config .plugin_settings ("ruff" , document_path = document_path )
0 commit comments