generated from itdominator/Python-With-Gtk-Template
removing completion items without text insertions
This commit is contained in:
parent
742ec1baad
commit
c06df187a6
|
@ -60,18 +60,21 @@ class EditorControllerMixin(KeyInputController, EditorEventsMixin):
|
||||||
if source_view.completion_view.get_parent():
|
if source_view.completion_view.get_parent():
|
||||||
source_view.remove(source_view.completion_view)
|
source_view.remove(source_view.completion_view)
|
||||||
|
|
||||||
|
if len( message.result["items"] ) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
source_view.completion_view.clear_items()
|
source_view.completion_view.clear_items()
|
||||||
x, y = self._get_insert_line_xy(source_view)
|
x, y = self._get_insert_line_xy(source_view)
|
||||||
source_view.add_child_in_window(source_view.completion_view, Gtk.TextWindowType.WIDGET, x, y)
|
source_view.add_child_in_window(source_view.completion_view, Gtk.TextWindowType.WIDGET, x, y)
|
||||||
|
completion_list = self.filter_completion_list( message.result["items"] )
|
||||||
|
|
||||||
for item in message.result["items"]:
|
for item in completion_list:
|
||||||
ci = CompletionItem()
|
ci = CompletionItem()
|
||||||
ci.populate_completion_item(item)
|
ci.populate_completion_item(item)
|
||||||
source_view.completion_view.add_completion_item(ci)
|
source_view.completion_view.add_completion_item(ci)
|
||||||
|
|
||||||
if len( message.result["items"] ) > 0:
|
source_view.completion_view.show_all()
|
||||||
source_view.completion_view.show_all()
|
GLib.idle_add( source_view.completion_view.select_first_row )
|
||||||
GLib.idle_add( source_view.completion_view.select_first_row )
|
|
||||||
|
|
||||||
# completion = source_view.get_completion()
|
# completion = source_view.get_completion()
|
||||||
# providers = completion.get_providers()
|
# providers = completion.get_providers()
|
||||||
|
@ -138,3 +141,15 @@ class EditorControllerMixin(KeyInputController, EditorEventsMixin):
|
||||||
yy = win_loc[1] + view_pos[1] + iter_loc.height
|
yy = win_loc[1] + view_pos[1] + iter_loc.height
|
||||||
|
|
||||||
return xx, yy
|
return xx, yy
|
||||||
|
|
||||||
|
# Note: What I really need to do (long term) is keep all results and then just
|
||||||
|
# toggle show/hide of the CompletionItems relevent to the request context.
|
||||||
|
def filter_completion_list(self, completion_list: list) -> list:
|
||||||
|
filtered_list = []
|
||||||
|
|
||||||
|
for item in completion_list:
|
||||||
|
keys = item.keys()
|
||||||
|
if "insertText" in keys or "textEdit" in keys:
|
||||||
|
filtered_list.append(item)
|
||||||
|
|
||||||
|
return filtered_list
|
|
@ -13,6 +13,7 @@ class CompletionItem(Gtk.Label):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(CompletionItem, self).__init__()
|
super(CompletionItem, self).__init__()
|
||||||
|
|
||||||
|
self.kind: int = -1
|
||||||
self.newText: str = ""
|
self.newText: str = ""
|
||||||
self.insertText: str = ""
|
self.insertText: str = ""
|
||||||
self.textEdit: [] = []
|
self.textEdit: [] = []
|
||||||
|
@ -36,6 +37,8 @@ class CompletionItem(Gtk.Label):
|
||||||
keys = item.keys()
|
keys = item.keys()
|
||||||
self.set_label(item["label"])
|
self.set_label(item["label"])
|
||||||
|
|
||||||
|
if "kind" in keys:
|
||||||
|
self.kind = item["kind"]
|
||||||
|
|
||||||
if "insertText" in keys:
|
if "insertText" in keys:
|
||||||
self.insertText = item["insertText"]
|
self.insertText = item["insertText"]
|
||||||
|
|
|
@ -191,3 +191,38 @@ class CompletionView(Gtk.ScrolledWindow):
|
||||||
iter.forward_char()
|
iter.forward_char()
|
||||||
|
|
||||||
return pre_char
|
return pre_char
|
||||||
|
|
||||||
|
# export const Text = 1;
|
||||||
|
# export const Method = 2;
|
||||||
|
# export const Function = 3;
|
||||||
|
# export const Constructor = 4;
|
||||||
|
# export const Field = 5;
|
||||||
|
# export const Variable = 6;
|
||||||
|
# export const Class = 7;
|
||||||
|
# export const Interface = 8;
|
||||||
|
# export const Module = 9;
|
||||||
|
# export const Property = 10;
|
||||||
|
# export const Unit = 11;
|
||||||
|
# export const Value = 12;
|
||||||
|
# export const Enum = 13;
|
||||||
|
# export const Keyword = 14;
|
||||||
|
# export const Snippet = 15;
|
||||||
|
# export const Color = 16;
|
||||||
|
# export const File = 17;
|
||||||
|
# export const Reference = 18;
|
||||||
|
# export const Folder = 19;
|
||||||
|
# export const EnumMember = 20;
|
||||||
|
# export const Constant = 21;
|
||||||
|
# export const Struct = 22;
|
||||||
|
# export const Event = 23;
|
||||||
|
# export const Operator = 24;
|
||||||
|
# export const TypeParameter = 25;
|
||||||
|
def sort_completion_list(self, completion_list: list) -> list:
|
||||||
|
new_completion_list = []
|
||||||
|
|
||||||
|
for item in filtered_list:
|
||||||
|
keys = item.keys()
|
||||||
|
if "insertText" in keys or "textEdit" in keys:
|
||||||
|
new_completion_list.append(item)
|
||||||
|
|
||||||
|
return new_completion_list
|
||||||
|
|
Loading…
Reference in New Issue