user8184393
user8184393

Reputation:

VScode use built-in variables, like $TM_FILENAME_BASE and others, in snippet choices

I have a question about snippets and choices. I would like t0 use variables in choices. Is this possible?

"test": {
"body": ["${1|choice1,choice2,$TM_FILENAME_BASE|}"],
"desciption": "test",
"prefix": "test"
}

Has somebody a solution for me?

Upvotes: 0

Views: 365

Answers (2)

Mark
Mark

Reputation: 182771

There is an issue filed on this: Support Snippet Variables in Snippet Enums.

Which is now a candidate for the Backlog list - so go and upvote the issue if you would like to see this implemented natively.

Upvotes: 0

Zcorn Zhou
Zcorn Zhou

Reputation: 11

Unfortunately, it is impossible to include variables in snippets. However, there is an alternative. My example:

    "Now": {
        "prefix": "NOW",
        "body": "${CURRENT_HOUR}:${CURRENT_MINUTE}${1| TODAY, |}",
        "description": "Now"
    },
    "Today's Date": {
        "prefix": "TODAY",
        "body": [
          "$CURRENT_DAY_NAME_SHORT, $CURRENT_MONTH_NAME_SHORT $CURRENT_DATE, $CURRENT_YEAR"
        ],
        "description": "Today's Date"
      }

, by which you can expand the "TODAY" snippet by tab once more.

Upvotes: 1

Related Questions