Sublime Forum

Autocomplete Popup from plugin

#1

Hi there -

I seem to be missing something - I’ve created an autocomplete plugin that works, but doesn’t show the popup with the list of choices - only works to tab through the possibilities.

Is there a tutorial somewhere? Am I missing a setting? I started with the Google autocomplete example, and man, everything looks the same.

Here’s the code:

[code] import sublime_plugin, sublime, re

class LangCompletions(sublime_plugin.EventListener):
 
    def on_query_completions(self, view, prefix, locations):
        pt = locations[0] - len(prefix) - 2
        ch = view.substr(sublime.Region(pt, pt + 2))
        if ch != '##':
            return ]
        pattern  = re.compile( 'LG\_.' )
        if re.match( pattern, prefix ):
          handle   = file( 'text-file-with-LG_-stuff.txt', 'rb')
          pattern  = re.compile( prefix )
          results  = ]
         
          for line in handle.readlines():
            match = re.match( pattern, line )
            if match:
              langkey = line.split( '=' )
              value   = langkey[0] + '##'
              display = '##' + value
              results.append( ( display, value ) )
 
          results.sort()
 
          return results
        return 0

[/code]

Anything missing?

0 Likes

#2

The hash signs # are considered word separators:

// Characters that are considered to separate words "word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=]{}`~?",
and don’t trigger the completions list. But you could leave this global setting, but try changing (copy first to your File Settings User, or Syntax specific)

// Additional situations to trigger auto complete "auto_complete_triggers": {"selector": "text.html", "characters": "<"} ],

It says ‘characters’ so perhaps you can type ‘##’ in place of ‘<’.

0 Likes