本帖最后由 lovzx 于 2024-10-6 09:17 编辑
效果展示
啥也不多说了,先看效果
make
make flash
make clean
dsa
按钮三件套
分别有make build、make clean 、flash以及pwd
配置原理
原理很简单,配置vscode的task任务,然后安装taskbutton插件,把task任务可视化的展示出来就可以了
1. 配置task
打开vscode的输入搜索框,输入>会有对应的提示,点击配置task,如下图所示
然后回出现推荐的task任务,随便选择一个就会跳到tasks.json里面了,把tasks对象替换成下面的内容
- "tasks": [
- {
- "type": "shell",
- "group": "build",
- "label": "pwd",
- "command": "pwd",
- "detail": "pwd",
- },
- {
- "type": "shell",
- "group": "build",
- "label": "make 编译",
- "command": "make",
- "detail": "make -j16",
- "args": [
- "-j16"
- ],
- },
- {
- "type": "shell",
- "group": "build",
- "label": "make clean",
- "command": "make",
- "detail": "make clean",
- "args": [
- "-j16",
- "clean"
- ]
- },
- {
- "type": "shell",
- "group": "build",
- "label": "make flash",
- "command": "make",
- "detail": "make flash",
- "args": [
- "-j16",
- "flash",
- "p=COM6"
- ]
- }
- ]
复制代码type:任务的类型,有shell和progress两种
group:任务的执行组,这里写build
label:任务名称
command:任务命令
args:任务的参数
以WB2为例,编译命令是make -j16,这里的make是命令,-j16是编译线程的参数,make编译代码的任务就是这样
- {
- "type": "shell",
- "group": "build",
- "label": "make 编译",
- "command": "make",
- "detail": "make -j16",
- "args": [
- "-j16"
- ],
- }
复制代码vscode默认执行路径是在当前的工作目录,如果打开的不是根目录这样是不能执行的,会提示找不到Makefile文件,这时候有两种解决方法
1. -C参数指定make的工作目录
2. 设置task的工作目录
为了方便修改可以在tasks的同级别对象里面添加options对象,配置options.cwd来设置tasks任务的工作目录
最后完整的tasks.json配置文件如下
- {
- "version": "2.0.0",
- "presentation": {
- "echo": false,
- "reveal": "always",
- "focus": true,
- "panel": "shared",
- "showReuseMessage": true,
- "clear": false
- },
- "options": {
- "cwd": "${workspaceFolder}/Ai-Thinker-WB2/applications/get-started/blink",
- // "cwd": "${workspaceFolder}/bel_demo"
- },
- "tasks": [
- {
- "type": "shell",
- "group": "build",
- "label": "pwd",
- "command": "pwd",
- "detail": "pwd",
- },
- {
- "type": "shell",
- "group": "build",
- "label": "make 编译",
- "command": "make",
- "detail": "make -j16",
- "args": [
- "-j16"
- ],
- },
- {
- "type": "shell",
- "group": "build",
- "label": "make clean",
- "command": "make",
- "detail": "make clean",
- "args": [
- "-j16",
- "clean"
- ]
- },
- {
- "type": "shell",
- "group": "build",
- "label": "make flash",
- "command": "make",
- "detail": "make flash",
- "args": [
- "-j16",
- "flash",
- "p=COM6"
- ]
- }
- ]
- }
复制代码
安装task buttons插件
在vscode插件搜索Task Buttons,可以找到下面的插件,点击安装
ps:一定要看好插件的作者spencerwmiles
配置Task Buttons
打开.vscode文件夹下面的settings.json文件(如果没有自己创建一个),把下面配置粘贴到settings.json中
- "VsCodeTaskButtons.showCounter": true,
- "VsCodeTaskButtons.tasks": [
- {
- "label": "🛠️ make build",
- "task": "make 编译",
- "tooltip": "编译代码"
- },
- {
- "label": "🧹make clean",
- "task": "make clean",
- "tooltip": "make clean"
- },
- {
- "label": "⬇️ flash",
- "task": "make flash",
- "tooltip": "烧录"
- },
- {
- "label": "pwd",
- "task": "pwd",
- "tooltip": "pwd"
- }
- ]
复制代码 VsCodeTaskButtons.showCounter配置是否显示任务按钮
label是任务按钮的名字
task是tasks.json中json的label,这个要一一对应,否则会提示找不到task
tooltip是任务提示信息,鼠标放到task buttons上会显示出来
有意思的是配置支持Emoji字符,加上图标就有内味了
文中我是以wb2项目为例的,实际可以根据自己的项目对配置文件进行适当的修改就可以用了
目前这就是我知道最方便的配置方法了,如果哪位大佬有更好的配置方法欢迎评论分享探讨
|