|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import ast |
| 4 | +from collections import defaultdict |
4 | 5 | from string import Template |
5 | 6 | from typing import TYPE_CHECKING, Any, List, Optional, Union, cast |
6 | 7 |
|
@@ -320,24 +321,36 @@ async def _apply_create_keyword(self, document: TextDocument, insert_text: str) |
320 | 321 | async def code_action_disable_robotcode_diagnostics_for_line( |
321 | 322 | self, document: TextDocument, range: Range, context: CodeActionContext |
322 | 323 | ) -> Optional[List[Union[Command, CodeAction]]]: |
323 | | - if (context.only and CodeActionKind.QUICK_FIX in context.only) or context.trigger_kind in [ |
324 | | - CodeActionTriggerKind.INVOKED, |
325 | | - CodeActionTriggerKind.AUTOMATIC, |
326 | | - ]: |
| 324 | + if ( |
| 325 | + range.start.line == range.end.line |
| 326 | + and range.start.character <= range.end.character |
| 327 | + and ( |
| 328 | + (context.only and CodeActionKind.QUICK_FIX in context.only) |
| 329 | + or context.trigger_kind |
| 330 | + in [ |
| 331 | + CodeActionTriggerKind.INVOKED, |
| 332 | + CodeActionTriggerKind.AUTOMATIC, |
| 333 | + ] |
| 334 | + ) |
| 335 | + ): |
327 | 336 | all_diagnostics = [d for d in context.diagnostics if d.source and d.source.startswith("robotcode.")] |
328 | 337 | if all_diagnostics: |
| 338 | + result = defaultdict(list) |
| 339 | + for diagnostics in all_diagnostics: |
| 340 | + result[diagnostics.code].append(diagnostics) |
| 341 | + |
329 | 342 | return [ |
330 | 343 | CodeAction( |
331 | | - f"Disable '{diagnostics.code}' for this line", |
| 344 | + f"Disable '{k}' for this line", |
332 | 345 | kind=CodeActionKind.QUICK_FIX, |
333 | 346 | command=Command( |
334 | 347 | self.parent.commands.get_command_name(self.disable_robotcode_diagnostics_for_line_command), |
335 | 348 | self.parent.commands.get_command_name(self.disable_robotcode_diagnostics_for_line_command), |
336 | 349 | [document.document_uri, range], |
337 | 350 | ), |
338 | | - diagnostics=[diagnostics], |
| 351 | + diagnostics=v, |
339 | 352 | ) |
340 | | - for diagnostics in all_diagnostics |
| 353 | + for k, v in result.items() |
341 | 354 | ] |
342 | 355 |
|
343 | 356 | return None |
|
0 commit comments