Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make user snippets work inside strings: vscode

I've made own user snippet code for javascript

"inner backquote concat variable" : {
    "prefix": "$",
    "body": "\\${$1}",
    "description": "concat variable with backquote sting"
}

I want that snippet to work inside backquote string or single quote string when I press '$' like this

snippetwork.gif

but it does not work when inside a string.

heloquote.gif

How do make the snippet work inside a string?

like image 889
Ridwan Maulana Tanjung Avatar asked Sep 19 '19 10:09

Ridwan Maulana Tanjung


2 Answers

Add the following snippet in settings.json

"editor.quickSuggestions": {
        "strings": true
    },

It makes all snippets/emmets working on strings.

like image 127
Ridwan Maulana Tanjung Avatar answered Sep 23 '22 07:09

Ridwan Maulana Tanjung


Together with @Ridwan's suggestion your example still wouldn't work because you have no space between $ and the backtick - so vscode does not see the $ as your prefix, it is just part of a larger string and so doesn't look like a unique trigger it is expecting.

You can see this with any snippet in or out of a string (using your snippet):

snippet prefix demo

So the snippet prefix must "stand alone" so to speak so it can be recognized as a separate trigger. And that includes not being next to a " or backtick. They must have spaces around them.

like image 22
Mark Avatar answered Sep 24 '22 07:09

Mark