Coverage for src/debputy/lsp/diagnostics.py: 100%
14 statements
« prev ^ index » next coverage.py v7.6.0, created at 2025-01-27 13:59 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2025-01-27 13:59 +0000
1from collections.abc import Mapping
2from typing import (
3 TypedDict,
4 NotRequired,
5 List,
6 Any,
7 Literal,
8 Optional,
9 TYPE_CHECKING,
10 get_args,
11 FrozenSet,
12 cast,
13)
15if TYPE_CHECKING:
16 import lsprotocol.types as types
17else:
18 import debputy.lsprotocol.types as types
20# These are in order of severity (most important to least important).
21#
22# Special cases:
23# - "spelling" is a specialized version of "pedantic" for textual spelling mistakes
24# (LSP uses the same severity for both; only `debputy lint` shows a difference
25# between them)
26#
27LintSeverity = Literal["error", "warning", "informational", "pedantic", "spelling"]
29LINT_SEVERITY2LSP_SEVERITY: Mapping[LintSeverity, types.DiagnosticSeverity] = {
30 "error": types.DiagnosticSeverity.Error,
31 "warning": types.DiagnosticSeverity.Warning,
32 "informational": types.DiagnosticSeverity.Information,
33 "pedantic": types.DiagnosticSeverity.Hint,
34 "spelling": types.DiagnosticSeverity.Hint,
35}
36NATIVELY_LSP_SUPPORTED_SEVERITIES: FrozenSet[LintSeverity] = cast(
37 "FrozenSet[LintSeverity]",
38 frozenset(
39 {
40 "error",
41 "warning",
42 "informational",
43 "pedantic",
44 }
45 ),
46)
49_delta = set(get_args(LintSeverity)).symmetric_difference(
50 LINT_SEVERITY2LSP_SEVERITY.keys()
51)
52assert (
53 not _delta
54), f"LintSeverity and LINT_SEVERITY2LSP_SEVERITY are not aligned. Delta: {_delta}"
55del _delta
58class DiagnosticData(TypedDict):
59 quickfixes: NotRequired[Optional[List[Any]]]
60 lint_severity: NotRequired[Optional[LintSeverity]]
61 report_for_related_file: NotRequired[str]
62 enable_non_interactive_auto_fix: bool