Sublime Forum

Autocomplete popup not working properly when text is inserted

#1

I’m a PHP dev. My key bindings are simple: bind dots (.) to (->) and dashes (-) to dollar signs ($) (for variables).

I recently installed an LSP plugin and the suggestions popup for the autocomplete feature does not work as expected when inserting dollar signs or object member accessors (->) using the “insert_snippet” command.

(click to enlarge)

I also noticed that this doesn’t work properly when pasting text (using CMD + v).

So my concussion is that the autosuggestions are based on key presses rather that the current text.

Does anyone know if I can perhaps trigger a key press using python?

Basically I just want to insert $ and -> and have the suggestions popup show correctly.

0 Likes

#2

And this is one of the key bindings that I have (on the second one I tried using the multicommand plugin to try trigger the popup manually)

{ "keys": ["-"], "command": "insert_snippet", "args": {"contents": "\\$"}, "context": [
    { "key": "selector", "operator": "equal", "operand": "source.php" }
]}

{
  "keys": ["."],
  "command": "multicommand",
  "args": {
    "commands": [
        { 
            "command": "insert_snippet", 
            "args": {"contents": "->"}, 
            "context": [
                {
                    "key": "selector", 
                    "operator": "equal", 
                    "operand": "source.php" 
                }
        ]},
        {"command": "auto_complete"}
    ]
  }
},
0 Likes

#3

There is a built-in chain command now, so you don’t need the additional package for the key binding. And -> is not really a snippet, so just insert should be sufficient. Does the following work better?

    {
        "keys": ["."],
        "command": "chain",
        "args": {
            "commands": [
                ["insert", {"characters": "->"}],
                ["auto_complete"]
            ]
        },
        "context": [
            { "key": "selector", "operand": "source.php" }
        ]
    },

If the completions come from LSP, only the current cursor position should be relevant for the available completions, and afaik it shouldn’t matter how the last characters were inserted.

2 Likes

#4

Does the following work better?

Like a charm, thanks a lot.

Been a few days since trying to fix this with no luck. I think I did try the “insert” command but didn’t try it alongside with the “auto_complete” command. Maybe the devs could make the autocompletion popup show after a snippet is inserted anyway, I have no idea why it wouldn’t work. It my opinion it should be expected behavior.

0 Likes