mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Add a basic language server
This commit is contained in:
parent
e553e5db29
commit
b553fc357c
5 changed files with 202 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue