generated from itdominator/Python-With-Gtk-Template
More LSP effort; improved file load by freezing event system until loaded
This commit is contained in:
parent
257a368e02
commit
cec6f71727
@ -26,6 +26,7 @@ class LSPCompletionProvider(GObject.Object, GtkSource.CompletionProvider):
|
|||||||
self._theme = Gtk.IconTheme.get_default()
|
self._theme = Gtk.IconTheme.get_default()
|
||||||
self._source_view = source_view
|
self._source_view = source_view
|
||||||
|
|
||||||
|
|
||||||
def do_get_name(self):
|
def do_get_name(self):
|
||||||
return "LSP Code Completion"
|
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()
|
return context.get_iter()[1] if isinstance(context.get_iter(), tuple) else context.get_iter()
|
||||||
|
|
||||||
def do_match(self, context):
|
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))
|
event_system.emit("textDocument/completion", (self._source_view, context, self.do_populate))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -45,7 +51,7 @@ class LSPCompletionProvider(GObject.Object, GtkSource.CompletionProvider):
|
|||||||
def do_populate(self, context, result = None):
|
def do_populate(self, context, result = None):
|
||||||
proposals = []
|
proposals = []
|
||||||
if result:
|
if result:
|
||||||
if result.items:
|
if not result.items is None:
|
||||||
for item in result.items:
|
for item in result.items:
|
||||||
proposals.append( self.create_completion_item(item) )
|
proposals.append( self.create_completion_item(item) )
|
||||||
else:
|
else:
|
||||||
@ -69,20 +75,17 @@ class LSPCompletionProvider(GObject.Object, GtkSource.CompletionProvider):
|
|||||||
def create_completion_item(self, item):
|
def create_completion_item(self, item):
|
||||||
comp_item = GtkSource.CompletionItem.new()
|
comp_item = GtkSource.CompletionItem.new()
|
||||||
comp_item.set_label(item.label)
|
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)
|
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_icon( self.get_icon_for_type(item.kind) )
|
||||||
comp_item.set_info(item.documentation)
|
comp_item.set_info(item.documentation)
|
||||||
|
|
||||||
|
|
||||||
return comp_item
|
return comp_item
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,7 +70,10 @@ class FileEventsMixin:
|
|||||||
file.set_location(gfile)
|
file.set_location(gfile)
|
||||||
self._file_loader = GtkSource.FileLoader.new(buffer, file)
|
self._file_loader = GtkSource.FileLoader.new(buffer, file)
|
||||||
|
|
||||||
|
event_system.emit("pause_event_processing")
|
||||||
def finish_load_callback(obj, res, user_data = None):
|
def finish_load_callback(obj, res, user_data = None):
|
||||||
|
event_system.emit("resume_event_processing")
|
||||||
|
|
||||||
self._file_loader.load_finish(res)
|
self._file_loader.load_finish(res)
|
||||||
self._document_loaded(line)
|
self._document_loaded(line)
|
||||||
self.update_labels(gfile)
|
self.update_labels(gfile)
|
||||||
@ -152,4 +155,3 @@ class FileEventsMixin:
|
|||||||
self.got_to_line(buffer, line)
|
self.got_to_line(buffer, line)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user