上一篇:使用Theia——建立擴展包javascript
下面咱們來看看如何建立Theia插件。做爲示例,咱們將註冊一個Hello World命令,該命令顯示一個「Hello World」通知。本文將指導你完成全部必要的步驟。html
Theia是一個可擴展的IDE。你可能據說過擴展是定製IDE的一種方式,而插件則是一種能夠被添加到Theia中的新的可擴展模型。下面是一些有關插件和擴展包之間的主要區別。前端
插件java
優勢:node
缺點:git
這裏有一個運行的Theia實例,(v0.3.12+)能夠從Theia倉庫得到Theia的說明。github
npm install -g yo @theia/generator-plugin mkdir theia-hello-world-plugin cd theia-hello-world-plugin yo @theia/plugin
在上面的命令中:typescript
下面是生成器運行的動態圖。npm
每一個問題使用默認選項便可。json
{ "name": "theia-hello-world-plugin", "publisher": "theia", "keywords": [ "theia-plugin" ], "version": "0.0.1", "files": [ "src" ], "devDependencies": { "@theia/plugin": "latest", <-- 1. Theia API dependency "rimraf": "^2.6.2", "typescript": "^2.9.2" }, "scripts": { "prepare": "yarn run clean && yarn run build", "clean": "rimraf lib", "build": "tsc" }, "engines": { "theiaPlugin": "latest" <-- 2. this plug-in requires Theia runtime }, "theiaPlugin": { "backend": "lib/theia-hello-world-plugin-backend-plugin.js" 3. <-- entrypoint } }
在這個package.json文件中,有三個重要的部分:
import * as theia from '@theia/plugin'; export function start() { const informationMessageTestCommand = { id: 'hello-world-example-generated', label: "Hello World" }; theia.commands.registerCommand(informationMessageTestCommand, (...args: any[]) => { theia.window.showInformationMessage('Hello World!'); }); } export function stop() { }