vscode

1. 准备

官方文档

  • nodejs

  • npm

  • yeoman npm install -g yo

  • generator-code npm install -g generator-code

  • 执行命令yo code 生成hello world demo。

  • 按f5执行,会打开一个新的window, 按ctrl + shift + p ,输入hello world 执行,弹出提示框。

2. 创建一个插件拓展hello world的三步

前提引入vscode:

import * as vscode from ‘vscode’;

1、 在package.json内的activationEvents,注册命令事件onCommand。

其他可用事件

1
2
3
"activationEvents": [
"onCommand:helloWorld"
]

2、 在package.json内,用contributes.commands字段绑定注册的命令并使其(hello world)在命令界面生效(ctrl + shift + p)。

contributes可选字段

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
"contributes": {
"commands": [
{
"command": "helloWorld",
"title": "Hello World"
}
],
// 快捷键
"keybindings": [{
"command": "helloWorld",
"key": "ctrl+alt+1",
"mac": "cmd+alt+1",
"when": "editorHasSelection"
}],
// 右键菜单环境
"menus": {
"editor/context": [
{
"when": "editorFocus",
"command": "helloWorld",
"group": "navigation"
}
]
}
}

3、 使用vscode.commands.registerCommand绑定并注册Activation Event的onCommand创建的命令事件。

其他可用api

返回
顶部