microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.99k stars 29.19k forks source link

User Snippet cannot escape $ #25814

Closed Morgy93 closed 7 years ago

Morgy93 commented 7 years ago
Extension Author Version
xml DotJoshJohnson 1.7.0
gc-excelviewer GrapeCity 1.1.15
beautify HookyQR 1.0.2
composer ikappas 0.5.0
format-indent Kasik96 1.3.0
vscode-docker PeterJausovec 0.0.13
vscode-icons robertohuertasm 7.6.0
cordova-tools vsmobile 1.2.7 ;

Call me crazy, but i am not able to escape $ character:

    "REIP": {
        "prefix": "REIP",
        "body": [
            "if ($_SERVER['REMOTE_ADDR'] == \"1234\") {",
            "    $0",
            "}"
        ],
        "description": "if IP == my"
    }

Things I tried so far:

"if (\$_SERVER['REMOTE_ADDR'] == \"1234\") {", "Invalid escape character in string"

"if ($_SERVER['REMOTE_ADDR'] == \"1234\") {", Not even shown +: "if ($$_SERVER['REMOTE_ADDR'] == \"1234\") {", The cursor goes right between SERVER and ['REMOTE_ADDR'] (I don't want it there)

"if (${1:$}_SERVER['REMOTE_ADDR'] == \"1234\") {", It's a variable then and I also don't want the cursor there.

I don't know other legit ways to get around this .. any help?

Morgy93 commented 7 years ago

Of course I found a way right after posting this:

                "body": [
            "if (\\$_SERVER['REMOTE_ADDR'] == \"1234\") {",
            "    $0",
            "}"
        ],

Works, but doesn't look right.

I leave it open so that someone can confirm if this is intended or not.

jrieken commented 7 years ago

https://github.com/Microsoft/vscode/issues/25814#issuecomment-298842679 is correct. There is double escaping necessary: (1) escape $ in the snippet-syntax with an backslash \ and (2) escape \ with another backslash in the json-syntax. That make two backslashes