VSCODE 扩展开发 02
此文章的 撰写时间 撰写日期 绝对有问题
此文章的部分图片可能无法加载。这是因为大概这一版的博客搭建在云服务器上所以图片没有用图床
为什么呢?难道云服务器流量不要钱吗?白嫖图床不好吗?
概要
主要借助右键菜单和快捷键讲解一下package.json
.
没错我就是标题党
添加右键菜单和快捷键
我们在package.json
中找到contributes
,
然后可以看到 1
2
3
4
5
6
7
8"contributes": {
"commands": [
{
"command": "extension.sayHello",
"title": "Hello World"
}
]
}command
数组的后面加一个,
(英文逗号)
然后写如下代码 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27"contributes": {
"commands": [
{
"command": "extension.sayHello",
"title": "Hello World"
}
],
//这个keybindings数组就是快捷键绑定了
"keybindings": [
{
"command": "name.helloWorld", //要绑定的命令名字
"key": "ctrl+f10", //按下ctrl f10时执行name.helloworl命令
"mac": "cmd+f10", //mac下快捷键 (mac os x的ctrl键叫cmd键
"when": "editorFocus" //什么时候,editor focus 即编辑器获得焦点 也就是光标在编辑器上
}
],
//菜单
"menus": { //注意这里不是[而是{了,表示不是数组而是对象
"editor/context":[
{
"when": "editorFocus", //同上
"command": "name.helloWorld", //右键菜单命令
"group": "navigation" //显示位置,"navigation"是最上面
}
]
}
} 这样我们就能看到右键菜单了,点击hello
world命令或ctrl+f10
great.
packag.json详细分析
1 | { |