Sublime Forum

Completion Triggers

#1

I’m having a series of difficulties with auto complete automatically accepting a selection when I don’t want it to (and some other problems). I was wondering if anyone has found a workaround this.

In particular, I’ve been using CoffeeComplete Plus for autocompletion, and tried automatic triggers on period so I don’t have to manually press Ctrl-Space to bring up the completion menu. This is done via this preference:

[code]“auto_complete_triggers”:

          {"characters": ".@", "selector": "source.coffee"}
       ]

[/code]

However, this often runs afoul when there is a partial match for an item you do not want. For example, in the following situation pressing space will accept the highlighted completion when I want it to dismiss the completion box.

Another frustration is that the completion box will not dismiss when you press Enter (I have “auto_complete_commit_on_tab”: true):

Finally, if I type too quickly, Sublime seems to instantly accept a completion entry without even displaying the completion box:

Is using auto_complete_triggers just not viable in Sublime? I would love to have completion similar to CodeSense in Xcode or IntelliSense in Visual Studio, which almost never get in the way.

1 Like

#2

I use auto_complete_triggers too but never experienced something like this. I do think that the “enter did not close auto complete” happened to me on occasions but it was usually when I wanted to complete anyway and just failed to press the tab button since I changed that setting quite recently.

Maybe you could try splitting the “characters” into to because I’m not sure if it will actually treat each character individually or search for the sequence. Like this:

"auto_complete_triggers":
           
              {"characters": ".", "selector": "source.coffee"},
              {"characters": "@", "selector": "source.coffee"}
           ]
1 Like

#3

I am having the same problems as sapphirehamster and it’s super annoying! I think I managed to reproduce it with a simple set up. The example is pretty arbitrary. After adding the key-binding and the plugin, ‘/’ triggers the autocomplete pop-up in ‘text.html’. Press ‘space’ and ST commits the auto completion although it should just insert a space. ST also commits on ‘/’ or pretty much any other sign such as ‘,’, ‘&’, ‘:’ etc. It does not complete on any letters or ‘(’ (which triggers a snippet).

I haven’t found a general work-around for this. It is possible to add key-bindings that overwrite single keys that trigger the completion using the context { "key": "auto_complete_visible" } so that they only work when the auto-complete popup is open. There is an example below. After adding that, the completion won’t trigger with ‘space’ but still with the other keys.

System: Mac OS X 10.9.2, ST3 Build 3059

  1. add a key-binding to trigger autocomplete. This one is for text.html scope
{ "keys": "/"], "command": "auto_complete", "context":
        
            {"key": "selector", "operator": "equal", "operand": "text.html"},
            {"key": "auto_complete_visible", "operator": "equal", "operand": false }
        ]
    }
  1. add this plugin
import sublime_plugin

class TestPlugin(sublime_plugin.EventListener):

    def on_query_completions(self, view, prefix, locations):
        if not view.match_selector(locations[0], "text.html"):
            return ]
        return ('test1', 't1'), ('test2', 't2')]
  1. work-around for single keys
{
        "keys": " "],
        "command": "chained_actions",
        "args": {
            "actions":"insert","hide_auto_complete"],
            "args":{"characters": " "},{}]
        },
        "context": 
            {"key": "selector", "operator": "equal", "operand": "text.html"},
            { "key": "auto_complete_visible" }
        ]
    }

where chained_action is from this plugin

[code]

http://stackoverflow.com/a/21123341/2503795

import sublime_plugin

class ChainedActionsCommand(sublime_plugin.TextCommand):
def run(self, edit, actions, args):
for i, action in enumerate(actions):
self.view.run_command(action, args*)
[/code]*

0 Likes

Sublime Forum bracket typos
#4

By the way, this does not happen when you add the auto-complete through settings using

“auto_complete_triggers”: {“characters”: “/”, “selector”: “text.html”}]

That is good to know. But I have to use key-bindings to trigger auto-complete and not the settings because I want to trigger on “(”, which does not work with settings. Try it.
“auto_complete_triggers”: {“characters”: “(”, “selector”: “text.html”}]
Does not work. The reason is that “(” is a default keybinding that inserts a snippet, which overwrites the “auto_complete_triggers” setting. So I have to use keybindings to trigger autocomplete…

0 Likes

#5

Yes, auto-complete on “(” won’t work with the setting when you have auto_match on because the keybinding actually does not insert a ( but a snippet which contains it. I don’t see a reasonable way to work around this other than having a macro that first enters ), than goes back by one and inserts the ( to trigger possible auto completions. It makes the thing overly complex though.

0 Likes