启动配置片段中的变量

Variables in launch configuration snippet

我的 launch.json 片段有问题。当我使用它时,它会从变量名中丢失 ${}

代码段如下所示:

    "Robot Framework: Launch selected test": {
        "prefix": "Robot Framework: Launch selected test",
        "body": [
            "{",
            "    \"type\": \"robotframework-lsp\",",
            "    \"name\": \"Robot Framework: Launch selected test\",",
            "    \"request\": \"launch\",",
            "    \"cwd\": \"${workspaceFolder}\",",
            "    \"target\": \"${file}\",",
            "    \"terminal\": \"none\",",
            "    \"env\": {},",
            "    \"args\": [\"-t\",\"${selectedText}\"],",
            "    \"internalConsoleOptions\": \"openOnSessionStart\"",
            "}"
        ],
        "description": "Robot Framework: Launch selected test"
    }

我粘贴的时候是这样的:

    {
        "type": "robotframework-lsp",
        "name": "Robot Framework: Launch selected test",
        "request": "launch",
        "cwd": "workspaceFolder",
        "target": "file",
        "terminal": "none",
        "env": {},
        "args": ["-t", "selectedText"],
        "internalConsoleOptions": "openOnSessionStart"
    }

美元符号和括号在 cwdtargetargs 行中丢失。 有什么办法可以防止这种形式的发生吗?

@rioV8 回答了我的问题。答案取自 vscode 文档:

To have a variable in the pasted script, you need to escape the '$' of the $variable name so that it isn't parsed by the snippet expansion phase.

    "Robot Framework: Launch selected test": {
        "prefix": "Robot Framework: Launch selected test",
        "body": [
            "{",
            "    \"type\": \"robotframework-lsp\",",
            "    \"name\": \"Robot Framework: Launch selected test\",",
            "    \"request\": \"launch\",",
            "    \"cwd\": \"\${workspaceFolder}\",",
            "    \"target\": \"\${file}\",",
            "    \"terminal\": \"none\",",
            "    \"env\": {},",
            "    \"args\": [\"-t\",\"\${selectedText}\"],",
            "    \"internalConsoleOptions\": \"openOnSessionStart\"",
            "}"
        ],
        "description": "Robot Framework: Launch selected test"
    }