VS Code 插件清单详解

269 阅读3分钟

插件清单(Extension Mainfest)

每个 VSCode插件都需要一个位于插件目录结构根目录的清单文件来说明插件的一些描述或功能。由前面的项目剖析我们可以看出VS Code插件项目其实也是一个Node.js项目,而VS Code插件清单使用Node.js项目里面的package.json文件作为它的插件清单,同时,它还扩展了package.json的字段作为VS Code插件特有的字段,例如publlisheractivationEventscontributes等。

下面我们来详细了解下VS Code插件清单里面的具体字段及其功能。

相关字段:

名称是否必须类型细节
nameYstring插件名称,应该全部小写且无空格
versionYstringSemVer兼容版本
publisherYstring发布者名称
enginesYobject一个至少包含与插件兼容的VS Code版本匹配的vscode键的对象。不能是*。例如,^0.10.5 表示兼容最低 VS Code 版本 0.10.5
license string参阅npm文档。如果你在插件的根目录中有一个LICENSE文件,则license应该为SEE LICENSE IN <filename>
displayName string插件在Marketplace中使用的显示名称
description string简短描述你的插件是什么和做什么用的
categories string[]插件的类别,允许为以下值:[Programming Languages, Snippets, Linters, Themes, Debuggers, Formatters, Keymaps, SCM Providers, Other, Extension Packs, Language Packs, Data Science, Machine Learning, Visualization, Notebooks, Education, Testing]
keywords array可以更轻松地找到插件的一组关键字。这包含Marketplace上的其他插件标签。此列表目前仅限于5个关键字
galleryBanner object帮助格式化Marketplace标题以匹配你的图标。
preview boolean将插件设置为在Marketplace标记为预览
main string插件入口点
browser stringWeb插件的入口点
contributes object描述插件contributes的对象
activationEvents array此插件的activation events数组
markdown string控制Marketplace中使用的Markdown渲染引擎。github(默认)或standard
dependencies object运行时Nodejs依赖项,同npm的dependencies
devDependencies object开发时Nodejs依赖项,同npm的devDependencies.
scripts object与npm的scripts完全相同,但VS Code具有额外的特定字段,例如vscode:prepublish 或 vscode:uninstall.
icon string图标的路径,至少128x128像素 (Retina屏幕为256x256).
extensionPack array插件包数组,当VS Code安装这个插件时,同时也会安装此插件包中的插件,插件id格式${publisher}.${name},例如vscode.csharp

与Marketplace相关的字段

我们开发的Node.js模块包可以发布npm供大家安装使用,同样,VS Code插件也可以发布VS Code的Marketplace供大家下载安装。那么,我们如何使我们的插件能在Marketplace中被大家搜索到呢?下面,我们来了解下VS Code插件清单里面与Marketplace有关的字段,其中,包括displayNamedescriptioncategories等,此外,还有README.md

  "displayName": "Word Count",
  "description": "Markdown Word Count Example - reports out the number of words in a Markdown file.",
{
  "icon": "images/icon.png",
  "galleryBanner": {
    "color": "#C80000",
    "theme": "dark"
  }
}
{
  "license": "SEE LICENSE IN LICENSE.txt",
  "homepage": "https://github.com/microsoft/vscode-wordcount/blob/main/README.md",
  "bugs": {
    "url": "https://github.com/microsoft/vscode-wordcount/issues",
    "email": "sean@contoso.com"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/microsoft/vscode-wordcount.git"
  }
}
{
  "categories": ["Linters", "Programming Languages", "Other"]
}

插件卸载钩子

VS Code完全卸载插件时执行此脚本(即在卸载程序后重新启动VSCode时),只支持Node.js脚本

{
  "scripts": {
    "vscode:uninstall": "node ./out/src/lifecycle"
  }
}