diff --git a/pyls_mypy/plugin.py b/pyls_mypy/plugin.py index dd07fc4..c95f62b 100644 --- a/pyls_mypy/plugin.py +++ b/pyls_mypy/plugin.py @@ -3,15 +3,15 @@ from mypy import api as mypy_api from pyls import hookimpl -line_pattern = r"(.*):(\d+):(\d+): (\w+): (.*)" +line_pattern = r"([^:]+):(?:(\d+):)?(?:(\d+):)? (\w+): (.*)" def parse_line(line): result = re.match(line_pattern, line) if result: _, lineno, offset, severity, msg = result.groups() - lineno = int(lineno) - offset = int(offset) + lineno = int(lineno or 1) + offset = int(offset or 0) errno = 2 if severity == 'error': errno = 1 diff --git a/test/test_plugin.py b/test/test_plugin.py index 5426cd4..7286593 100644 --- a/test/test_plugin.py +++ b/test/test_plugin.py @@ -6,6 +6,8 @@ """ TEST_LINE = 'main.py:279:8: error: "Request" has no attribute "id"' +TEST_LINE_WITHOUT_COL = 'main.py:279: error: "Request" has no attribute "id"' +TEST_LINE_WITHOUT_LINE = 'main.py: error: "Request" has no attribute "id"' def test_plugin(): @@ -19,8 +21,22 @@ def test_plugin(): assert diag['range']['end'] == {'line': 0, 'character': 1} -def test_parse_line(): +def test_parse_full_line(): diag = plugin.parse_line(TEST_LINE) assert diag['message'] == '"Request" has no attribute "id"' assert diag['range']['start'] == {'line': 278, 'character': 8} assert diag['range']['end'] == {'line': 278, 'character': 9} + + +def test_parse_line_without_col(): + diag = plugin.parse_line(TEST_LINE_WITHOUT_COL) + assert diag['message'] == '"Request" has no attribute "id"' + assert diag['range']['start'] == {'line': 278, 'character': 0} + assert diag['range']['end'] == {'line': 278, 'character': 1} + + +def test_parse_line_without_line(): + diag = plugin.parse_line(TEST_LINE_WITHOUT_LINE) + assert diag['message'] == '"Request" has no attribute "id"' + assert diag['range']['start'] == {'line': 0, 'character': 0} + assert diag['range']['end'] == {'line': 0, 'character': 1}