Sublime Forum

JS Template literals (string interpolation) snippet not working as expected

#1

Consider the following snippet…

<snippet>
  <content><![CDATA[\${${1:someVar}}]]></content>
  <tabTrigger>$</tabTrigger>
  <description>JS - String Interpolation</description>
  <scope>source.js</scope>
</snippet>

The idea is to create a snippet which inserts ${someVar} into a JS document when you autocomplete on the $ key.

It works fine on its own in a JS document. However whenever it’s within back ticks as required for JS Template Literals it autocompletes to <1></1>.

For reference it also autocompletes to <1></1> in single or double quotes.

Why is this happening and more importantly how can I fix the snippet so it autocompletes to ${someVar} within back ticks?

0 Likes

#2

I suspect a third party package or something is interfering - it works fine for me on the JavaScript syntax bundled with ST build 3184

0 Likes

#3

How do I track that down? Is it a matter of removing all my packages and adding them one by one until it breaks? Or is there a clever way to find out what is doing it?

What decides precedence in autocomplete execution?

0 Likes

#4

Just post a list of installed packages and it’s likely one of them will jump out at us.

I suspect that what is happening is that you’re using a third-party JavaScript syntax that’s highlighting the inside of the template string as HTML. This is causing HTML autocompletion to be used inside the template string.

0 Likes

#5

I went through the remove package pain :wink:

It’s Emmet. Removing it stops the problem from happening. This is particularly strange as Emmet shouldn’t effect anything in the JS scope.

Any ideas?

0 Likes

#6

It’s Emmet. Removing it stops the problem from happening. This is particularly strange as Emmet shouldn’t effect anything in the JS scope.

This sounds like a fairly typical experience with Emmet.

0 Likes

#7

Yeah. Have raised an issue but it doesn’t look like the plugin gets a lot of love anymore. Guess I’ll just choose another autocomplete trigger.

0 Likes