A minimal example for a plugin based completions plugin would be:
import sublime
import sublime_plugin
class YamlCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
if not view.match_selector(locations[0], "source.yaml"):
return
pt = locations[0]
# get the text in front of first caret
token = view.substr(sublime.Region(pt - 2, pt))
if token == "!<":
return sublime.CompletionList(
[
sublime.CompletionItem(
trigger="!<Rule",
kind=[sublime.KindId.FUNCTION, "r", "Rule"],
annotation="My Rule",
details="This is a rule to..."
)
]
)
We need to read content from before caret’s location as prefix
is empty due to !<
being word separator characters (which is also the reason why static completions don’t work).
So we get the text left to caret manually and return completions, if they match certain criteria.