Skip to content

Commit

Permalink
Handle results without line or column
Browse files Browse the repository at this point in the history
  • Loading branch information
tomv564 committed Aug 8, 2017
1 parent be5843a commit bf163ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pyls_mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion test/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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}

0 comments on commit bf163ac

Please sign in to comment.