Skip to content

Commit

Permalink
Fix spurious output for --follow-imports=normal
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammf committed Jul 6, 2023
1 parent 1f37c26 commit dc87909
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bundled/tool/lsp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def update_sys_path(path_to_add: str, strategy: str) -> None:
TOOL_ARGS = [
"--no-color-output",
"--no-error-summary",
"--show-absolute-path",
"--show-column-numbers",
"--show-error-code",
"--no-pretty",
Expand Down Expand Up @@ -113,7 +114,9 @@ def _linting_helper(document: workspace.Document) -> list[lsp.Diagnostic]:

# deep copy here to prevent accidentally updating global settings.
settings = copy.deepcopy(_get_settings_by_document(document))
return _parse_output_using_regex(result.stdout, settings["severity"])
return _parse_output_using_regex(
result.stdout, settings["severity"], document
)
except Exception:
LSP_SERVER.show_message_log(
f"Linting failed with error:\r\n{traceback.format_exc()}",
Expand All @@ -136,7 +139,7 @@ def _get_group_dict(line: str) -> Optional[Dict[str, str | None]]:


def _parse_output_using_regex(
content: str, severity: Dict[str, str]
content: str, severity: Dict[str, str], document: workspace.Document
) -> list[lsp.Diagnostic]:
lines: list[str] = content.splitlines()
diagnostics: list[lsp.Diagnostic] = []
Expand All @@ -153,6 +156,11 @@ def _parse_output_using_regex(
if not data:
continue

# skip output from other documents
# (causes --follow-imports=normal to behave like silent).
if data["filepath"] != document.path:
continue

type_ = data["type"]
code = data["code"]

Expand Down

0 comments on commit dc87909

Please sign in to comment.