Skip to content

Commit 43a6dc0

Browse files
committed
fix(langserver: ignore error quickfix now only works if selection is one line
1 parent d8591b1 commit 43a6dc0

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_quick_fixes.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import ast
4+
from collections import defaultdict
45
from string import Template
56
from typing import TYPE_CHECKING, Any, List, Optional, Union, cast
67

@@ -320,24 +321,36 @@ async def _apply_create_keyword(self, document: TextDocument, insert_text: str)
320321
async def code_action_disable_robotcode_diagnostics_for_line(
321322
self, document: TextDocument, range: Range, context: CodeActionContext
322323
) -> 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+
):
327336
all_diagnostics = [d for d in context.diagnostics if d.source and d.source.startswith("robotcode.")]
328337
if all_diagnostics:
338+
result = defaultdict(list)
339+
for diagnostics in all_diagnostics:
340+
result[diagnostics.code].append(diagnostics)
341+
329342
return [
330343
CodeAction(
331-
f"Disable '{diagnostics.code}' for this line",
344+
f"Disable '{k}' for this line",
332345
kind=CodeActionKind.QUICK_FIX,
333346
command=Command(
334347
self.parent.commands.get_command_name(self.disable_robotcode_diagnostics_for_line_command),
335348
self.parent.commands.get_command_name(self.disable_robotcode_diagnostics_for_line_command),
336349
[document.document_uri, range],
337350
),
338-
diagnostics=[diagnostics],
351+
diagnostics=v,
339352
)
340-
for diagnostics in all_diagnostics
353+
for k, v in result.items()
341354
]
342355

343356
return None

0 commit comments

Comments
 (0)