Skip to content

Commit

Permalink
Fix spurious errors when using --follow-imports=normal (#76)
Browse files Browse the repository at this point in the history
* Fix spurious output for `--follow-imports=normal`

* Switch default config to `--follow-imports=normal`
  • Loading branch information
Jammf committed Jul 6, 2023
1 parent 1f37c26 commit 544d86d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions bundled/tool/lsp_server.py
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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -67,7 +67,7 @@
"properties": {
"mypy-type-checker.args": {
"default": [
"--follow-imports=skip"
"--follow-imports=normal"
],
"markdownDescription": "%settings.args.description%",
"items": {
Expand Down

0 comments on commit 544d86d

Please sign in to comment.