Created
August 30, 2020 19:10
-
-
Save rchl/721c69ab2a01794f07a48841828605df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime | |
import sublime_plugin | |
FIRST_RESPONSE_DELAY = 200 | |
SECOND_RESPONSE_DELAY = 2000 | |
class CompletionListener(sublime_plugin.ViewEventListener): | |
def on_query_completions(self, prefix, locations): | |
is_popup_visible = self.view.is_popup_visible() | |
print('on_query_completions', prefix, is_popup_visible) | |
completion_list = sublime.CompletionList() | |
sublime.set_timeout_async(lambda: self._on_query_completions_async(completion_list, locations[0], is_popup_visible)) | |
return completion_list | |
def _on_query_completions_async(self, completion_list, location, is_popup_visible): | |
completions = [ | |
sublime.CompletionItem( | |
trigger='createEvent', | |
annotation=' createEvent(const EventCreateInfo &createInfo) const', | |
completion='createEvent(${1:const EventCreateInfo &createInfo})', | |
completion_format=sublime.COMPLETION_FORMAT_SNIPPET, | |
kind=(sublime.KIND_ID_FUNCTION, "m", "Method"), | |
details='' | |
), | |
sublime.CompletionItem( | |
trigger='createEvent', | |
annotation=' createEvent(const vk::EventCreateInfo *pCreateInfo, const vk::AllocationCallbacks *pAllocator, vk::Event *pEvent) const', | |
completion='createEvent(${1:const vk::EventCreateInfo *pCreateInfo}, ${2:const vk::AllocationCallbacks *pAllocator}, ${3:vk::Event *pEvent})', | |
completion_format=sublime.COMPLETION_FORMAT_SNIPPET, | |
kind=(sublime.KIND_ID_FUNCTION, "m", "Method"), | |
details='' | |
), | |
sublime.CompletionItem( | |
trigger='createEventUnique', | |
annotation=' createEventUnique(const EventCreateInfo &createInfo) const', | |
completion='createEventUnique(${1:const EventCreateInfo &createInfo})', | |
completion_format=sublime.COMPLETION_FORMAT_SNIPPET, | |
kind=(sublime.KIND_ID_FUNCTION, "m", "Method"), | |
details='' | |
), | |
] | |
timeout = FIRST_RESPONSE_DELAY if not is_popup_visible else SECOND_RESPONSE_DELAY | |
sublime.set_timeout(lambda: completion_list.set_completions(completions, flags=0), timeout) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment