fixing additional completion insertion edge cases

This commit is contained in:
itdominator 2024-10-03 21:31:59 -05:00
parent 8eb8c4d543
commit 742ec1baad
1 changed files with 14 additions and 14 deletions

View File

@ -134,15 +134,10 @@ class CompletionView(Gtk.ScrolledWindow):
pre_char = self.get_pre_char(siter) pre_char = self.get_pre_char(siter)
if completion_item.textEdit: if completion_item.textEdit:
sline = completion_item.textEdit["range"]["start"]["line"] self.process_range_insert(buffer, completion_item.textEdit, completion_item.newText)
schar = completion_item.textEdit["range"]["start"]["character"]
eline = completion_item.textEdit["range"]["end"]["line"]
echar = completion_item.textEdit["range"]["end"]["character"]
siter = buffer.get_iter_at_line_offset( sline, schar )
eiter = buffer.get_iter_at_line_offset( eline, echar )
buffer.delete(siter, eiter) for edit in completion_item.additionalTextEdits:
buffer.insert(siter, completion_item.newText, -1) self.process_range_insert(buffer, edit, edit["newText"])
source_view.remove(self) source_view.remove(self)
GLib.idle_add( source_view.grab_focus ) GLib.idle_add( source_view.grab_focus )
@ -168,16 +163,21 @@ class CompletionView(Gtk.ScrolledWindow):
buffer.delete(siter, eiter) buffer.delete(siter, eiter)
buffer.insert(siter, completion_item.insertText, -1) buffer.insert(siter, completion_item.insertText, -1)
for edit in completion_item.additionalTextEdits:
print()
print()
print(edit)
print()
print()
source_view.remove(self) source_view.remove(self)
GLib.idle_add( source_view.grab_focus ) GLib.idle_add( source_view.grab_focus )
def process_range_insert(self, buffer, insert_data: {}, text: str):
sline = insert_data["range"]["start"]["line"]
schar = insert_data["range"]["start"]["character"]
eline = insert_data["range"]["end"]["line"]
echar = insert_data["range"]["end"]["character"]
siter = buffer.get_iter_at_line_offset( sline, schar )
eiter = buffer.get_iter_at_line_offset( eline, echar )
buffer.delete(siter, eiter)
buffer.insert(siter, text, -1)
def get_word_start(self, iter): def get_word_start(self, iter):
pre_char = self.get_pre_char(iter) pre_char = self.get_pre_char(iter)
while pre_char == '_': while pre_char == '_':