how to make user snippets work inside strings: vscode

≯℡__Kan透↙ 提交于 2020-06-16 02:50:24

问题


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

but it does not work when inside a string.

How do make the snippet work inside a string?


回答1:


Add the following snippet in settings.json

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

It makes all snippets/emmets working on strings.




回答2:


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):

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.



来源:https://stackoverflow.com/questions/58008872/how-to-make-user-snippets-work-inside-strings-vscode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!