@@ -116,46 +116,48 @@ def pylsp_format_document(workspace: Workspace, document: Document) -> Generator
116
116
Document to apply ruff on.
117
117
118
118
"""
119
- log .debug (f"textDocument/formatting: { document } " )
120
- outcome = yield
121
- result = outcome .get_result ()
122
- if result :
123
- source = result [0 ]["newText" ]
124
- else :
125
- source = document .source
126
119
127
- settings = load_settings (workspace = workspace , document_path = document .path )
128
- if not settings .format_enabled :
129
- return
120
+ with workspace .report_progress ("format: ruff" ):
121
+ log .debug (f"textDocument/formatting: { document } " )
122
+ outcome = yield
123
+ result = outcome .get_result ()
124
+ if result :
125
+ source = result [0 ]["newText" ]
126
+ else :
127
+ source = document .source
130
128
131
- new_text = run_ruff_format (
132
- settings = settings , document_path = document . path , document_source = source
133
- )
129
+ settings = load_settings ( workspace = workspace , document_path = document . path )
130
+ if not settings . format_enabled :
131
+ return
134
132
135
- if settings .format :
136
- # A second pass through the document with `ruff check` and only the rules
137
- # enabled via the format config property. This allows for things like
138
- # specifying `format = ["I"]` to get import sorting as part of formatting.
139
- new_text = run_ruff (
140
- settings = PluginSettings (
141
- ignore = ["ALL" ], select = settings .format , executable = settings .executable
142
- ),
143
- document_path = document .path ,
144
- document_source = new_text ,
145
- fix = True ,
133
+ new_text = run_ruff_format (
134
+ settings = settings , document_path = document .path , document_source = source
146
135
)
147
136
148
- # Avoid applying empty text edit
149
- if not new_text or new_text == source :
150
- return
137
+ if settings .format :
138
+ # A second pass through the document with `ruff check` and only the rules
139
+ # enabled via the format config property. This allows for things like
140
+ # specifying `format = ["I"]` to get import sorting as part of formatting.
141
+ new_text = run_ruff (
142
+ settings = PluginSettings (
143
+ ignore = ["ALL" ], select = settings .format , executable = settings .executable
144
+ ),
145
+ document_path = document .path ,
146
+ document_source = new_text ,
147
+ fix = True ,
148
+ )
151
149
152
- range = Range (
153
- start = Position (line = 0 , character = 0 ),
154
- end = Position (line = len (document .lines ), character = 0 ),
155
- )
156
- text_edit = TextEdit (range = range , new_text = new_text )
150
+ # Avoid applying empty text edit
151
+ if not new_text or new_text == source :
152
+ return
153
+
154
+ range = Range (
155
+ start = Position (line = 0 , character = 0 ),
156
+ end = Position (line = len (document .lines ), character = 0 ),
157
+ )
158
+ text_edit = TextEdit (range = range , new_text = new_text )
157
159
158
- outcome .force_result (converter .unstructure ([text_edit ]))
160
+ outcome .force_result (converter .unstructure ([text_edit ]))
159
161
160
162
161
163
@hookimpl
@@ -174,10 +176,12 @@ def pylsp_lint(workspace: Workspace, document: Document) -> List[Dict]:
174
176
List of dicts containing the diagnostics.
175
177
176
178
"""
177
- settings = load_settings (workspace , document .path )
178
- checks = run_ruff_check (document = document , settings = settings )
179
- diagnostics = [create_diagnostic (check = c , settings = settings ) for c in checks ]
180
- return converter .unstructure (diagnostics )
179
+
180
+ with workspace .report_progress ("lint: ruff" ):
181
+ settings = load_settings (workspace , document .path )
182
+ checks = run_ruff_check (document = document , settings = settings )
183
+ diagnostics = [create_diagnostic (check = c , settings = settings ) for c in checks ]
184
+ return converter .unstructure (diagnostics )
181
185
182
186
183
187
def create_diagnostic (check : RuffCheck , settings : PluginSettings ) -> Diagnostic :
0 commit comments