Home Download Buy Blog Forum Support

Code hinting - getting started

Code hinting - getting started

Postby ostinelli on Thu Apr 19, 2012 8:22 pm

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:

Code: Select all
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? :) BTW, I never see the 'hello' suggestion.

Thank you,

r.
ostinelli
 
Posts: 15
Joined: Thu Apr 12, 2012 4:50 am

Re: Code hinting - getting started

Postby agibsonsw on Thu Apr 19, 2012 9:32 pm

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

Code: Select all
    // 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.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Code hinting - getting started

Postby ostinelli on Fri Apr 20, 2012 12:37 am

Thank you.

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

Will this do anyway?

r.
ostinelli
 
Posts: 15
Joined: Thu Apr 12, 2012 4:50 am

Re: Code hinting - getting started

Postby agibsonsw on Fri Apr 20, 2012 12:55 pm

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.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm


Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests