VSCode插件開發(fā)全攻略之package.json詳解
package.json
在詳細(xì)介紹vscode插件開發(fā)細(xì)節(jié)之前,這里我們先詳細(xì)介紹一下vscode插件的package.json寫法,但是建議先只需要隨便看一下,了解個(gè)大概,等后面講到具體細(xì)節(jié)的時(shí)候再回過頭來看。
如下是package.json文件的常用配置,當(dāng)然這里還不是全部:
{
// 插件的名字,應(yīng)全部小寫,不能有空格
"name": "vscode-plugin-demo",
// 插件的友好顯示名稱,用于顯示在應(yīng)用市場,支持中文
"displayName": "VSCode插件demo",
// 描述
"description": "VSCode插件demo集錦",
// 關(guān)鍵字,用于應(yīng)用市場搜索
"keywords": ["vscode", "plugin", "demo"],
// 版本號
"version": "1.0.0",
// 發(fā)布者,如果要發(fā)布到應(yīng)用市場的話,這個(gè)名字必須與發(fā)布者一致
"publisher": "sxei",
// 表示插件最低支持的vscode版本
"engines": {
"vscode": "^1.27.0"
},
// 插件應(yīng)用市場分類,可選值: [Programming Languages, Snippets, Linters, Themes, Debuggers, Formatters, Keymaps, SCM Providers, Other, Extension Packs, Language Packs]
"categories": [
"Other"
],
// 插件圖標(biāo),至少128x128像素
"icon": "images/icon.png",
// 擴(kuò)展的激活事件數(shù)組,可以被哪些事件激活擴(kuò)展,后文有詳細(xì)介紹
"activationEvents": [
"onCommand:extension.sayHello"
],
// 插件的主入口
"main": "./src/extension",
// 貢獻(xiàn)點(diǎn),整個(gè)插件最重要最多的配置項(xiàng)
"contributes": {
// 插件配置項(xiàng)
"configuration": {
"type": "object",
// 配置項(xiàng)標(biāo)題,會(huì)顯示在vscode的設(shè)置頁
"title": "vscode-plugin-demo",
"properties": {
// 這里我隨便寫了2個(gè)設(shè)置,配置你的昵稱
"vscodePluginDemo.yourName": {
"type": "string",
"default": "guest",
"description": "你的名字"
},
// 是否在啟動(dòng)時(shí)顯示提示
"vscodePluginDemo.showTip": {
"type": "boolean",
"default": true,
"description": "是否在每次啟動(dòng)時(shí)顯示歡迎提示!"
}
}
},
// 命令
"commands": [
{
"command": "extension.sayHello",
"title": "Hello World"
}
],
// 快捷鍵綁定
"keybindings": [
{
"command": "extension.sayHello",
"key": "ctrl+f10",
"mac": "cmd+f10",
"when": "editorTextFocus"
}
],
// 菜單
"menus": {
// 編輯器右鍵菜單
"editor/context": [
{
// 表示只有編輯器具有焦點(diǎn)時(shí)才會(huì)在菜單中出現(xiàn)
"when": "editorFocus",
"command": "extension.sayHello",
// navigation是一個(gè)永遠(yuǎn)置頂?shù)姆纸M,后面的@6是人工進(jìn)行組內(nèi)排序
"group": "navigation@6"
},
{
"when": "editorFocus",
"command": "extension.demo.getCurrentFilePath",
"group": "navigation@5"
},
{
// 只有編輯器具有焦點(diǎn),并且打開的是JS文件才會(huì)出現(xiàn)
"when": "editorFocus && resourceLangId == javascript",
"command": "extension.demo.testMenuShow",
"group": "z_commands"
},
{
"command": "extension.demo.openWebview",
"group": "navigation"
}
],
// 編輯器右上角圖標(biāo),不配置圖片就顯示文字
"editor/title": [
{
"when": "editorFocus && resourceLangId == javascript",
"command": "extension.demo.testMenuShow",
"group": "navigation"
}
],
// 編輯器標(biāo)題右鍵菜單
"editor/title/context": [
{
"when": "resourceLangId == javascript",
"command": "extension.demo.testMenuShow",
"group": "navigation"
}
],
// 資源管理器右鍵菜單
"explorer/context": [
{
"command": "extension.demo.getCurrentFilePath",
"group": "navigation"
},
{
"command": "extension.demo.openWebview",
"group": "navigation"
}
]
},
// 代碼片段
"snippets": [
{
"language": "javascript",
"path": "./snippets/javascript.json"
},
{
"language": "html",
"path": "./snippets/html.json"
}
],
// 自定義新的activitybar圖標(biāo),也就是左側(cè)側(cè)邊欄大的圖標(biāo)
"viewsContainers": {
"activitybar": [
{
"id": "beautifulGirl",
"title": "美女",
"icon": "images/beautifulGirl.svg"
}
]
},
// 自定義側(cè)邊欄內(nèi)view的實(shí)現(xiàn)
"views": {
// 和 viewsContainers 的id對應(yīng)
"beautifulGirl": [
{
"id": "beautifulGirl1",
"name": "國內(nèi)美女"
},
{
"id": "beautifulGirl2",
"name": "國外美女"
},
{
"id": "beautifulGirl3",
"name": "人妖"
}
]
},
// 圖標(biāo)主題
"iconThemes": [
{
"id": "testIconTheme",
"label": "測試圖標(biāo)主題",
"path": "./theme/icon-theme.json"
}
]
},
// 同 npm scripts
"scripts": {
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
},
// 開發(fā)依賴
"devDependencies": {
"typescript": "^2.6.1",
"vscode": "^1.1.6",
"eslint": "^4.11.0",
"@types/node": "^7.0.43",
"@types/mocha": "^2.2.42"
},
// 后面這幾個(gè)應(yīng)該不用介紹了
"license": "SEE LICENSE IN LICENSE.txt",
"bugs": {
"url": "https://github.com/sxei/vscode-plugin-demo/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/sxei/vscode-plugin-demo"
},
// 主頁
"homepage": "https://github.com/sxei/vscode-plugin-demo/blob/master/README.md"
}
activationEvents
插件在VS Code中默認(rèn)是沒有被激活的,哪什么時(shí)候才被激活呢?就是通過activationEvents來配置,目前支持一下8種配置:
- onLanguage:${language}
- onCommand:${command}
- onDebug
- workspaceContains:${toplevelfilename}
- onFileSystem:${scheme}
- onView:${viewId}
- onUri
- *
都比較好懂,我就不做一一介紹了,舉個(gè)例子,如果我配置了onLanguage:javascript,那么只要我打開了JS類型的文件,插件就會(huì)被激活。
重點(diǎn)說一下*,如果配置了*,只要一啟動(dòng)vscode,插件就會(huì)被激活,為了出色的用戶體驗(yàn),官方不推薦這么做??吹竭@里相信大家知道了我們前面HelloWord里面為啥要配置onCommand了吧。
3.contributes
- configuration:設(shè)置
- commands:命令
- menus:菜單
- keybindings:快捷鍵綁定
- languages:新語言支持
- debuggers:調(diào)試
- breakpoints:斷點(diǎn)
- grammars
- themes:主題
- snippets:代碼片段
- jsonValidation:自定義JSON校驗(yàn)
- views:左側(cè)側(cè)邊欄視圖
- viewsContainers:自定義activitybar
- problemMatchers
- problemPatterns
- taskDefinitions
- colors
參考

