Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer end position for Pylint diagnostics #547

Merged
merged 1 commit into from
Aug 22, 2024
Merged
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
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
Loading