如何以编程方式添加片段?
How do I add a snippet programmatically?
我们通过键绑定和片段 json 文件提供了一些自定义片段作为 VS Code 扩展的一部分:
{
"key": "ctrl+shift+i",
"mac": "cmd+shift+i",
"command": "editor.action.insertSnippet"
},
...
"snippets": [
{
"language": "xml",
"path": "./snippets/xml.json"
}
]
我们想要一个按钮,用于在当前光标位置向编辑器添加一个特定片段。
如何以编程方式调用 "editor.action.insertSnippet" 在 用户选择代码段后的部分?
您可以 运行 通过 vscode.commands.executeCommand
注册的任何命令。另见 vscode namespace API.
我发布了this issue on the vscode repo。
jrieken responded with the following reply:
The insertSnippet-command accepts an argument which is either the name of a snippet or a snippet itself. So, either { snippet: "console.log()[=10=]"} for an inline snippet or { langId: "csharp", name: "myFavSnippet" } referencing an existing snippet.
我们通过键绑定和片段 json 文件提供了一些自定义片段作为 VS Code 扩展的一部分:
{
"key": "ctrl+shift+i",
"mac": "cmd+shift+i",
"command": "editor.action.insertSnippet"
},
...
"snippets": [
{
"language": "xml",
"path": "./snippets/xml.json"
}
]
我们想要一个按钮,用于在当前光标位置向编辑器添加一个特定片段。
如何以编程方式调用 "editor.action.insertSnippet" 在 用户选择代码段后的部分?
您可以 运行 通过 vscode.commands.executeCommand
注册的任何命令。另见 vscode namespace API.
我发布了this issue on the vscode repo。
jrieken responded with the following reply:
The insertSnippet-command accepts an argument which is either the name of a snippet or a snippet itself. So, either { snippet: "console.log()[=10=]"} for an inline snippet or { langId: "csharp", name: "myFavSnippet" } referencing an existing snippet.