總結(jié)
到此這篇關(guān)于VSCode插件開發(fā)全攻略之package.json詳解的文章就介紹到這了,更多相關(guān)VSCode插件開發(fā) package.json內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
聊聊Qt+OpenCV聯(lián)合開發(fā)之圖像的創(chuàng)建與賦值問題
這篇文章主要介紹了Qt+OpenCV聯(lián)合開發(fā)之圖像的創(chuàng)建與賦值問題,給大家介紹了圖像的克隆及拷貝問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-01-01
C++ 中strcpy標(biāo)準(zhǔn)寫法實(shí)例詳解
這篇文章主要介紹了C++ 中strcpy標(biāo)準(zhǔn)寫法實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-06-06
C++實(shí)現(xiàn)LeetCode(63.不同的路徑之二)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(63.不同的路徑之二),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07
C語言入門篇--學(xué)習(xí)選擇,if,switch語句以及代碼塊
本篇文章是基礎(chǔ)篇,適合c語言剛?cè)腴T的朋友,本文主要帶大家學(xué)習(xí)一下C語言的選擇,if,switch語句及代碼塊,幫助大家快速入門c語言的世界,更好的理解c語言2021-08-08
使用Libmicrohttpd搭建內(nèi)嵌(本地)服務(wù)器的方法
下面小編就為大家?guī)硪黄褂肔ibmicrohttpd搭建內(nèi)嵌(本地)服務(wù)器的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08

