R. Tanjung
R. Tanjung

Reputation: 458

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?

Upvotes: 10

Views: 2727

Answers (2)

Mark
Mark

Reputation: 181299

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.

Upvotes: 2

R. Tanjung
R. Tanjung

Reputation: 458

Add the following snippet in settings.json

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

It makes all snippets/emmets working on strings.

Upvotes: 13

Related Questions