在 vscode 片段中执行函数
是否可以在代码片段扩展期间运行函数?
javascript.json - vscode 代码片段文件:
function add() {
return 2+2;
}
"Print to console": {
"prefix": "log",
"body": [
"console.log("Addition", add());"
],
"description": "Log output to console"
}
index.js - 项目文件:
// I wrote "log" and intellisense currently provides
console.log("Addition", add());
// But I need
console.log("Addition", 4);
明显的原因可能是代码片段是一个 json 文件,它不是一个 javascript 文件,所以它不能运行代码,只需用光标位置 $1、$2 等显示语法。
或者可以通过 vscode 插件吗?
Is it possible to run a function during expansion of snippet?
javascript.json - vscode snippet file:
function add() {
return 2+2;
}
"Print to console": {
"prefix": "log",
"body": [
"console.log("Addition", add());"
],
"description": "Log output to console"
}
index.js - project file:
// I wrote "log" and intellisense currently provides
console.log("Addition", add());
// But I need
console.log("Addition", 4);
The obvious reason might be snippet is a json file, it's not a javascript file so it can't run code, just show syntax as it with cursor positions $1, $2 etc.
Or is it possible through a vscode plugin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按照 rioV8 建议使用 Hypersnips vscode 扩展,我有一个可用的 hsnips 可能会对您有所帮助。
all.hsnips 或 javascript.hsnips:
Using Hypersnips vscode extension as suggested by rioV8, I've a working hsnips which might help you.
all.hsnips OR javascript.hsnips: