VS 代码片段替换(转换)适用于变量而不是占位符
VS code snippet substitution (transform) works with variables not placeholders
vs 代码应该支持变电站,即在用户定义的片段中进行转换。但它只适用于(内置)变量而不适用于占位符。
请参阅以下代码段:
"substitution test" : {
"prefix" : "abc",
"body": [
"${TM_FILENAME}",
"${TM_FILENAME/^([^.]+)\..+$//}",
"${TM_FILENAME/^([^.]+)\..+$/${1:/capitalize}/}",
"${TM_FILENAME/^([^.]+)\..+$/${1:/upcase}/}",
"${2:showMeInAllCapsWhenReferenced}",
"${2/upcase}"
]
}
第 1-4 行的输出符合预期:
users.actions.ts
users
Users
USERS
第 5 行有一个占位符,我在第 6 行再次引用它。我希望它显示两次,一次是在我键入时显示,一次是全部大写。例如:
fooFoo
FOOFOO
但实际输出是
showMeInAllCapsWhenReferenced
${2/upcase}
substitution/transformation 个引用占位符(如我键入的那样)是否可能?
你的最后两行应该是:
"${2:showMeInAllCapsWhenReferenced}",
"${2/(.*)/${1:/upcase}/}"
在最后一个选项卡之后实际应用了转换(因此从技术上讲 "as you type" 不是占位符替换)。
The inserted text is matched with the regular expression and the match
or matches - depending on the options - are replaced with the
specified replacement format text.
所以你不能像你在第 5 行尝试做的那样只使用 :/upcase 没有正则表达式捕获 - 它只能转换正则表达式 match.
查看 grammar 部分:
transform ::= '/' regex '/' (format | text)+ '/' options
format ::= '$' int | '${' int '}'
| '${' int ':' '/upcase' | '/downcase' | '/capitalize' '}'
| '${' int ':+' if '}'
| '${' int ':?' if ':' else '}'
| '${' int ':-' else '}' | '${' int ':' else '}'
我们看到 :/upcase 必须跟在正则表达式之后。 ("format",其中大写字母为 1,必须在 "transform" 中跟在 "regex" 之后。)
vs 代码应该支持变电站,即在用户定义的片段中进行转换。但它只适用于(内置)变量而不适用于占位符。
请参阅以下代码段:
"substitution test" : {
"prefix" : "abc",
"body": [
"${TM_FILENAME}",
"${TM_FILENAME/^([^.]+)\..+$//}",
"${TM_FILENAME/^([^.]+)\..+$/${1:/capitalize}/}",
"${TM_FILENAME/^([^.]+)\..+$/${1:/upcase}/}",
"${2:showMeInAllCapsWhenReferenced}",
"${2/upcase}"
]
}
第 1-4 行的输出符合预期:
users.actions.ts
users
Users
USERS
第 5 行有一个占位符,我在第 6 行再次引用它。我希望它显示两次,一次是在我键入时显示,一次是全部大写。例如:
fooFoo
FOOFOO
但实际输出是
showMeInAllCapsWhenReferenced
${2/upcase}
substitution/transformation 个引用占位符(如我键入的那样)是否可能?
你的最后两行应该是:
"${2:showMeInAllCapsWhenReferenced}",
"${2/(.*)/${1:/upcase}/}"
在最后一个选项卡之后实际应用了转换(因此从技术上讲 "as you type" 不是占位符替换)。
The inserted text is matched with the regular expression and the match or matches - depending on the options - are replaced with the specified replacement format text.
所以你不能像你在第 5 行尝试做的那样只使用 :/upcase 没有正则表达式捕获 - 它只能转换正则表达式 match.
查看 grammar 部分:
transform ::= '/' regex '/' (format | text)+ '/' options format ::= '$' int | '${' int '}' | '${' int ':' '/upcase' | '/downcase' | '/capitalize' '}' | '${' int ':+' if '}' | '${' int ':?' if ':' else '}' | '${' int ':-' else '}' | '${' int ':' else '}'
我们看到 :/upcase 必须跟在正则表达式之后。 ("format",其中大写字母为 1,必须在 "transform" 中跟在 "regex" 之后。)