上一篇:使用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() { }