对于 sn-ps,您使用 scope 参数:
"FrontMatter": {
"scope": "csharp", // put your language identifier here
"prefix": "frontmatter",
"body": [
"...",
]
},
如果该范围不够具体,请改用键绑定,这样可以提供更多的具体性。
scope 不能接受像editorTextFocus && !editorReadonly && resourceExtname =~ /\\.csproj/ 这样的内容。
----------- 对于键绑定,您可以使用以下 -----------
"when": "editorTextFocus && !editorReadonly && resourceExtname =~ /\\.csproj/ && editorLangId == csharp"
见when clause operator
=~ 运算符允许在右侧使用正则表达式,因此您可以这样做
resourceExtname =~ /\\.(html|css|scss) 限制为这三个扩展。在我看来,您确实必须在扩展程序本身之前专门添加 .,但这似乎很奇怪,但您似乎这样做了。
name 引用 sn-p 的键绑定 - sn-p 本身在您的以下 sn-p 文件之一中定义:
{
"key": "alt+l",
"command": "editor.action.insertSnippet",
"args": {
"name": "My groovy comment style"
},
"when": "editorTextFocus && !editorReadonly && resourceExtname =~ /\\.csproj/ && editorLangId == csharp"
},
或在键绑定中使用实际的 sn-p 正文:
{
"key": "alt+m",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus && !editorReadonly && resourceExtname =~ /\\.csproj/ && editorLangId == csharp",
"args": {
"snippet": "${TM_SELECTED_TEXT/([a-z])([A-Z]+(?=[A-Z]))|([A-Z][a-z])/$1 ${2:/downcase}${3:/downcase}/g}"
}
},