如何在 VS Code 中为用户片段编写多行描述
How to write a multi-line description for user snippets in VS Code
我尝试在 VS Code 中为 Pascal 创建自己的用户代码段。
运行良好,显示了我写的多行描述
正确。
但是过了一段时间,比如一个月,多行的描述就不再有效了。
问题可能出在多行描述的代码上,因为只有一行的描述仍然有效并且显示正确。
但是,多行描述未正确显示,并被替换为 {0} 而不是我写的描述。
多行描述是这样显示的:
没有我的描述,而是 {0},我不知道为什么,因为它在一个月前运行良好。
这是我使用的代码:
{
"SetValue":{
"prefix": "SetValue",
"body": "SetValue(${1:val:Integer}, ${2:id:Integer});",
"description": [
"Parameter:\r",
" val...desc\r",
" id....desc\r",
"\r",
"result:\r",
" 0 : false desc\r",
" 1 : true desc\r"
]
}
}
我希望我表达的意思可以理解,你可以帮我解决这个问题。感谢您的关注!
我无法解释为什么它会改变,但它似乎只接受一个字符串(而不是一组字符串)。但是你仍然可以建立一个字符串 - 有点难看但它有效:
"description":
"Parameter:\rval...desc\r id....desc\r\rresult:\r 0 : false desc\r 1 : true desc\r"
现在它将如您所愿地显示在建议面板中。
编辑:v1.31 修复了此问题,因此您可以使用一组字符串而不是一个长字符串。 Snippet descriptions
When authoring snippets with long descriptions, in the past you were
forced to write a long single string. There was no support for using
an array as you could for body. This has now changed and long
descriptions can be written using string arrays.
{
"prefix": "happy",
"body": "#Happy Coding!",
"description": [
" First Line", // note the spaces after the opening parens
" Second Line",
" Third Line"
]
}
感谢@Ben 的质疑,我发现了一个错误并进行了修复。
"description": [
"First Line", // won't work
"Second Line",
"Third Line"
]
"description": [
" First Line", // will work
" Second Line",
" Third Line"
]
如果前导 space 仅在 "First Line"
上,它将不起作用,但如果 " Second Line"
[=40] 上有前导 space,它将起作用=]或" Third Line"
。所以我建议只在所有行上做一个前导 space。
或者更好:
"description": [
"First line", // no leading spaces
"Second line",
"Third line",
"\r" // just adding this makes it work, or \n
]
OP 的示例之所以有效,是因为他的描述中有一些前导 space 和 "\r"
。
我尝试在 VS Code 中为 Pascal 创建自己的用户代码段。 运行良好,显示了我写的多行描述 正确。 但是过了一段时间,比如一个月,多行的描述就不再有效了。 问题可能出在多行描述的代码上,因为只有一行的描述仍然有效并且显示正确。 但是,多行描述未正确显示,并被替换为 {0} 而不是我写的描述。
多行描述是这样显示的:
没有我的描述,而是 {0},我不知道为什么,因为它在一个月前运行良好。
这是我使用的代码:
{
"SetValue":{
"prefix": "SetValue",
"body": "SetValue(${1:val:Integer}, ${2:id:Integer});",
"description": [
"Parameter:\r",
" val...desc\r",
" id....desc\r",
"\r",
"result:\r",
" 0 : false desc\r",
" 1 : true desc\r"
]
}
}
我希望我表达的意思可以理解,你可以帮我解决这个问题。感谢您的关注!
我无法解释为什么它会改变,但它似乎只接受一个字符串(而不是一组字符串)。但是你仍然可以建立一个字符串 - 有点难看但它有效:
"description":
"Parameter:\rval...desc\r id....desc\r\rresult:\r 0 : false desc\r 1 : true desc\r"
现在它将如您所愿地显示在建议面板中。
编辑:v1.31 修复了此问题,因此您可以使用一组字符串而不是一个长字符串。 Snippet descriptions
When authoring snippets with long descriptions, in the past you were forced to write a long single string. There was no support for using an array as you could for body. This has now changed and long descriptions can be written using string arrays.
{
"prefix": "happy",
"body": "#Happy Coding!",
"description": [
" First Line", // note the spaces after the opening parens
" Second Line",
" Third Line"
]
}
感谢@Ben 的质疑,我发现了一个错误并进行了修复。
"description": [
"First Line", // won't work
"Second Line",
"Third Line"
]
"description": [
" First Line", // will work
" Second Line",
" Third Line"
]
如果前导 space 仅在 "First Line"
上,它将不起作用,但如果 " Second Line"
[=40] 上有前导 space,它将起作用=]或" Third Line"
。所以我建议只在所有行上做一个前导 space。
或者更好:
"description": [
"First line", // no leading spaces
"Second line",
"Third line",
"\r" // just adding this makes it work, or \n
]
OP 的示例之所以有效,是因为他的描述中有一些前导 space 和 "\r"
。