Fix diagnostic location reporting

Text positions at the beginning of a line were being shown on the
previous line.
This commit is contained in:
James Westman 2022-12-25 16:02:55 -06:00
parent 40f493b378
commit 7ef314ff94
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
2 changed files with 3 additions and 4 deletions

View file

@ -74,9 +74,8 @@ def did_you_mean(word: str, options: T.List[str]) -> T.Optional[str]:
def idx_to_pos(idx: int, text: str) -> T.Tuple[int, int]: def idx_to_pos(idx: int, text: str) -> T.Tuple[int, int]:
if idx == 0 or len(text) == 0: if idx == 0 or len(text) == 0:
return (0, 0) return (0, 0)
sp = text[:idx].splitlines(keepends=True) line_num = text.count("\n", 0, idx) + 1
line_num = len(sp) col_num = idx - text.rfind("\n", 0, idx) - 1
col_num = len(sp[-1])
return (line_num - 1, col_num) return (line_num - 1, col_num)

View file

@ -1 +1 @@
1,10,0,Expected a version number for GTK 1,11,0,Expected a version number for GTK