Sublime Forum

Code hinting - getting started

#1

Dear all,

I’m starting a plugin for ST2 which suggests code completion when hitting the colon ‘:’ key. I keep on finding examples using on_query_completions, however this method is not included in the API reference, and this code never gets triggered on the colon key, but only on other keys:

class TestCompletions(sublime_plugin.EventListener):
    def on_query_completions(self, view, prefix, locations):
        print 'ok'
        return 'hello']

Can some kind soul explain to me where is the starting point in building such a plugin? :smile: BTW, I never see the ‘hello’ suggestion.

Thank you,

r.

0 Likes

#2

You can cause ‘:’ to trigger completions by amending the following setting:

// Additional situations to trigger auto complete "auto_complete_triggers": {"selector": "text.html", "characters": "<"} ],
Copy this from the default settings file and create your own file for user settings, or a syntax specific file.

Reading the **html_completions.py **file should help a lot. In particular, you need to return a list of tuples (trigger,snippet)].

You can also use ‘view.match_selector()’ in your completions file, to prevent the code running for every file.

0 Likes

#3

Thank you.

I don’t need snippets though, I just want to display the list of available class methods.

Will this do anyway?

r.

0 Likes

#4

on_query_completions returns a list of ‘snippets’, even if they are just words.

Alternatively, you can just create a ‘sublime-completions’ file. This is a list of words and/or snippets, which can have a scope to only display for certain files. Have a look at the ‘PHP.sublime-completions’ file. This approach is simpler but doesn’t give the control that ‘on_query_completions’ does.

0 Likes