Add a basic language server

This commit is contained in:
James Westman 2021-10-22 21:47:05 -05:00
parent e553e5db29
commit b553fc357c
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
5 changed files with 202 additions and 7 deletions

View file

@ -65,3 +65,14 @@ def did_you_mean(word: str, options: [str]) -> T.Optional[str]:
if closest[1] <= 5:
return closest[0]
return None
def idx_to_pos(idx: int, text: str) -> (int, int):
sp = text[:idx].splitlines(keepends=True)
line_num = len(sp)
col_num = len(sp[-1])
return (line_num, col_num)
def pos_to_idx(line: int, col: int, text: str) -> int:
lines = text.splitlines(keepends=True)
return sum([len(line) for line in lines[:line]]) + col