Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pylsp/plugins/flake8_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ def parse_stdout(source, stdout):

_, line, character, code, msg = parsed_line
line = int(line) - 1
character = int(character) - 1
# Some plugins report column zero when no precise column is available.
character = max(0, int(character) - 1)
# show also the code in message
msg = code + " " + msg
severity = lsp.DiagnosticSeverity.Warning
Expand Down
29 changes: 29 additions & 0 deletions test/plugins/test_flake8_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from textwrap import dedent
from unittest.mock import patch

import pytest

from pylsp import lsp, uris
from pylsp.plugins import flake8_lint
from pylsp.workspace import Document
Expand Down Expand Up @@ -60,6 +62,33 @@ def test_flake8_lint(workspace) -> None:
os.remove(name)


@pytest.mark.parametrize(
"line, column, expected_character",
[
(" # comment", 0, 0),
("", 0, 0),
(" # comment", 1, 0),
(" # comment", 5, 4),
],
)
def test_flake8_diagnostic_columns(workspace, line, column, expected_character) -> None:
source = f"def myfun():\n{line}\n pass\n"
doc = Document("", workspace, source)
output = (
f"stdin:2:{column}: ANN201 Missing return type annotation for public function\n"
)

with patch("pylsp.plugins.flake8_lint.run_flake8", return_value=output):
diagnostics = flake8_lint.pylsp_lint(workspace, doc)

assert len(diagnostics) == 1
assert diagnostics[0]["range"] == {
"start": {"line": 1, "character": expected_character},
"end": {"line": 1, "character": len(line) + 1},
}
assert diagnostics[0]["code"] == "ANN201"


def test_flake8_respecting_configuration(workspace) -> None:
docs = [
("src/__init__.py", ""),
Expand Down