From 28ec70df8dd435206133eabb4f3816cc1a1b3776 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 26 Jan 2023 12:40:39 -0500 Subject: [PATCH] Treat E999 as an error diagnostic (#59) --- ruff_lsp/server.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/ruff_lsp/server.py b/ruff_lsp/server.py index 6aff78b..30726eb 100755 --- a/ruff_lsp/server.py +++ b/ruff_lsp/server.py @@ -163,27 +163,34 @@ def _parse_output_using_regex(content: str) -> list[Diagnostic]: diagnostic = Diagnostic( range=Range(start=start, end=end), message=check.get("message"), - severity=_get_severity(check["code"], check.get("type", "Error")), + severity=_get_severity(check["code"]), code=check["code"], source=TOOL_DISPLAY, data=check.get("fix"), - tags=( - [DiagnosticTag.Unnecessary] - if check["code"] - in { - "F401", # `module` imported but unused - "F841", # local variable `name` is assigned to but never used - } - else None - ), + tags=_get_tags(check["code"]), ) diagnostics.append(diagnostic) return diagnostics -def _get_severity(*_codes: list[str]) -> DiagnosticSeverity: - return DiagnosticSeverity.Warning +def _get_tags(code: str) -> list[DiagnosticTag] | None: + if code in { + "F401", # `module` imported but unused + "F841", # local variable `name` is assigned to but never used + }: + return [DiagnosticTag.Unnecessary] + return None + + +def _get_severity(code: str) -> DiagnosticSeverity: + if code in { + "E902", # `IOError` + "E999", # `SyntaxError` + }: + return DiagnosticSeverity.Error + else: + return DiagnosticSeverity.Warning NOQA_REGEX = re.compile(r"(?i:# noqa)(?::\s?(?P([A-Z]+[0-9]+(?:[,\s]+)?)+))?")