lsp: Add code actions

"Did you mean" hints are automatically converted into code actions.
This commit is contained in:
James Westman 2021-11-11 22:59:49 -06:00
parent d89f2356b4
commit d511b3f1e3
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
5 changed files with 82 additions and 16 deletions

View file

@ -78,3 +78,17 @@ def idx_to_pos(idx: int, text: str) -> T.Tuple[int, int]:
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
def idxs_to_range(start: int, end: int, text: str):
start_l, start_c = idx_to_pos(start, text)
end_l, end_c = idx_to_pos(end, text)
return {
"start": {
"line": start_l,
"character": start_c,
},
"end": {
"line": end_l,
"character": end_c,
},
}