8000 Infer end position for Pylint diagnostics (#547) · deepnote/python-lsp-server@4714d38 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4714d38

Browse files
authored
Infer end position for Pylint diagnostics (python-lsp#547)
1 parent cabac8e commit 4714d38

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pylsp/plugins/pylint_lint.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ def lint(cls, document, is_saved, flags=""):
151151
"line": line,
152152
# It's possible that we're linting an empty file. Even an empty
153153
# file might fail linting if it isn't named properly.
154-
"character": len(document.lines[line]) if document.lines else 0,
154+
"character": (
155+
_find_end_of_identifier(document.lines[line], diag["column"])
156+
if document.lines
157+
else 0
158+
),
155159
},
156160
}
157161

@@ -338,8 +342,9 @@ def _parse_pylint_stdio_result(document, stdout):
338342
"start": {"line": line, "character": character},
339343
"end": {
340344
"line": line,
341-
# no way to determine the column
342-
"character": len(document.lines[line]) - 1,
345+
"character": _find_end_of_identifier(
346+
document.lines[line], character
347+
),
343348
},
344349
},
345350
"message": msg,
@@ -352,3 +357,11 @@ def _parse_pylint_stdio_result(document, stdout):
352357
diagnostics.append(diagnostic)
353358

354359
return diagnostics
360+
361+
362+
def _find_end_of_identifier(string, start):
363+
"""Find the end of the identifier starting at the given position."""
364+
for i in range(len(string), start, -1):
365+
if string[start:i].isidentifier():
366+
return i
367+
return len(string) - 1

0 commit comments

Comments
 (0)
0