Skip to content

Commit

Permalink
Infer end position for Pylint diagnostics (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuestengecko committed Aug 22, 2024
1 parent cabac8e commit 4714d38
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pylsp/plugins/pylint_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ def lint(cls, document, is_saved, flags=""):
"line": line,
# It's possible that we're linting an empty file. Even an empty
# file might fail linting if it isn't named properly.
"character": len(document.lines[line]) if document.lines else 0,
"character": (
_find_end_of_identifier(document.lines[line], diag["column"])
if document.lines
else 0
),
},
}

Expand Down Expand Up @@ -338,8 +342,9 @@ def _parse_pylint_stdio_result(document, stdout):
"start": {"line": line, "character": character},
"end": {
"line": line,
# no way to determine the column
"character": len(document.lines[line]) - 1,
"character": _find_end_of_identifier(
document.lines[line], character
),
},
},
"message": msg,
Expand All @@ -352,3 +357,11 @@ def _parse_pylint_stdio_result(document, stdout):
diagnostics.append(diagnostic)

return diagnostics


def _find_end_of_identifier(string, start):
"""Find the end of the identifier starting at the given position."""
for i in range(len(string), start, -1):
if string[start:i].isidentifier():
return i
return len(string) - 1

0 comments on commit 4714d38

Please sign in to comment.