当前位置:网站首页>如何自己动手写一个vscode插件,实现插件自由!
如何自己动手写一个vscode插件,实现插件自由!
2022-06-12 21:29:00 【锦鲤儿】
一、环境搭建
1、安装Visual Studio Code
2、安装Node.js
3、安装Git
4、安装生产插件代码的工具:Yeoman和VSCode Extension generator
- 打开cmd命令行工具,执行以下命令安装Yeoman和VSCode Extension generator
npm install -g yo generator-code
二、创建工程
1、在cmd命令行中执行以下命令,自动生成一个工程的基本代码
yo code

2、选择项解释:
- 选择编写扩展的语言,我选择的是JavaScript
- 输入扩展名称
- 输入一个标志(我直接选择的默认)
- 输入对这个扩展的描述
- 在 jsconfig.json 中是否启用 javascript 类型检查
- 是否绑定git仓库
- 使用哪个包管理器(我选择的npm)
3、目录说明
4、结果展示
- 项目按F5或者vscode菜单栏:“运行–启动调试”,之后会开启一个新的工作区窗口
- 快捷键Ctrl+shift+p,输入hello word,就会弹出对应的内容


三、修改代码,做一个统计选择代码的字符数
1、在package.json中添加相关代码
2、在extension.js文件中添加相关代码
3、外部文件wordCounter.js文件
class WordCounter {
constructor(_vscode) {
//构造函数,传入vscode对象
this.vscode = _vscode;
this.init();
}
init() {
//初始化
var vscode = this.vscode;
var StatusBarAlignment = vscode.StatusBarAlignment;
var window = this.vscode.window;
//statusBar,是需要手动释放的
this.statusBar = window.createStatusBarItem(StatusBarAlignment.Left);
//跟注册事件相配合的数组,事件的注册,也是需要释放的
var disposable = [];
//事件在注册的时候,会自动填充一个回调的dispose到数组
window.onDidChangeTextEditorSelection(this.updateText, this, disposable);
//保存需要释放的资源
this.disposable = vscode.Disposable.from(disposable);
this.updateText();
this.statusBar.show();
}
updateText() {
var window = this.vscode.window;
this.editor = window.activeTextEditor;
var content = this.editor.document.getText();
var len = content.replace(/[\r\n\s]+/g, '').length;
this.statusBar.text = `已经敲了${
len}个字符了`;
}
dispose() {
//实现dispose方法
this.disposable.dispose();
this.statusBar.dispose();
}
}
module.exports = WordCounter;
边栏推荐
- Oracle 19c 安装文档
- 一款高颜值的MySQL管理工具
- Li Mu [practical machine learning] 1.4 data annotation
- Insert sort
- Zip压缩解压缩
- Pointer and array & pointer and const & struct and Const
- The ifeq, filter and strip of makefile are easy to use
- Data visualization - biaxial comparison effect
- RestTemplate的@LoadBalance注解
- Cv2.lut() (populates the output array with values from the lookup table)
猜你喜欢

ASCII code comparison table

结构体知识点all in

Teambition 协作应用心得分享|社区征文

#141 Linked List Cycle

The year of the outbreak of financial innovation! All dtinsight products of kangaroo cloud data stack have passed the special test of Xinchuang of ICT Institute

Graphics2D类基本使用

New product release Junda intelligent integrated environmental monitoring terminal

Lintcode:127. Topology sorting

Structure knowledge points all in
![(4) Pyqt designs and implements the [factory production management system] order page - add, delete, modify and query (including source code analysis)](/img/71/47698193c0eb1a7fa39ceceb05b711.jpg)
(4) Pyqt designs and implements the [factory production management system] order page - add, delete, modify and query (including source code analysis)
随机推荐
Principales étapes de la collecte des ordures à Zgc
#141 Linked List Cycle
drf 接收嵌套数据并创建对象, 解决:drf NOT NULL constraint failed
Research Report on market supply and demand and strategy of hydraulic operating table industry in China
Two sentences to clarify JS throttling and anti shake
Data visualization - histogram
The service did not report any errors MySQL
atoi超强解析
A high-value MySQL management tool
Mxnet record IO details
冒泡排序
nn. PReLU(planes)
Deep Hough voting for 3D object detection in point clouds
金融信创爆发年!袋鼠云数栈DTinsight全线产品通过信通院信创专项测试
gzip压缩解压缩
同花顺能开户吗,在同花顺开户安全么
Pointer and array & pointer and const & struct and Const
Teamwork collaboration application experience sharing | community essay solicitation
zgc 并发标识和并发转移阶段的多视图地址映射
The year of the outbreak of financial innovation! All dtinsight products of kangaroo cloud data stack have passed the special test of Xinchuang of ICT Institute