问题
I tried to create my own user snippet for pascal in VS Code. It worked fine and the multi-line descriptions I wrote were displayed correctly. But after a while, like a month, the descriptions with multiple lines aren't working anymore. The problem may be the code for the multi-line descriptions because descriptions with only one row still works and displays correct. However the multi-line descriptions aren't displayed correctly and get replaced with a {0} instead of the description I wrote.
This is how the multi-line descriptions are displayed:
Instead of my description there is a {0} and I don't know why because it worked fine a month ago.
This is the code I used:
{
"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"
]
}
}
I hope I have expressed myself understandably and you may can help me with this problem. Thanks for your attention!
回答1:
I can't explain why it changed but it appears to accept only one string (and not an array of strings). But you can still build up one string - a little ugly but it works:
"description":
"Parameter:\rval...desc\r id....desc\r\rresult:\r 0 : false desc\r 1 : true desc\r"
Now it will display in the suggestions panel as you expect.
Edit: v1.31 fixed this so you can use an array of strings rather than one long string. 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",
"Second Line",
"Third Line"
]
}
来源:https://stackoverflow.com/questions/53296517/how-to-write-a-multi-line-description-for-user-snippets-in-vs-code