More LSP effort; improved file load by freezing event system until loaded

This commit is contained in:
itdominator 2023-11-13 22:09:25 -06:00
parent 257a368e02
commit cec6f71727
2 changed files with 20 additions and 15 deletions

View File

@ -26,6 +26,7 @@ class LSPCompletionProvider(GObject.Object, GtkSource.CompletionProvider):
self._theme = Gtk.IconTheme.get_default()
self._source_view = source_view
def do_get_name(self):
return "LSP Code Completion"
@ -33,6 +34,11 @@ class LSPCompletionProvider(GObject.Object, GtkSource.CompletionProvider):
return context.get_iter()[1] if isinstance(context.get_iter(), tuple) else context.get_iter()
def do_match(self, context):
iter = self.get_iter_correctly(context)
buffer = iter.get_buffer()
if buffer.get_context_classes_at_iter(iter) != ['no-spell-check']:
return False
event_system.emit("textDocument/completion", (self._source_view, context, self.do_populate))
return True
@ -45,7 +51,7 @@ class LSPCompletionProvider(GObject.Object, GtkSource.CompletionProvider):
def do_populate(self, context, result = None):
proposals = []
if result:
if result.items:
if not result.items is None:
for item in result.items:
proposals.append( self.create_completion_item(item) )
else:
@ -69,20 +75,17 @@ class LSPCompletionProvider(GObject.Object, GtkSource.CompletionProvider):
def create_completion_item(self, item):
comp_item = GtkSource.CompletionItem.new()
comp_item.set_label(item.label)
if item.textEdit:
if isinstance(item.textEdit, dict):
comp_item.set_text(item.textEdit["newText"])
else:
comp_item.set_text(item.textEdit)
else:
comp_item.set_text(item.insertText)
comp_item.set_icon( self.get_icon_for_type(item.kind) )
comp_item.set_info(item.documentation)
return comp_item

View File

@ -70,7 +70,10 @@ class FileEventsMixin:
file.set_location(gfile)
self._file_loader = GtkSource.FileLoader.new(buffer, file)
event_system.emit("pause_event_processing")
def finish_load_callback(obj, res, user_data = None):
event_system.emit("resume_event_processing")
self._file_loader.load_finish(res)
self._document_loaded(line)
self.update_labels(gfile)
@ -152,4 +155,3 @@ class FileEventsMixin:
self.got_to_line(buffer, line)