Sublime Forum

Weird Behaviour Snippet Behaving Differently Inside Conditional

#1

I’m hoping someone can help me out with this. I have a snippet for $ which translates to $this-> which prompts me with an autocompletion popup, but recently I found it doesn’t work all the time as shown below.

this works but strangely if I start the conditional with if like this

if ($this->)

then it doesn’t show the autocompletion popup.

This is how I have it setup if it helps

https://gist.github.com/carlevison/77d0c92286774b114ded4074bf896767

Help please.

0 Likes

#2

Your question is “How do I automatically open the auto-complete popup after triggering this ‘snippet’?” ?

1 Like

#3

Hi. Thank for the reply, the snippet works, it successfully opens the autocomplete popup inside methods but for some strange reason

(triggering it here works) {  }

but

if (triggering it here doesn't) {  }

0 Likes

#4

and here is it not working

0 Likes

#5

Not sure which language you are using, but you can just install “Chain Of Command” and add this keybinding, which just always triggers autocompletion:

    {
        "keys": ["tab"], "command": "chain",
        "args": {
            "commands": [
                ["insert_snippet", {"contents": "this->"}],
                ["auto_complete"]
            ]
        },
        "context":
        [
            // { "key": "selector", "operand": "source.yourlang" },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\$$"},
        ],
    },
1 Like

#6

Thanks for replying so quickly.

I am using php, I copied your key binding but unfortunately it isn’t working.

0 Likes

#7

You may need to disable (outcomment/remove) your keybinding, because it takes precedence.

0 Likes

#8

my screen capture doesn’t have a high enough FPS to catch it, but when I run it inside the

if ( ) { }

it seems to work it very quickly flashes up a popup box but it goes away and it’s too quick to read what it prompts me with.

0 Likes

#9

Then I assume its a package hidding the auto complete again, are you using SublimeCodelntel and/or Anaconda_php?

0 Likes

#10

I’m using CodeComplice.

Thanks for the help :slight_smile:

0 Likes

#11

Not sure why this happens. My other idea would be to reopen the auto complete with a little delay and check what happens then.

0 Likes

#12

How would I go about doing that?

0 Likes

#13

Select Tools > Developer > New Plugin… and paste (and save in the Package/User folder as auto suggested):

from functools import partial
import sublime
import sublime_plugin


class RunCommandWithDelayCommand(sublime_plugin.WindowCommand):
    def run(self, command, args={}, delay=100):
        sublime.set_timeout(partial(self.window.run_command, command, args), delay)

then change you kbd to (play around with the value of “delay”):

    {
        "keys": ["tab"], "command": "chain",
        "args": {
            "commands": [
                ["insert_snippet", {"contents": "this->"}],
                ["run_command_with_delay", {"command": "auto_complete", "delay": 200}]
            ]
        },
        "context":
        [
            // { "key": "selector", "operand": "source.yourlang" },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\$$"},
        ],
    },
0 Likes

#14

unfortunately the popup was populated with methods which aren’t related to the app.

I’m so confused :weary:

0 Likes

#15

Seems they have a weird way for auto completeion, then change it from ["run_command_with_delay", {"command": "auto_complete", "delay": 200}] to ["run_command_with_delay", {"command": "code_intel_auto_complete", "delay": 200}] (auto_complete to code_intel_auto_complete)

0 Likes

#16

I replaced the line with.

["run_command_with_delay", {"command": "code_intel_auto_complete", "delay": 200}]

but now I don’t get any autocomplete popup.

Thanks for helping it means a lot.

0 Likes

#17

Sorry I don’t know it further, my last idea would be to add the api completions only argument: ["run_command_with_delay", {"command": "auto_complete", "args": {"api_completions_only": true}, "delay": 200}]

1 Like

#18

Hi. Unfortunately that didn’t work either but I would like to thank you for all the help you provided me I appreciate it.

0 Likes

#19

It seems it is doing raw word completion.

How do you get these autcompletion? Do you use some third part package as Sublime Code Intel? Which packages do you have installed on Sublime Text? Perhaps this would be an issue for https://github.com/SublimeTextIssues/Core/issues or https://github.com/sublimehq/Packages/issues

0 Likes