Visual Studio代码段无效控制字符

时间:2017-09-21 13:23:12

标签: visual-studio-code code-snippets

我有以下用户代码:

{
/*
    // Place your snippets for JavaScript React here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    "Print to console": {
        "prefix": "log",
        "body": [
            "console.log('$1');",
            "$2"
        ],
        "description": "Log output to console"
    }
*/
    "Small comment": {
        "prefix": "//=",
        "body": [
            "// ===================================",
            "// ${1:COMMENT}",
            "// ==================================="
        ],
        "description": "Small comment"
    }
}

我在第二个身体线上收到以下错误:

Invalid characters in string. Control characters must be escaped.

我认为${1:somestring}是一个有效的占位符。我在构建这个片段时做错了什么?

1 个答案:

答案 0 :(得分:0)

我只是在寻找答案时发现了这个问题,我使用了代码段生成器,因此假设每个格式都相同,但是却没有想到我会粘贴带有选项卡的代码。

删除选项卡并使用空格代替格式化,这已为我修复。

希望这会有所帮助。 :)