vsc extension 入门尝试

开始 & 安装

文档

https://code.visualstudio.com/api/get-started/your-first-extension

https://github.com/microsoft/vscode-extension-samples

install & Run

1
2
npm install -g yo generator-code
yo code

选择你希望的选项

code ./新建目录

F5启动

Ctrl+Shift+P输入Hello world回车

当你修改了代码后,在新打开的窗口Ctrl+Shift+P再输入Reload Window就重新加载了代码

解剖

package.json

  • 注册 onCommand Activation Event:onCommand:extension.helloWorld ,so the extension becomes activated when user runs the Hello World command.

  • 使用contributes.commands Contribution Point 来让Hello World命令 在Command Palette 可用,并且绑定到命令idextension.helloWorld

  • 使用commands.registerCommand的VS Code API绑定到已注册的命令ID extension.helloWorld

  • Activation Events: events upon which your extension becomes active.

  • Contribution Points: static declarations that you make in the package.json Extension Manifest to extend VS Code.

  • VS Code API: 代码中API,可以在你的extension代码中调起

其它配置文件

  • launch.json used to configure VS Code Debugging
  • tasks.json for defining VS Code Tasks
  • tsconfig.json consult the TypeScript Handbook

package.json

vsc使用 <publisher>.<name>作为一个插件的unique ID

tree-view

emmmmmm 看了一会代码 发现有文档 https://code.visualstudio.com/api/extension-guides/tree-view

直接看文档吧…