【发布时间】:2018-10-18 13:16:16
【问题描述】:
https://code.visualstudio.com/docs/editor/userdefinedsnippets#_placeholdertransform
我的目标是在插入的 sn-p 上下文中自动设置类名。 VSCode 本身不支持类名或方法名,但确实支持文件名。
我的文件名与类名非常相似:
foo-bar.ts 为class FooBar。
这是我当前的代码 sn-p,其中我可以使用 VSCode 提供的本机“大写”语法将 "foo-bar" 转换为 "Foo-bar"。
TM_FILENAME_BASE 是一个本机变量,它提取不带扩展名的文件名:
"My Snippet": {
"scope": "typescript",
"prefix": "snippet",
"body": [
"${1}() {",
"\treturn this.get(${TM_FILENAME_BASE/(.*)/${1:/capitalize}/}.FIELD.${3});",
"}",
"",
"$0"
],
"description": "Creates a function wrapper for a model's attribute."
}
我想将“foo-bar”转换为“FooBar”。
【问题讨论】:
标签: visual-studio-code code-snippets vscode-snippets