Skip to content

Commit

Permalink
Catch mypy diagnostics which omit start column/end ranges (#72)
Browse files Browse the repository at this point in the history
This commit adds a second line-regexp that catches
mypy diagnostics which only include a starting line
but have no column or end marker (i.e. --warn-unused-ignores).

---------

Co-authored-by: Heals <[email protected]>
Co-authored-by: Rafał Chłodnicki <[email protected]>
  • Loading branch information
3 people authored Nov 15, 2023
1 parent 2f569f6 commit 89cff67
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pylsp_mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
)
)

whole_line_pattern = re.compile( # certain mypy warnings do not report start-end ranges
(
r"^(?P<file>.+):(?P<start_line>\d+): "
r"(?P<severity>\w+): (?P<message>.+?)(?: +\[(?P<code>.+)\])?$"
)
)

log = logging.getLogger(__name__)

# A mapping from workspace path to config file path
Expand Down Expand Up @@ -82,7 +89,8 @@ def parse_line(line: str, document: Optional[Document] = None) -> Optional[Dict[
The dict with the lint data.
"""
result = line_pattern.match(line)
result = line_pattern.match(line) or whole_line_pattern.match(line)

if not result:
return None

Expand All @@ -95,9 +103,9 @@ def parse_line(line: str, document: Optional[Document] = None) -> Optional[Dict[
return None

lineno = int(result["start_line"]) - 1 # 0-based line number
offset = int(result["start_col"]) - 1 # 0-based offset
end_lineno = int(result["end_line"]) - 1
end_offset = int(result["end_col"]) # end is exclusive
offset = int(result.groupdict().get("start_col", 1)) - 1 # 0-based offset
end_lineno = int(result.groupdict().get("end_line", lineno + 1)) - 1
end_offset = int(result.groupdict().get("end_col", 1)) # end is exclusive

severity = result["severity"]
if severity not in ("error", "note"):
Expand Down

0 comments on commit 89cff67

Please sign in to comment.