From 266a49a9cc5c6012c3f2feb19541defeff8c9e43 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 11 Nov 2023 23:34:31 -0600 Subject: [PATCH] Some LSP cleanup and method extracted --- .../lsp_completion_provider.py | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/core/widgets/base/sourceview/custom_completion_providers/lsp_completion_provider.py b/src/core/widgets/base/sourceview/custom_completion_providers/lsp_completion_provider.py index d6a6d4a..ed1bb8c 100644 --- a/src/core/widgets/base/sourceview/custom_completion_providers/lsp_completion_provider.py +++ b/src/core/widgets/base/sourceview/custom_completion_providers/lsp_completion_provider.py @@ -15,10 +15,10 @@ from gi.repository import GObject class LSPCompletionProvider(GObject.Object, GtkSource.CompletionProvider): """ - This code is A python code completion plugin for Newton. + This code is an LSP code completion plugin for Newton. # NOTE: Some code pulled/referenced from here --> https://github.com/isamert/gedi """ - __gtype_name__ = 'PythonProvider' + __gtype_name__ = 'LSPProvider' def __init__(self, source_view): GObject.Object.__init__(self) @@ -47,19 +47,9 @@ class LSPCompletionProvider(GObject.Object, GtkSource.CompletionProvider): if result: if result.items: for item in result.items: - comp_item = GtkSource.CompletionItem.new() - comp_item.set_label(item.label) - comp_item.set_text(item.textEdit) - comp_item.set_icon( self.get_icon_for_type(item.kind) ) - comp_item.set_info(item.documentation) - proposals.append(comp_item) + proposals.append( self.create_completion_item(item) ) else: - comp_item = GtkSource.CompletionItem.new() - comp_item.set_label(item.label) - comp_item.set_text(item.textEdit) - comp_item.set_icon( self.get_icon_for_type(item.kind) ) - comp_item.set_info(item.documentation) - proposals.append(comp_item) + proposals.append( self.create_completion_item(result) ) context.add_proposals(self, proposals, True) @@ -67,7 +57,32 @@ class LSPCompletionProvider(GObject.Object, GtkSource.CompletionProvider): try: return self._theme.load_icon(icon_names[_type.lower()], 16, 0) except: - try: - return self._theme.load_icon(Gtk.STOCK_ADD, 16, 0) - except: - return None \ No newline at end of file + ... + + try: + return self._theme.load_icon(Gtk.STOCK_ADD, 16, 0) + except: + ... + + return None + + def create_completion_item(self, item): + comp_item = GtkSource.CompletionItem.new() + comp_item.set_label(item.label) + comp_item.set_text(item.textEdit) + comp_item.set_icon( self.get_icon_for_type(item.kind) ) + comp_item.set_info(item.documentation) + + return comp_item + + + + + + + + + + + +