Sublime Forum

How to ignore curly brace in svelte snippets

#1

Say I want to make a snippet for:

/* valid svelte */
{#await promise}
  
{/await}

The XML will look like:

<!-- ST Snippet XML -->
<content><![CDATA[
{#await ${1:promise}}
    $0
{/await}
]]></content>

But ST would take curly braces as a tab selection. So after few tabs it’s gone:

/* invalid svelte */
#await promise
  
{/await}

It loses necessary curly braces.

Plus that, this snippet wouldn’t appear automatically until I tab or ^+ Space. Is this normal?

Full snippet XML below:

<snippet>
    <content><![CDATA[
{#await ${1:promise}}
    $0
{/await}
]]></content>
	<tabTrigger>await</tabTrigger>
	<scope>text.html.svelte</scope>
	<description>Svelte await</description>
</snippet>

by Pier Bover

0 Likes

#2

The snippet is fully applied including curly braces using ST4122 on Windows 11. I can’t reproduce it loosing them, even not when running ST in SAFE MODE.

this snippet wouldn’t appear automatically

ST disables auto-completions in text scopes by default.

If you want to see the auto completion popup you might want to modify syntax specific auto_complete_selector.

The following example enables auto completions everywhere but within comments and strings.

{
	"auto_complete_selector": "- comment - string",
}
1 Like

#3

Thanks for your help @deathaxe

Do you mean you don’t have the same problem? curly brackets don’t disappear when you are tabbing?
That’s really strange, and I don’t know how to fix this problem for me :confused:

0 Likes

#4

I’ve tried with both ST3210 and ST4122. Both add curly braces correctly.

You could try to escape the curly braces though.

<snippet>
	<content><![CDATA[
\{#await ${1:promise}\}
    $0
\{/await\}
]]></content>
	<tabTrigger>await</tabTrigger>
	<scope>text.html.svelte</scope>
	<description>Svelte await</description>
</snippet>
0 Likes

#5

Thanks @deathaxe! I sort of figured it out.
If I activate the snippet with full tab trigger, the curly braces disappear.

for example, given that tab trigger is <tabTrigger>await</tabTrigger>

await /* tabs */

/* tabs again
#await promise
    
{/await}
*/

If I open up auto completion on a substring of the tab trigger, curly braces remain.

aw /* tabs */

/* tabs again
{#await promise}
    
{/await}
*/

The problem is solved in a way, but I still want to know why this way.
Escaping doesn’t make much difference by the way .

0 Likes

#6

This is still stange. It doesn’t behave like this on my machine.

0 Likes