Sublime Forum

ST4 triggering completion

#1

Hi, I recently switched to ST4 and I noticed the completion triggers are different. In particular my plugin is no longer working, because it won’t trigger a completion after typing the word new. This is in a Javascript context.

For example, in ST3 when you type new C, the on_query_completions event will be triggered with the prefix C and this is where I insert my custom snippets starting that start with C. In ST4 nothing is triggered after typing new C, only after the first n and the space behind w.

I figured this could also be fixed with the settings auto_complete_selector or auto_complete_triggers, but the documentation is not enough for me to understand them. For example I tried adding {"selector": "meta.function-call.constructor.js", "characters": "C"}, guessing that could trigger the completion, but still nothing happens after typing new C.

Any help would be appreciated, how do I make it trigger the autocompletion like in ST3?

0 Likes

#2

Sorry to bump this, but surely somebody here can answer on how to change the auto completion triggers?

0 Likes

#3

I’m not a regular JavaScript user, but when I type new C with the JavaScript syntax, I do get the autocompletion popup with word completions from the view. The default value for auto_complete_selector doesn’t disable the completions, and neither should JavaScript’s Completion Rules.tmPreferences. You can easily assure that on_query_completions is triggered with a little plugin like this, and look at the console output:

import sublime_plugin

class CompletionListener(sublime_plugin.ViewEventListener):
    def on_query_completions(self, prefix, locations):
        print(prefix)

Maybe you should post your plugin code here, if you want help with debugging.

Perhaps you have another package installed that messes with completions?

0 Likes

#4

Hey thanks for answering @jwortmann it took a while for me to try this because I wanted to try this on a fresh copy of Sublime 4 without any plugins. So I finally tried it and copied your snippet in a new python script and tried it on new C. Again, C is not triggered by the callback…

I hope there are other suggestions or ideas…

0 Likes

#5

I still can’t reproduce this and don’t have any idea why it wouldn’t work.

javascript

You should try to start ST in safe mode with subl --safe-mode, then open Preferences > Browse Packages and copy the test script into the User folder. If it still doesn’t work, the issue tracker at https://github.com/sublimehq/sublime_text/issues would be the right place to report it. Perhaps it is a bug only on a certain OS (I’m on Windows). If it works in safe mode, then you still have a package or setting active somewhere which would cause the behavior you see.

0 Likes

#6

Hey thanks @jwortmann, this is interesting, I’m convinced this is a bug now! I tried it in safe mode and I got the same behavior, but I figured out how to reproduce the behavior: basically if there’s already a statement with new in the file, any other new statement will no longer trigger the completion!St4bug

0 Likes

#7

Interesting, I never really realized that ST automatically shows the autocompletion popup (e.g. with word completions from the buffer) after typing the whitespace, and then only queries again if the typed letters don’t match any of the completion items.

I just tested it on ST3, and this behavior seems indeed to be different from ST3, where the completion popup only appears after typing a letter, and not after the whitespace.

So to properly support ST4, your plugin would have to provide the possible completion items already if the prefix is empty. Or alternatively you could experiment with something like the following to force ST to re-query for completions after the first typed letter (not sure whether this is a good solution or possibly affects performance in some way):

import sublime
import sublime_plugin

class CompletionListener(sublime_plugin.ViewEventListener):
    def on_query_completions(self, prefix, locations):
        print(prefix)  # just for debugging
        if not prefix:
            return [], sublime.DYNAMIC_COMPLETIONS
0 Likes