├── .editorconfig
├── .gitignore
├── LICENSE
├── README.md
├── api
├── authorize
│ └── index.js
├── commands
│ └── executeCommand.js
├── customEditor
│ ├── custom.js
│ └── test.cscratch
├── env
│ ├── clipboard.js
│ └── openExternal.js
├── help
│ └── help.js
├── languages
│ └── DiagnosticCollection.js
├── textEditor
│ ├── getText.js
│ ├── lineAt.js
│ ├── lineFromPosition.js
│ ├── setSelection.js
│ ├── textEditor.js
│ └── uri.js
├── treeview
│ └── treeview.js
├── util
│ ├── json.js
│ └── test.json
├── webview
│ └── webview.js
├── window
│ ├── WebviewDialog.js
│ ├── clearStatusBarMessage.js
│ ├── createOutputChannel.js
│ ├── createStatusBarItem.js
│ ├── getActiveTextEditor.js
│ ├── setStatusBarMessage.js
│ ├── showErrorMessage.js
│ ├── showFormDialog.js
│ ├── showInformationMessage.js
│ ├── showInputBox.js
│ ├── showMessageBox.js
│ ├── showQuickPick.js
│ └── showWarningMessage.js
└── workspace
│ ├── applyEdit.js
│ ├── copyFileWithPrompt.js
│ ├── getConfiguration.js
│ ├── getWorkspaceFolder.js
│ ├── getWorkspaceFolders.js
│ ├── onDidChangeConfiguration.js
│ ├── onDidChangeTextDocument.js
│ ├── onDidChangeWorkspaceFolders.js
│ ├── onDidOpenTextDocument.js
│ ├── onDidSaveTextDocument.js
│ ├── onWillSaveTextDocument.js
│ └── openTextDocument.js
├── commandPanel.js
├── extension.js
├── package.json
├── snippets
├── c.json
└── python.json
├── static
├── exmaple.jpg
├── fileiconfont.ttf
└── message.svg
└── test
└── test.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org
2 |
3 | root = true
4 |
5 | # all files
6 | [*]
7 | charset = utf-8
8 | indent_style = space
9 | indent_size = 4
10 | end_of_line = lf
11 | insert_final_newline = true
12 | # trim_trailing_whitespace = true
13 |
14 | # md files
15 | [*.md]
16 | insert_final_newline = false
17 | trim_trailing_whitespace = false
18 |
19 | [*.json]
20 | indent_size = 4
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | node_modules/*
3 |
4 | # Mac
5 | .DS_Store
6 | **/.DS_Store
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 DCloud
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HBuilderX插件扩展示例
2 |
3 | 本插件用于演示HBuilderX 各个API用法。
4 |
5 | 1. 建议您将本仓库克隆到本地,直接在HBuilderX内运行。
6 | 2. 下载此插件后,将目录拖到HBuilderX中,点击工具栏【运行】
7 |
8 | 
9 |
10 | #### 克隆仓库
11 |
12 | ```shell
13 | git clone https://github.com/dcloudio/hbuilderx-extension-samples.git
14 | ```
15 |
16 |
--------------------------------------------------------------------------------
/api/authorize/index.js:
--------------------------------------------------------------------------------
1 | const hx = require('hbuilderx');
2 |
3 | function login() {
4 | let prom = hx.authorize.login({
5 | appId: "Hl9DHrNwyc",
6 | scopes: ['basic', 'email', 'phone'],
7 | description: "这个是申请权限描述......."
8 | });
9 | prom.then(function(param) {
10 | console.log(param)
11 | });
12 | }
13 |
14 |
15 | function logout() {
16 | hx.authorize.onUserLogout(function(res){
17 | console.log(res);
18 | })
19 | }
20 |
21 | module.exports = {
22 | login,
23 | logout
24 | };
25 |
--------------------------------------------------------------------------------
/api/commands/executeCommand.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 |
3 | /**
4 | * @description 执行内置命令
5 | */
6 | function executeCommand() {
7 | hx.commands.executeCommand('workbench.action.closeAllEditors');
8 | }
9 |
10 | module.exports = {
11 | executeCommand
12 | };
--------------------------------------------------------------------------------
/api/customEditor/custom.js:
--------------------------------------------------------------------------------
1 | const hx = require("hbuilderx");
2 |
3 | let CustomDocument = hx.CustomEditor.CustomDocument;
4 | let CustomEditorProvider = hx.CustomEditor.CustomEditorProvider;
5 | let CustomDocumentEditEvent = hx.CustomEditor.CustomDocumentEditEvent;
6 |
7 |
8 | class CatCustomDocument extends CustomDocument {
9 | constructor(uri) {
10 | super(uri)
11 | }
12 | dispose() {
13 | super.dispose();
14 | }
15 | }
16 |
17 | function html(webViewPanel) {
18 | webViewPanel.webView.html = `
19 |
20 |
34 |
35 | 设置编辑器为编辑状态
36 | 关闭当前自定义编辑器
37 |
38 |
52 |
53 | `;
54 | }
55 |
56 | class CatCustomEditorProvider extends CustomEditorProvider {
57 | constructor(context) {
58 | super()
59 | }
60 | openCustomDocument(uri) {
61 | return Promise.resolve(new CatCustomDocument(uri));
62 | }
63 | resolveCustomEditor(document, webViewPanel) {
64 |
65 | // 渲染html
66 | html(webViewPanel);
67 |
68 | webViewPanel.onDidDispose(function() {
69 | console.log("custom editor disposed");
70 | });
71 |
72 | let provider = this;
73 | webViewPanel.webView.onDidReceiveMessage(function(msg) {
74 | if (!msg)
75 | return;
76 | if (msg.command == 'close') {
77 | webViewPanel.dispose();
78 | } else if (msg.type == 'edit') {
79 | provider.onDidChangeCustomDocument.fire(new CustomDocumentEditEvent(document));
80 | }
81 | });
82 | }
83 |
84 | saveCustomDocument(document) {
85 | return true;
86 | }
87 | saveCustomDocumentAs(document, destination) {
88 | return true;
89 | }
90 | }
91 |
92 |
93 | module.exports = CatCustomEditorProvider;
--------------------------------------------------------------------------------
/api/customEditor/test.cscratch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dcloudio/hbuilderx-extension-samples/b7ba7189bcfa7e1256227b22c38fb96ae55dce25/api/customEditor/test.cscratch
--------------------------------------------------------------------------------
/api/env/clipboard.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 写入剪切板
5 | * @createTime 2020-5-18 17:36:00
6 | */
7 | function clipboardWrite() {
8 | hx.env.clipboard.writeText("Hello HBuilderX");
9 | }
10 |
11 | /**
12 | * @description 读取剪切板
13 | * @createTime 2020-5-18 17:36:00
14 | */
15 | function clipboardRead() {
16 | var textPromise = hx.env.clipboard.readText();
17 | textPromise.then(function(res){
18 | console.log("当前剪切板内容为: ",res);
19 | })
20 | }
21 |
22 | module.exports = {
23 | clipboardWrite,
24 | clipboardRead
25 | };
26 |
--------------------------------------------------------------------------------
/api/env/openExternal.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 打开浏览器
5 | * @param {String} url
6 | * @createTime 2020-5-18 17:36:00
7 | */
8 | function openExternal(url) {
9 | var openPromise = hx.env.openExternal(url);
10 | openPromise.then(function(res){
11 | console.log("--",res);
12 | })
13 | }
14 |
15 | module.exports = {
16 | openExternal
17 | };
18 |
--------------------------------------------------------------------------------
/api/help/help.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 打开浏览器
5 | * @param {String} url
6 | */
7 | function openBrowser(url) {
8 | var exec = require('child_process').exec;
9 | switch (process.platform) {
10 | case "darwin":
11 | exec('open ' + url);
12 | break;
13 | case "win32":
14 | exec('start ' + url);
15 | break;
16 | default:
17 | exec('xdg-open', [url]);
18 | }
19 | }
20 |
21 | /**
22 | * @description 打开帮助页面
23 | */
24 | function openHelp() {
25 | openBrowser("https://hbuilderx.dcloud.net.cn")
26 | }
27 |
28 | module.exports = {
29 | openHelp
30 | };
31 |
--------------------------------------------------------------------------------
/api/languages/DiagnosticCollection.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 | var path = require('path');
3 |
4 | /**
5 | * @description DiagnosticCollection - 创建问题集合
6 | */
7 | function createDiagnosticCollection() {
8 | let activeEditor = hx.window.getActiveTextEditor();
9 | activeEditor.then(function(editor) {
10 | // 获取文件路径
11 | let file_url = editor.document.uri.fsPath;
12 |
13 | // 判断文件后缀
14 | var extname = path.extname(file_url);
15 | if (![".js", ".html", ".vue", ".css", ".ts"].includes(extname)) {
16 | hx.window.showErrorMessage("请在html或css或js或vue文件上进行操作");
17 | }
18 | // 创建问题集合
19 | let collections = [{
20 | column: 0,
21 | line: 3,
22 | message: "error for test",
23 | severity: 'error'
24 | },
25 | {
26 | column: 4,
27 | line: 5,
28 | message: "warning for test",
29 | severity: 'warn'
30 | }
31 | ];
32 | let diagnostics = hx.languages.createDiagnosticCollection('eslint');
33 | diagnostics.set(file_url, collections);
34 | });
35 | }
36 |
37 | module.exports = {
38 | createDiagnosticCollection
39 | };
40 |
--------------------------------------------------------------------------------
/api/textEditor/getText.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description getText - 获取指定区域内的文本
5 | */
6 | function getText() {
7 | let activeEditor = hx.window.getActiveTextEditor();
8 | activeEditor.then(function(editor) {
9 | // 获取指定区域内的文本
10 | let text = editor.document.getText({
11 | start: 0,
12 | end: 50
13 | });
14 |
15 | // 将获取到的内容输出到控制台
16 | let outputChannel = hx.window.createOutputChannel("getText");
17 | outputChannel.show();
18 | outputChannel.appendLine(text);
19 | });
20 | }
21 |
22 | module.exports = {
23 | getText
24 | };
--------------------------------------------------------------------------------
/api/textEditor/lineAt.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description lineAt
5 | */
6 | function lineAt() {
7 | let activeEditor = hx.window.getActiveTextEditor();
8 | activeEditor.then(function(editor) {
9 | // 行号是从0开始
10 | let linePromise = editor.document.lineAt(2);
11 | linePromise.then((line)=>{
12 | console.log("TextLine is:", line.text);
13 | hx.window.showInformationMessage("第3行内容为:" + String(line.text));
14 | });
15 | });
16 | }
17 |
18 | module.exports = {
19 | lineAt
20 | };
--------------------------------------------------------------------------------
/api/textEditor/lineFromPosition.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description lineFromPosition
5 | */
6 | function lineFromPosition() {
7 | let activeEditor = hx.window.getActiveTextEditor();
8 | activeEditor.then(function(editor) {
9 | let linePromise = editor.document.lineFromPosition(editor.selection.active);
10 | linePromise.then((line)=>{
11 | console.log(line);
12 | console.log("TextLine is:", line.text, "开始位置:", line.start, "结束位置:", line.end);
13 | hx.window.setStatusBarMessage(line.text);
14 | });
15 | });
16 | }
17 |
18 | module.exports = {
19 | lineFromPosition
20 | };
--------------------------------------------------------------------------------
/api/textEditor/setSelection.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description setSelection
5 | */
6 | function setSelection() {
7 | let activeEditor = hx.window.getActiveTextEditor();
8 | activeEditor.then(function(editor) {
9 | editor.setSelection(0, 50).then(() => {
10 | // editor.addSelection(16, 18);
11 | });
12 | }).catch( error => {
13 | console.log('--------', error);
14 | });
15 | }
16 |
17 | module.exports = {
18 | setSelection
19 | };
20 |
--------------------------------------------------------------------------------
/api/textEditor/textEditor.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description TextEditor
5 | */
6 | function textEditor(property) {
7 | let activeEditor = hx.window.getActiveTextEditor();
8 | activeEditor.then(function(editor) {
9 |
10 | // 获取文件对象
11 | if (property == "document") {
12 | let fname = editor.document.fileName;
13 | let msg_fname = "当前打开的文件是:" + String(fname) + "\n";
14 |
15 | let lineCount = editor.document.lineCount;
16 | let msg_line = "文档总行数" + String(lineCount) + "\n";
17 |
18 | let language = editor.document.languageId;
19 | let msg_language = "它是一个 " + language + "项目\n";
20 |
21 | let isUntitled = editor.document.isUntitled;
22 | let msg_isUntitled = "是否是无标题文件: " + String(isUntitled) + "\n";
23 |
24 | let isDirty = editor.document.isDirty;
25 | let msg_isDirty = "是否是修改状态: " + String(isDirty) + "\n";
26 |
27 | let msg = msg_fname + msg_line + msg_language + msg_isUntitled + msg_isDirty;
28 |
29 | // 输出到控制台
30 | let outputChannel = hx.window.createOutputChannel("info");
31 | outputChannel.show();
32 | outputChannel.appendLine(msg);
33 | }
34 |
35 | // 获取光标所在行内容
36 | if (property == "linetext") {
37 | let linePromise = editor.document.lineFromPosition(editor.selection.active);
38 | linePromise.then((line)=>{
39 | let line_msg = "当前光标所在行内容为: " + line.text.trim();
40 | hx.window.showInformationMessage(line_msg);
41 | console.log(line_msg);
42 | });
43 | }
44 |
45 | // 把当前选中的内容由小写转换大写
46 | if (property == "UpperCase") {
47 | let selection = editor.selection;
48 | console.log(selection);
49 | let word = editor.document.getText(selection);
50 | let toUpperCase = word.toUpperCase();
51 | editor.edit(editBuilder => {
52 | editBuilder.replace(selection,toUpperCase);
53 | });
54 | }
55 |
56 | // 获取当前文件缩进方式
57 | if (property == "tabSize") {
58 | let msg_tab_size = "当前tabSize为: " + String(editor.options.tabSize);
59 | hx.window.showInformationMessage(msg_tab_size);
60 | console.log(msg_tab_size);
61 | }
62 |
63 | });
64 | }
65 |
66 | module.exports = {
67 | textEditor
68 | };
--------------------------------------------------------------------------------
/api/textEditor/uri.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 打印uri所有信息
5 | */
6 | function uri(value) {
7 | let activeEditor = hx.window.getActiveTextEditor();
8 | activeEditor.then(function(editor) {
9 | let uri = editor.document.uri;
10 |
11 | // 创建控制台输出
12 | let outputChannel = hx.window.createOutputChannel("uri");
13 | outputChannel.show();
14 | outputChannel.appendLine(JSON.stringify(uri,null,2));
15 | });
16 | }
17 |
18 | module.exports = {
19 | uri
20 | };
21 |
--------------------------------------------------------------------------------
/api/treeview/treeview.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | class DemoTreeDataProvider {
4 | constructor() {
5 | this._demoData = [{
6 | name: "Root1",
7 | children: []
8 | }
9 | ];
10 | }
11 | getChildren(element) {
12 | let demoData = this._demoData;
13 | return new Promise(resolve => {
14 | if (!element) {
15 | resolve(demoData);
16 | } else {
17 | resolve(element.children);
18 | }
19 | });
20 | }
21 |
22 | getTreeItem(element) {
23 | return {
24 | label: element.name,
25 | collapsibleState: element.children ? 1 : 0,
26 | command: {
27 | command: element.children ? "" : "extension.helloWorld",
28 | arguments: [
29 | element.name
30 | ]
31 | }
32 | }
33 | }
34 | }
35 |
36 | module.exports = {
37 | DemoTreeDataProvider
38 | };
--------------------------------------------------------------------------------
/api/util/json.js:
--------------------------------------------------------------------------------
1 | const hx = require("hbuilderx");
2 | const path = require("path");
3 |
4 | class handleJson {
5 | constructor() {
6 | this.testfile = path.join(__dirname, 'test.json');
7 | // this.testfile = 'C:/Users/Administrator/AppData/Roaming/HBuilder X/user/settings.json';
8 | }
9 |
10 | async read() {
11 | try{
12 | let result = hx.util.readJSONValue(this.testfile, '.list[0]');
13 | result.then((data) => {
14 | console.log("----读取的值为:", data)
15 | });
16 | }catch(e){
17 | console.error(e)
18 | }
19 | }
20 |
21 | async write() {
22 | let result = hx.util.writeJSONValue(this.testfile, '.version', '2.0.0');
23 | result.then((data) => {
24 | console.log(data)
25 | });
26 | }
27 |
28 | async main() {
29 | console.log('------------- json file path is: ', this.testfile)
30 | await this.read();
31 | await this.write();
32 | }
33 | }
34 |
35 | module.exports = handleJson;
36 |
--------------------------------------------------------------------------------
/api/util/test.json:
--------------------------------------------------------------------------------
1 | {
2 | "version" : "2.0.0",
3 | "list": [
4 | {
5 | "name": "小明"
6 | },
7 | {
8 | "name": "小红"
9 | }
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/api/webview/webview.js:
--------------------------------------------------------------------------------
1 | const hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 显示webview
5 | */
6 | function showWebView(webviewPanel) {
7 | let webview = webviewPanel.webView;
8 |
9 | let background = '';
10 |
11 | let config = hx.workspace.getConfiguration();
12 | let colorScheme = config.get('editor.colorScheme');
13 | if (colorScheme == 'Monokai') {
14 | background = 'rgb(39,40,34)'
15 | } else if (colorScheme == 'Atom One Dark') {
16 | background = 'rgb(40,44,53)'
17 | } else {
18 | background = 'rgb(255,250,232)'
19 | };
20 |
21 | webview.html =
22 | `
23 |
24 |
25 |

26 |
27 |
28 |
29 |
30 |
31 |
45 |
46 |
47 | `;
48 | webview.onDidReceiveMessage((msg) => {
49 | if (msg.command == 'alert') {
50 | hx.window.showInformationMessage(msg.text);
51 | webview.postMessage({
52 | command: "test"
53 | });
54 | }
55 | });
56 | };
57 |
58 |
59 | module.exports = {
60 | showWebView
61 | }
62 |
--------------------------------------------------------------------------------
/api/window/WebviewDialog.js:
--------------------------------------------------------------------------------
1 | const hx = require('hbuilderx');
2 |
3 | /**
4 | * @description hx.window.createWebViewDialog
5 | */
6 | function WebviewDialog() {
7 | let webviewDialog = hx.window.createWebViewDialog({
8 | modal: true,
9 | title: "是否删除文件?",
10 | description: "删除后无法恢复,请谨慎操作。也可以到回收站看看。",
11 | dialogButtons: [
12 | "确定", "取消"
13 | ],
14 | size: {
15 | width: 400,
16 | height: 300
17 | }
18 | }, {
19 | enableScripts: true
20 | });
21 |
22 | let webview = webviewDialog.webView;
23 | webview.html = `
24 |
25 |
43 |
44 | `;
45 |
46 | webview.onDidReceiveMessage((msg) => {
47 | console.log(msg)
48 | if (msg.command == 'cancel') {
49 | webviewDialog.close();
50 | }
51 | });
52 |
53 | let promi = webviewDialog.show();
54 | promi.then(function (data) {
55 | // 处理错误信息
56 | });
57 | };
58 |
59 | module.exports = WebviewDialog;
60 |
--------------------------------------------------------------------------------
/api/window/clearStatusBarMessage.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 清空状态栏消息
5 | */
6 | function clearStatusBarMessage() {
7 | hx.window.clearStatusBarMessage()
8 | }
9 |
10 | module.exports = {
11 | clearStatusBarMessage
12 | };
13 |
--------------------------------------------------------------------------------
/api/window/createOutputChannel.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 创建输出控制台
5 | */
6 | function createOutputChannel() {
7 |
8 | // 控制台名称
9 | let channel_name = "dev";
10 |
11 | // 创建控制台
12 | let outputChannel = hx.window.createOutputChannel(channel_name);
13 |
14 | // 显示控制台
15 | outputChannel.show();
16 |
17 | // 输出内容
18 | outputChannel.appendLine("====================================================");
19 | outputChannel.appendLine("欢迎体验HBuilderX插件:http://hbuilderx.dcloud.net.cn/");
20 | outputChannel.appendLine({"level": "success", "line": "这是一条成功的消息"});
21 | outputChannel.appendLine({"level": "error", "line": "这是一条失败的消息"});
22 | }
23 |
24 | module.exports = {
25 | createOutputChannel
26 | };
27 |
--------------------------------------------------------------------------------
/api/window/createStatusBarItem.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | let myStatusBarItem;
4 |
5 | /**
6 | * @description 创建状态栏元素
7 | * https://hx.dcloud.net.cn/ExtensionDocs/Api/windows/createStatusBarItem
8 | */
9 | function createStatusBarItem() {
10 | if (myStatusBarItem == undefined) {
11 | myStatusBarItem = hx.window.createStatusBarItem(
12 | hx.StatusBarAlignment.Left,
13 | 100,
14 | );
15 | };
16 |
17 | // 状态栏元素要显示的文本
18 | myStatusBarItem.text = '显示通知框';
19 | myStatusBarItem.text = '$(message)显示通知框';
20 |
21 | // 将鼠标悬停在状态栏元素上时的工具提示文本。
22 | myStatusBarItem.tooltip = "这是一个自定义的状态栏元素";
23 |
24 | // 要在单击时运行的命令或命令的标识符。命令必须是已注册的。
25 | myStatusBarItem.command = "api.show_info_message";
26 |
27 | myStatusBarItem.show();
28 | };
29 |
30 | module.exports = createStatusBarItem;
31 |
--------------------------------------------------------------------------------
/api/window/getActiveTextEditor.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 获取当前激活的编辑器
5 | */
6 | function getActiveTextEditor(value) {
7 | let activeEditor = hx.window.getActiveTextEditor();
8 | activeEditor.then(function(editor) {
9 | switch (value) {
10 | case "filename":
11 | let fname = editor.document.fileName;
12 | hx.window.showInformationMessage("当前激活的编辑器是:" + String(fname));
13 | break;
14 | case "nature":
15 | let nature = editor.document.workspaceFolder.nature;
16 | hx.window.showInformationMessage("当前项目类型是:" + nature);
17 | break;
18 | case "project_name":
19 | let pro_name = editor.document.workspaceFolder.name;
20 | hx.window.showInformationMessage("当前项目名称是:" + String(pro_name));
21 | break;
22 | }
23 |
24 | });
25 | }
26 |
27 | module.exports = {
28 | getActiveTextEditor
29 | };
30 |
--------------------------------------------------------------------------------
/api/window/setStatusBarMessage.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 设置状态栏消息 (状态栏上不支持url跳转)
5 | * @param {String} level = ['info','error','warn'] - 消息级别
6 | */
7 | function setStatusBarMessage(level = 'info', hideAfterTimeOut = 0) {
8 | let msg = "这是一条" + level + "级别的消息 查看url";
9 | if (hideAfterTimeOut !== 0) {
10 | msg = "这是一条能够自动隐藏的消息," + String(hideAfterTimeOut) + "毫秒后消失。";
11 | }
12 | hx.window.setStatusBarMessage(msg, hideAfterTimeOut, level);
13 | }
14 |
15 | module.exports = {
16 | setStatusBarMessage
17 | };
18 |
--------------------------------------------------------------------------------
/api/window/showErrorMessage.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 窗口右下角错误通知框
5 | */
6 | function showErrorMessage() {
7 | let resultPromise = hx.window.showErrorMessage('这是一个 error 相关的通知框。错误', ['我知道了',
8 | '取消'
9 | ]);
10 | resultPromise.then((result) => {
11 | if (result === '我知道了') {
12 | console.log('您点击的是: 我知道了');
13 | } else if (result === '取消') {
14 | console.log("您点击的是: 取消");
15 | }
16 | });
17 | }
18 |
19 | module.exports = {
20 | showErrorMessage
21 | };
22 |
--------------------------------------------------------------------------------
/api/window/showFormDialog.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | *@description 窗口控件
5 | 支持的控件如下:
6 | - input 普通输入框
7 | - file 文件选择输入框
8 | - radio 单选框
9 | - list 列表
10 | - label 描述
11 | */
12 | function getUIData(selected) {
13 | let uiData = {
14 | formItems: [
15 | {
16 | type: "label",
17 | name: "label1",
18 | text: "这是一个文本展示组件,主要用来放置描述文字,欢迎大家开发HBuilderX插件"
19 | },
20 | {
21 | type: "input",
22 | name: "projectName",
23 | label: "普通输入框",
24 | placeholder: '这是一个普通输入框',
25 | value: ""
26 | },
27 | {
28 | type: "input",
29 | name: "projectName",
30 | label: "普通输入框",
31 | placeholder: '这是一个普通输入框',
32 | value: "uni-app",
33 | disabled: true
34 | },
35 | {
36 | type: "fileSelectInput",
37 | name: "projectLocation",
38 | label: "文件选择输入框",
39 | placeholder: '这是一个文件选择输入框, 只能选择html和json文件',
40 | value: "",
41 | mode: "file",
42 | filters: ["*.html;*.json"]
43 | },
44 | {
45 | type: "comboBox",
46 | placeholder: "请输入",
47 | name: "functionNameInput",
48 | label: "组合下拉框",
49 | editable: true,
50 | items: ["item1","item2","item3"],
51 | text: "item1"
52 | },
53 | {
54 | type: "checkBox",
55 | name: "checkBox",
56 | value: "复选框",
57 | label: "复选框"
58 | },
59 | {
60 | type: "radioGroup",
61 | name: "projectType",
62 | label: "单选框",
63 | value: "css",
64 | items: [
65 | {label: "css",id: "css"},
66 | {label: "html",id: "html"},
67 | {label: "javascript",id: "javascript"},
68 | {label: "typescript",id: "typescript"},
69 | {label: "php",id: "php"}
70 | ]
71 | },
72 | {
73 | type: "textEditor",
74 | name: "paramsInput",
75 | title: "标题",
76 | languageId: "json",
77 | text: "{\n\"params\":[\n]}",
78 | },
79 | {
80 | "type": "list",
81 | "title": "选择框",
82 | "name": "list1",
83 | "columnStretches": [1, 2],
84 | "items": [
85 | {
86 | "columns": [
87 | {"label": "百度"},
88 | {"label": "百度一下百度"}
89 | ]
90 | },
91 | {
92 | "columns": [
93 | {"label": "Google"},
94 | {"label": "谷歌一下Google"}
95 | ]
96 | }
97 | ],
98 | "value": 0
99 | }
100 | ]
101 | }
102 | return uiData;
103 | };
104 |
105 |
106 | /**
107 | * @description showFormDialog
108 | */
109 | async function showFormDialog() {
110 | // 获取默认UI数据
111 | let uidata = getUIData()
112 |
113 | hx.window.showFormDialog({
114 | ...uidata,
115 | title: "showFormDialog",
116 | subtitle: "插件API hx.window.showFormDialog测试用例",
117 | width: 640,
118 | height: 780,
119 | submitButtonText: "提交(&S)",
120 | cancelButtonText: "取消(&C)",
121 | validate: function(formData) {
122 | if (!formData.projectName) {
123 | this.showError("普通输入框不能为空,请填写");
124 | return false;
125 | };
126 | return true;
127 | },
128 | onChanged: function(field, value) {
129 | if (field == "projectType") {
130 | let updateData = getUIData(value);
131 | this.updateForm(updateData);
132 | };
133 | }
134 | }).then((res) => {
135 | console.log("返回结果:", JSON.stringify(res));
136 | });
137 |
138 | };
139 |
140 | module.exports = showFormDialog;
141 |
--------------------------------------------------------------------------------
/api/window/showInformationMessage.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 窗口右下角info通知框
5 | */
6 | function showInformationMessage() {
7 | let resultPromise = hx.window.showInformationMessage('这是一个 Information 相关的通知框。 DCloud官网', ['我知道了','取消']);
8 | resultPromise.then((result) => {
9 | if (result === '我知道了') {
10 | console.log('您点击的是: 我知道了');
11 | } else if (result === '取消') {
12 | console.log("您点击的是: 取消");
13 | }
14 | });
15 | }
16 |
17 | module.exports = {
18 | showInformationMessage
19 | };
20 |
--------------------------------------------------------------------------------
/api/window/showInputBox.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 在屏幕中间显示输入框
5 | */
6 | function showInputBox() {
7 | let inputPromise = hx.window.showInputBox({
8 | prompt: "请输入密码",
9 | value: '123456',
10 | password: true
11 | });
12 | inputPromise.then((result) => {
13 | hx.window.showInformationMessage("您输入的密码为:" + result);
14 | })
15 | }
16 |
17 | module.exports = {
18 | showInputBox
19 | };
--------------------------------------------------------------------------------
/api/window/showMessageBox.js:
--------------------------------------------------------------------------------
1 | const hx = require('hbuilderx');
2 |
3 | /**
4 | * @brief showMessageBox
5 | * @param messageType 消息类型 error | info | warning
6 | * @param messageTitle 标题
7 | * @param messageText 内容
8 | * @param buttons 按钮列表
9 | * @param defaultButton 默认按钮索引
10 | * @param escapeButton 默认Esc后执行的操作按钮索引
11 | *
12 | * escapeButton和defaultButton两个数值不能一样
13 | */
14 | function showMessageBox() {
15 | let result = hx.window.showMessageBox({
16 | type: 'info',
17 | title: '测试对话框',
18 | text: '测试对话框?',
19 | buttons: ['关闭','查询', '替换'],
20 | defaultButton: -10,
21 | escapeButton: -1
22 | });
23 | result.then((button) => {
24 | console.log(button);
25 | });
26 | }
27 |
28 | module.exports = showMessageBox;
29 |
--------------------------------------------------------------------------------
/api/window/showQuickPick.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 打开浏览器
5 | * @param {String} url
6 | */
7 | function openBrowser(url) {
8 | var exec = require('child_process').exec;
9 | switch (process.platform) {
10 | case "darwin":
11 | exec('open ' + url);
12 | break;
13 | case "win32":
14 | exec('start ' + url);
15 | break;
16 | default:
17 | exec('xdg-open', [url]);
18 | }
19 | }
20 |
21 | /**
22 | * @description 在窗口中间弹出一个可搜索的建议选择列表
23 | */
24 | function showQuickPick() {
25 | let items = [{
26 | label: "入门必看: HBuilderX入门教程",
27 | url: "https://ask.dcloud.net.cn/article/35357"
28 | }, {
29 | label: "HBuilderX技巧:利用外部命令,可以做哪些事?",
30 | url: "https://ask.dcloud.net.cn/article/35460"
31 | },
32 | {
33 | label: "HBuilderX editorconfig使用说明",
34 | url: "https://ask.dcloud.net.cn/article/36070"
35 | },
36 | {
37 | label:"HBuilderX真机运行常见问题",
38 | url: "https://ask.dcloud.net.cn/article/97"
39 | }
40 | ];
41 |
42 | const PickResult = hx.window.showQuickPick(items, {
43 | placeHolder: "请选择您要查看的帮助文档"
44 | });
45 |
46 | PickResult.then(function(result) {
47 | if (!result) {
48 | return;
49 | }
50 | let text = result.label;
51 | console.log("您选择的内容是:", text);
52 |
53 | // 使用浏览器打开URL
54 | openBrowser(result.url);
55 | });
56 | }
57 |
58 | module.exports = {
59 | showQuickPick
60 | };
61 |
--------------------------------------------------------------------------------
/api/window/showWarningMessage.js:
--------------------------------------------------------------------------------
1 | let hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 窗口右下角warning通知框
5 | */
6 | function showWarningMessage() {
7 | let resultPromise = hx.window.showWarningMessage('这是一个 Warning 相关的通知框。', ['我知道了','取消']);
8 | resultPromise.then((result) => {
9 | if (result === '我知道了') {
10 | console.log('您点击的是: 我知道了');
11 | } else if (result === '取消') {
12 | console.log("您点击的是: 取消");
13 | }
14 | });
15 | }
16 |
17 | module.exports = {
18 | showWarningMessage
19 | };
20 |
--------------------------------------------------------------------------------
/api/workspace/applyEdit.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 |
3 | /**
4 | * @description 执行指定的文档编辑工作
5 | */
6 | function applyEdit() {
7 | let editorPromise = hx.window.getActiveTextEditor();
8 | editorPromise.then((editor) => {
9 | let workspaceEdit = new hx.WorkspaceEdit();
10 | let edits = [];
11 | edits.push(new hx.TextEdit({
12 | start: 0,
13 | end: 0
14 | }, "foo\n"));
15 |
16 | workspaceEdit.set(editor.document.uri, edits);
17 | hx.workspace.applyEdit(workspaceEdit);
18 | hx.window.showInformationMessage("请注意: 文档第一行开头,插入了 foo");
19 | });
20 | }
21 |
22 | module.exports = {
23 | applyEdit
24 | };
25 |
--------------------------------------------------------------------------------
/api/workspace/copyFileWithPrompt.js:
--------------------------------------------------------------------------------
1 | const hx = require('hbuilderx');
2 |
3 | /**
4 | * @description 把文件或目录,拷贝到指定目录下
5 | * @param {String} src 绝对路径,目录或文件
6 | * @param {String} dest 绝对路径,必须是目录
7 | */
8 | function copyFileWithPrompt(src, dest) {
9 | hx.workspace.copyFileWithPrompt({
10 | src: hx.Uri.file(src),
11 | dest: hx.Uri.file(dest),
12 | filter: function(params) {
13 | return 0;
14 | },
15 | rootPromptTips: "当前位置文件已存在,将选择后续操作?",
16 | errorHandler: function(err) {
17 | return 0;
18 | }
19 | }).then((data) => {
20 | // 0 操作成功
21 | // 101 无效的路径/没有找到该文件对应的文件系统
22 | // 102 没有找到该文件
23 | // 103 打开文件失败
24 | // 104 读取文件内容失败
25 | // 105 写入文件内容失败
26 | // 106 删除文件失败
27 | // 107 创建文件夹失败
28 | // 108 获取文件列表失败
29 | // 109 创建临时文件夹失败
30 | // 201 解析Json数据失败,可能是无效的Json数据
31 | console.log("--->", data);
32 | })
33 | };
34 |
35 | module.exports = copyFileWithPrompt;
36 |
--------------------------------------------------------------------------------
/api/workspace/getConfiguration.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 |
3 | /**
4 | * @description 根据指定的section获取从【设置-源码视图】 取值
5 | */
6 | function getConfiguration() {
7 | // 以node内存值为例
8 | let config = hx.workspace.getConfiguration();
9 | let node_memory = config.get('node.run.memoryParam');
10 | let msg = "当前uniapp node运行内存最大值为: " + String(node_memory);
11 | hx.window.showInformationMessage(msg);
12 |
13 | // 以eslint-js为例
14 | let esconfig = hx.workspace.getConfiguration("eslint-js");
15 | let is_autoFixOnSave = esconfig.get('autoFixOnSave');
16 | console.log("=============== eslint is_autoFixOnSave: ",is_autoFixOnSave);
17 | }
18 |
19 | /**
20 | * @description 更新配置, 把node内存默认值由2048为1024
21 | */
22 | function updateConfiguration() {
23 | let config = hx.workspace.getConfiguration();
24 | var before_memory = config.get('node.run.memoryParam');
25 | console.log("==============update before:",before_memory);
26 |
27 | config.update("node.run.memoryParam", "1024").then(() => {
28 | // 获取更新之后的值
29 | let after_memory = config.get('node.run.memoryParam');
30 | console.log("==============update after",typeof(after_memory),after_memory);
31 | // 输出消息到控制台、弹框
32 | let msg = "node内存值从" + String(before_memory) + "更新为: " + String(after_memory);
33 | hx.window.showInformationMessage(msg);
34 | console.log(msg);
35 | })
36 |
37 | config.update("testobject", {"name":"beijign"}).then(() => {
38 | console.log('更新object')
39 | })
40 |
41 | config.update("workbench.colorCustomizations", {"[Default]":{
42 | "sideBar.background": "#FFFFFF"
43 | }}).then(() => {
44 | console.log('更新object')
45 | })
46 | }
47 |
48 | /**
49 | * @description 在全局配置中,插入新值
50 | */
51 | function addConfiguration() {
52 | let config = hx.workspace.getConfiguration();
53 | config.update("datetime", "2020-04-28 00:00:00").then(() => {
54 | hx.window.showInformationMessage("插入新值成功");
55 | })
56 | }
57 |
58 | module.exports = {
59 | getConfiguration,
60 | updateConfiguration,
61 | addConfiguration
62 | };
63 |
--------------------------------------------------------------------------------
/api/workspace/getWorkspaceFolder.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 |
3 | /**
4 | * @description 获取某个文件所在的项目
5 | */
6 | function getWorkspaceFolder() {
7 | let activeEditor = hx.window.getActiveTextEditor();
8 | activeEditor.then(function(editor) {
9 | var fspath = editor.document.uri;
10 | var wsPromise = hx.workspace.getWorkspaceFolder(fspath);
11 | wsPromise.then(function(wsFolder) {
12 | console.log('----',wsFolder);
13 | console.log("文件所在项目:", wsFolder.name);
14 | });
15 | })
16 | }
17 |
18 | module.exports = {
19 | getWorkspaceFolder
20 | };
21 |
--------------------------------------------------------------------------------
/api/workspace/getWorkspaceFolders.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 |
3 | /**
4 | * @description 获取项目管理器下所有的项目对象
5 | */
6 | function getWorkspaceFolders() {
7 | var wsPromise = hx.workspace.getWorkspaceFolders();
8 | wsPromise.then(function(wsFolders) {
9 | console.log(wsFolders);
10 | console.log("项目管理器包含的项目数量:", wsFolders.length);
11 | });
12 | }
13 |
14 | module.exports = {
15 | getWorkspaceFolders
16 | };
17 |
--------------------------------------------------------------------------------
/api/workspace/onDidChangeConfiguration.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 |
3 | /**
4 | * @description 全局配置改变事件,比如"editor.fontSize"改变,或者通过插件扩展的配置项改变
5 | */
6 | function onDidChangeConfiguration() {
7 | let configurationChangeDisplose = hx.workspace.onDidChangeConfiguration(function(event) {
8 | if (event.affectsConfiguration("node.run.memoryParam")) {
9 | console.log("修改了node内存");
10 | }
11 | });
12 | }
13 |
14 | module.exports = {
15 | onDidChangeConfiguration
16 | };
17 |
--------------------------------------------------------------------------------
/api/workspace/onDidChangeTextDocument.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 |
3 | /**
4 | * @description 文档被修改时的事件
5 | */
6 | function onDidChangeTextDocument() {
7 | let onDidChangeTextDocumentEventDispose = hx.workspace.onDidChangeTextDocument(function(event) {
8 | let document = event.document;
9 | console.log(document);
10 | // 获取文件路径与行数
11 | console.log("当前触发修改的文件路径为: ", document.uri);
12 | console.log("当前触发修改的文件行数为",document.lineCount);
13 | });
14 | }
15 |
16 | module.exports = {
17 | onDidChangeTextDocument
18 | };
--------------------------------------------------------------------------------
/api/workspace/onDidChangeWorkspaceFolders.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 |
3 | /**
4 | * @description 项目管理器内的项目新增或者移除时产生的事件
5 | */
6 | function onDidChangeWorkspaceFolders() {
7 | let wsFoldersChangeDisplose = hx.workspace.onDidChangeWorkspaceFolders(function(event) {
8 | if (event.added) {
9 | event.added.forEach(item => console.log("新增了项目:", item.name));
10 | }
11 | if (event.removed) {
12 | event.removed.forEach(item => console.log("移除了项目:", item.name));
13 | }
14 | });
15 | }
16 |
17 | module.exports = {
18 | onDidChangeWorkspaceFolders
19 | };
20 |
--------------------------------------------------------------------------------
/api/workspace/onDidOpenTextDocument.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 |
3 | /**
4 | * @description 文档打开时的事件
5 | */
6 | function onDidOpenTextDocument() {
7 | let onDidOpenTextDocumentEventDispose = hx.workspace.onDidOpenTextDocument(function(event) {
8 | console.log('---------------------------');
9 | console.log(event);
10 | });
11 | }
12 |
13 | module.exports = {
14 | onDidOpenTextDocument
15 | };
16 |
--------------------------------------------------------------------------------
/api/workspace/onDidSaveTextDocument.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 |
3 | /**
4 | * @description 文档被保存时的事件
5 | */
6 | function onDidSaveTextDocument() {
7 | let onDidSaveTextDocumentEventDispose = hx.workspace.onDidSaveTextDocument(function(event) {
8 | console.log(event);
9 | // 获取文件路径与行数
10 | console.log("当前触发保存的文件路径为: ", event.uri.fsPath);
11 | console.log("当前触发保存的文件行数为",event.lineCount);
12 | });
13 | }
14 |
15 | module.exports = {
16 | onDidSaveTextDocument
17 | };
--------------------------------------------------------------------------------
/api/workspace/onWillSaveTextDocument.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 |
3 | /**
4 | * @description 文档即将要保存的事件
5 | */
6 | function onWillSaveTextDocument() {
7 | let willSaveTextDocumentEventDispose = hx.workspace.onWillSaveTextDocument(function(event) {
8 | let document = event.document;
9 |
10 | // 获取文件路径与行数
11 | console.log("当前触发保存的文件路径为: ", document.uri.fsPath);
12 | console.log("当前触发保存的文件行数为",document.lineCount);
13 | });
14 | }
15 |
16 | module.exports = {
17 | onWillSaveTextDocument
18 | };
--------------------------------------------------------------------------------
/api/workspace/openTextDocument.js:
--------------------------------------------------------------------------------
1 | var hx = require("hbuilderx");
2 | var fs = require("fs");
3 | var path = require("path");
4 |
5 | /**
6 | * @description 通过指定的uri打开一个文档
7 | */
8 | function openTextDocument() {
9 | // 文档地址
10 | var current_dir = __dirname;
11 | var random_filename = String(Date.parse(new Date())) + ".log";
12 | let uri = path.join(__dirname, random_filename);
13 |
14 | // 随机创建一个文件并打开
15 | fs.writeFile(uri, "这是一个刚刚创建的文件,创建后,使用hx.workspace.openTextDocument()打开了它",err => {
16 | if (err) {
17 | hx.window.showErrorMessage("创建测试文件失败!");
18 | } else {
19 | var documentPromise = hx.workspace.openTextDocument(uri);
20 | documentPromise.then(function(document) {
21 | console.log(document);
22 | console.log("当前打开的文档是: ", document.fileName);
23 | });
24 | }
25 | });
26 | }
27 |
28 | module.exports = {
29 | openTextDocument
30 | };
31 |
--------------------------------------------------------------------------------
/commandPanel.js:
--------------------------------------------------------------------------------
1 | const hx = require('hbuilderx');
2 |
3 | let packageFile = require('./package.json');
4 | let commands = packageFile.contributes.commands;
5 |
6 | /**
7 | * @description 命令面板
8 | * @datetime 2020-10-30 10:16:00
9 | */
10 | function showCommandPanel(param) {
11 | try{
12 | count('CommandPanel').catch( error=> {});
13 | }catch(e){};
14 |
15 | let tmp = [];
16 | for (let s of commands) {
17 | if (s.command != 'api.CommandPanel') {
18 | tmp.push(s);
19 | }
20 | };
21 |
22 | let data = JSON.parse(JSON.stringify(tmp).replace(/title/g,"label"));
23 | const pickResult = hx.window.showQuickPick(data, {
24 | placeHolder: '请选择要执行的操作'
25 | });
26 |
27 | pickResult.then(function(result) {
28 | if (!result) { return; };
29 | let cmd = result.command;
30 | hx.commands.executeCommand(cmd, param);
31 | });
32 | };
33 |
34 | module.exports = showCommandPanel;
35 |
--------------------------------------------------------------------------------
/extension.js:
--------------------------------------------------------------------------------
1 | const hx = require("hbuilderx");
2 | const path = require("path");
3 |
4 | // api
5 | const commands = require("./api/commands/executeCommand.js");
6 |
7 | const setStatusBarMessage = require('./api/window/setStatusBarMessage.js');
8 | const clearStatusBarMessage = require('./api/window/clearStatusBarMessage.js');
9 | const showErrorMessage = require('./api/window/showErrorMessage.js');
10 | const showInformationMessage = require('./api/window/showInformationMessage.js');
11 | const showWarningMessage = require('./api/window/showWarningMessage.js');
12 | const showMessageBox = require('./api/window/showMessageBox.js');
13 | const showQuickPick = require('./api/window/showQuickPick.js');
14 | const getActiveTextEditor = require('./api/window/getActiveTextEditor.js');
15 | const createOutputChannel = require('./api/window/createOutputChannel.js');
16 | const showInputBox = require('./api/window/showInputBox.js');
17 | const WebviewDialog = require('./api/window/WebviewDialog.js');
18 | const showFormDialog = require('./api/window/showFormDialog.js');
19 | const createStatusBarItem = require('./api/window/createStatusBarItem.js');
20 |
21 | const openTextDocument = require('./api/workspace/openTextDocument.js');
22 | const onWillSaveTextDocument = require('./api/workspace/onWillSaveTextDocument.js');
23 | const onDidChangeTextDocument = require('./api/workspace/onDidChangeTextDocument.js');
24 | const onDidSaveTextDocument = require('./api/workspace/onDidSaveTextDocument.js');
25 | const onDidOpenTextDocument = require('./api/workspace/onDidOpenTextDocument.js');
26 | const onDidChangeWorkspaceFolders = require('./api/workspace/onDidChangeWorkspaceFolders.js');
27 | const onDidChangeConfiguration = require('./api/workspace/onDidChangeConfiguration.js')
28 | const applyEdit = require('./api/workspace/applyEdit.js');
29 | const getConfiguration = require('./api/workspace/getConfiguration.js');
30 | const getWorkspaceFolders = require('./api/workspace/getWorkspaceFolders.js');
31 | const getWorkspaceFolder = require('./api/workspace/getWorkspaceFolder.js');
32 | const copyFileWithPrompt = require('./api/workspace/copyFileWithPrompt.js');
33 |
34 | const textEditor = require('./api/textEditor/textEditor.js');
35 | const lineFromPosition = require('./api/textEditor/lineFromPosition.js');
36 | const lineAt = require('./api/textEditor/lineAt.js');
37 | const getText = require('./api/textEditor/getText.js');
38 | const uri = require('./api/textEditor/uri.js');
39 | const setSelection = require('./api/textEditor/setSelection.js');
40 |
41 | const DiagnosticCollection = require('./api/languages/DiagnosticCollection.js');
42 |
43 | const help = require('./api/help/help.js');
44 | const openExternal = require('./api/env/openExternal.js');
45 | const clipboard = require('./api/env/clipboard.js');
46 | const authorize = require('./api/authorize/index.js');
47 | const handleJson = require('./api/util/json.js');
48 |
49 | const showCommandPanel = require('./commandPanel.js');
50 |
51 | var DemoTreeDataProvider = require('./api/treeview/treeview.js').DemoTreeDataProvider;
52 | var showWebView = require('./api/webview/webview.js');
53 | var test = require('./test/test.js');
54 |
55 | var CatCustomEditorProvider = require('./api/customEditor/custom.js');
56 |
57 |
58 | //该方法将在插件激活的时候调用
59 | function activate(context) {
60 | hx.app.registService("api.pack_example", (context) => {
61 | console.log("path:" + context.pkgLocation);
62 | });
63 |
64 | // command
65 | let CommandPanel = hx.commands.registerCommand('api.CommandPanel', () => {
66 | showCommandPanel();
67 | });
68 | context.subscriptions.push(CommandPanel);
69 |
70 | // run test
71 | let runtest = hx.commands.registerCommand('api.runtest', () => {
72 | test.runtest();
73 | });
74 | context.subscriptions.push(runtest);
75 |
76 | // commands
77 | let api_commands = hx.commands.registerCommand('api.commands', () => {
78 | commands.executeCommand();
79 | });
80 | context.subscriptions.push(api_commands);
81 |
82 | // window Api: 设置状态栏消息 info
83 | let api_status_bar_info_message = hx.commands.registerCommand('api.status_bar_info_message', () => {
84 | setStatusBarMessage.setStatusBarMessage("info");
85 | });
86 | context.subscriptions.push(api_status_bar_info_message);
87 |
88 | // window Api: 设置状态栏消息 error
89 | let api_status_bar_error_message = hx.commands.registerCommand('api.status_bar_error_message', () => {
90 | setStatusBarMessage.setStatusBarMessage("error");
91 | });
92 | context.subscriptions.push(api_status_bar_error_message);
93 |
94 | // window Api: 设置状态栏消息 warn
95 | let api_status_bar_warn_message = hx.commands.registerCommand('api.status_bar_warn_message', () => {
96 | setStatusBarMessage.setStatusBarMessage("warn");
97 | });
98 | context.subscriptions.push(api_status_bar_warn_message);
99 |
100 | // window Api: 设置状态栏消息 warn
101 | let api_status_bar_timeout_message = hx.commands.registerCommand('api.status_bar_timeout_message', () => {
102 | setStatusBarMessage.setStatusBarMessage("info", 2000);
103 | });
104 | context.subscriptions.push(api_status_bar_timeout_message);
105 |
106 | // window Api: 清空设置状态栏消息
107 | let api_clear_status_bar_message = hx.commands.registerCommand('api.clear_status_bar_message', () => {
108 | clearStatusBarMessage.clearStatusBarMessage();
109 | });
110 | context.subscriptions.push(api_clear_status_bar_message);
111 |
112 | // window Api: 右下角错误通知栏
113 | let api_show_error_message = hx.commands.registerCommand('api.show_error_message', () => {
114 | showErrorMessage.showErrorMessage();
115 | });
116 | context.subscriptions.push(api_show_error_message);
117 |
118 | // window Api: 右下角info通知栏
119 | let api_show_info_message = hx.commands.registerCommand('api.show_info_message', () => {
120 | showInformationMessage.showInformationMessage();
121 | });
122 | context.subscriptions.push(api_show_info_message);
123 |
124 | // window Api: 右下角warning通知栏
125 | let api_show_warning_message = hx.commands.registerCommand('api.show_warning_message', () => {
126 | showWarningMessage.showWarningMessage();
127 | });
128 | context.subscriptions.push(api_show_warning_message);
129 |
130 | // window Api: show Box
131 | let api_window_show_message_box = hx.commands.registerCommand('api.window_show_message_box', () => {
132 | showMessageBox();
133 | });
134 | context.subscriptions.push(api_window_show_message_box);
135 |
136 | // window Api: 在窗口中间弹出一个可搜索的建议选择列表
137 | let api_window_show_quick_pick = hx.commands.registerCommand('api.window_show_quick_pick', () => {
138 | showQuickPick.showQuickPick();
139 | });
140 | context.subscriptions.push(api_window_show_quick_pick);
141 |
142 | // window Api: show_input_box
143 | let api_window_show_input_box = hx.commands.registerCommand('api.window_show_input_box', () => {
144 | showInputBox.showInputBox();
145 | });
146 | context.subscriptions.push(api_window_show_input_box);
147 |
148 | // window Api: createWebViewDialog
149 | let api_window_WebviewDialog = hx.commands.registerCommand('api.window_WebviewDialog', ()=> {
150 | WebviewDialog();
151 | });
152 | context.subscriptions.push(api_window_WebviewDialog);
153 |
154 | // window Api: window_showFormDialog
155 | let api_window_showFormDialog = hx.commands.registerCommand('api.window_showFormDialog', ()=> {
156 | showFormDialog();
157 | });
158 | context.subscriptions.push(api_window_showFormDialog);
159 |
160 | // window Api: 获取当前激活的编辑器名称
161 | let api_get_active_text_editor = hx.commands.registerCommand('api.get_active_text_editor', () => {
162 | getActiveTextEditor.getActiveTextEditor("filename");
163 | });
164 | context.subscriptions.push(api_get_active_text_editor);
165 |
166 | // window Api: 获取项目类型
167 | let api_get_active_text_editor_for_nature = hx.commands.registerCommand('api.get_active_text_editor_for_nature', () => {
168 | getActiveTextEditor.getActiveTextEditor("nature");
169 | });
170 | context.subscriptions.push(api_get_active_text_editor_for_nature);
171 |
172 | // window Api: 获取项目名称
173 | let api_get_active_text_editor_for_project_name = hx.commands.registerCommand('api.get_active_text_editor_for_project_name', () => {
174 | getActiveTextEditor.getActiveTextEditor("project_name");
175 | });
176 | context.subscriptions.push(api_get_active_text_editor_for_project_name);
177 |
178 | // window Api: 创建输出控制台
179 | let api_window_create_output_channel = hx.commands.registerCommand('api.window_create_output_channel', () => {
180 | createOutputChannel.createOutputChannel();
181 | });
182 | context.subscriptions.push(api_window_create_output_channel);
183 |
184 | // window Api: createStatusBarItem
185 | let api_window_createStatusBarItem = hx.commands.registerCommand('api.window_createStatusBarItem', () => {
186 | createStatusBarItem();
187 | });
188 | context.subscriptions.push(api_window_createStatusBarItem);
189 |
190 | // workspace Api: 通过uri打开文档
191 | let api_open_text_document = hx.commands.registerCommand('api.open_text_document', () => {
192 | openTextDocument.openTextDocument();
193 | });
194 | context.subscriptions.push(api_open_text_document);
195 |
196 | // workspace Api: 文档即将要保存的事件
197 | let api_on_will_save_text_document = hx.commands.registerCommand('api.on_will_save_text_document', () => {
198 | onWillSaveTextDocument.onWillSaveTextDocument();
199 | });
200 | context.subscriptions.push(api_on_will_save_text_document);
201 |
202 | // workspace Api: 文档被修改时的事件
203 | let api_on_did_change_text_document = hx.commands.registerCommand('api.on_did_change_text_document', () => {
204 | onDidChangeTextDocument.onDidChangeTextDocument();
205 | });
206 | context.subscriptions.push(api_on_did_change_text_document);
207 |
208 | let api_on_did_open_text_document = hx.commands.registerCommand('api.on_did_open_text_document', () => {
209 | onDidOpenTextDocument.onDidOpenTextDocument()
210 | });
211 | context.subscriptions.push(api_on_did_open_text_document);
212 |
213 | // workspace Api: 文档被保存时的事件
214 | let api_on_did_save_text_document = hx.commands.registerCommand('api.on_did_save_text_document', () => {
215 | onDidSaveTextDocument.onDidSaveTextDocument();
216 | });
217 | context.subscriptions.push(api_on_did_save_text_document);
218 |
219 | // workspace Api:
220 | let api_on_did_change_forkspace_folders = hx.commands.registerCommand('api.on_did_change_forkspace_folders', () => {
221 | onDidChangeWorkspaceFolders.onDidChangeWorkspaceFolders()
222 | });
223 | context.subscriptions.push(api_on_did_change_forkspace_folders);
224 |
225 | // workspace Api: applyEdit
226 | let api_workspace_apply_edit = hx.commands.registerCommand('api.workspace_apply_edit', () => {
227 | applyEdit.applyEdit();
228 | });
229 | context.subscriptions.push(api_workspace_apply_edit);
230 |
231 | // workspace Api: getWorkspaceFolders
232 | let api_get_workspace_folders = hx.commands.registerCommand('api.get_workspace_folders', () => {
233 | getWorkspaceFolders.getWorkspaceFolders();
234 | });
235 | context.subscriptions.push(api_get_workspace_folders);
236 |
237 | // workspace Api: getWorkspaceFolder
238 | let api_get_workspace_folder = hx.commands.registerCommand('api.get_workspace_folder', () => {
239 | getWorkspaceFolder.getWorkspaceFolder();
240 | });
241 | context.subscriptions.push(api_get_workspace_folder);
242 |
243 | // workspace Api: onDidChangeConfiguration
244 | let api_on_did_chanage_configuration = hx.commands.registerCommand('api.on_did_chanage_configuration', () => {
245 | onDidChangeConfiguration.onDidChangeConfiguration()
246 | });
247 | context.subscriptions.push(api_on_did_chanage_configuration);
248 |
249 | // workspace Api: getConfiguration 根据指定的section获取对应配置
250 | let api_workspace_get_configuration = hx.commands.registerCommand('api.workspace_get_configuration', () => {
251 | getConfiguration.getConfiguration();
252 | });
253 | context.subscriptions.push(api_workspace_get_configuration);
254 |
255 | // workspace Api: getConfiguration update
256 | let api_workspace_update_configuration = hx.commands.registerCommand('api.workspace_update_configuration',() => {
257 | getConfiguration.updateConfiguration();
258 | });
259 | context.subscriptions.push(api_workspace_update_configuration);
260 |
261 | // workspace Api: getConfiguration add
262 | let api_workspace_add_configuration = hx.commands.registerCommand('api.workspace_add_configuration', () => {
263 | getConfiguration.addConfiguration();
264 | });
265 | context.subscriptions.push(api_workspace_add_configuration);
266 |
267 | // workspace Api: copyFileWithPrompt
268 | let api_workspace_copy_file_with_prompt = hx.commands.registerCommand('api.workspace_copy_file_with_prompt', () => {
269 | copyFileWithPrompt();
270 | });
271 | context.subscriptions.push(api_workspace_copy_file_with_prompt);
272 |
273 | // window Api: 打印uri所有信息
274 | let api_uri = hx.commands.registerCommand('api.uri', () => {
275 | uri.uri();
276 | });
277 | context.subscriptions.push(api_uri);
278 |
279 | // TextEditor Api: TextEditor
280 | let api_text_editor = hx.commands.registerCommand('api.text_editor', () => {
281 | textEditor.textEditor("document");
282 | });
283 | context.subscriptions.push(api_text_editor);
284 |
285 | // TextEditor Api: TextEditor for line text 获取光标所在行内容
286 | let api_text_editor_linetext = hx.commands.registerCommand('api.text_editor_linetext', () => {
287 | textEditor.textEditor("linetext");
288 | });
289 | context.subscriptions.push(api_text_editor_linetext);
290 |
291 | // TextEditor Api: 把当前选中的内容由小写转换大写
292 | let api_text_editor_line_to_upper_case = hx.commands.registerCommand('api.text_editor_line_to_upper_case',() => {
293 | textEditor.textEditor("UpperCase");
294 | });
295 | context.subscriptions.push(api_text_editor_line_to_upper_case);
296 |
297 | // TextEditor Api:获取当前文件tabSize
298 | let api_text_editor_indent = hx.commands.registerCommand('api.text_editor_indent', () => {
299 | textEditor.textEditor("tabSize");
300 | });
301 | context.subscriptions.push(api_text_editor_indent);
302 |
303 | // TextEditor Api: lineFromPosition 根据光标位置获取光标所在行
304 | let api_text_lineFromPosition = hx.commands.registerCommand('api.text_lineFromPosition', () => {
305 | lineFromPosition.lineFromPosition();
306 | });
307 | context.subscriptions.push(api_text_lineFromPosition);
308 |
309 | // TextEditor Api: lineFromPosition 根据光标位置获取光标所在行
310 | let api_text_lineAt = hx.commands.registerCommand('api.text_lineAt', () => {
311 | lineAt.lineAt();
312 | });
313 | context.subscriptions.push(api_text_lineAt);
314 |
315 | // TextEditor Api: getText 获取指定区域内的文本
316 | let api_text_getText = hx.commands.registerCommand('api.text_getText', () => {
317 | getText.getText();
318 | });
319 | context.subscriptions.push(api_text_getText);
320 |
321 | // setSelection
322 | let api_set_selection = hx.commands.registerCommand('api.set_selection', () => {
323 | setSelection.setSelection()
324 | });
325 | context.subscriptions.push(api_set_selection);
326 |
327 | // Languages Api: DiagnosticCollection 创建问题集合
328 | let api_languages_create_diagnostics_collection = hx.commands.registerCommand('api.languages_create_diagnostics_collection', () => {
329 | DiagnosticCollection.createDiagnosticCollection();
330 | });
331 | context.subscriptions.push(api_languages_create_diagnostics_collection);
332 |
333 | // help
334 | let open_help = hx.commands.registerCommand("api.open_help", () => {
335 | help.openHelp();
336 | });
337 | context.subscriptions.push(open_help);
338 |
339 | // openExternals
340 | let api_openExternal_url = hx.commands.registerCommand('api.openExternal_url', () => {
341 | openExternal.openExternal("https://www.baidu.com")
342 | });
343 | context.subscriptions.push(api_openExternal_url);
344 |
345 | // openExternals
346 | let api_openExternal_mail = hx.commands.registerCommand('api.openExternal_mail', () => {
347 | openExternal.openExternal("mailto:ide@dcloud.io")
348 | });
349 | context.subscriptions.push(api_openExternal_mail);
350 |
351 | // clipboard
352 | let api_clipboard_write = hx.commands.registerCommand('api.clipboard_write', () => {
353 | clipboard.clipboardWrite();
354 | });
355 | context.subscriptions.push(api_clipboard_write);
356 |
357 | // clipboard
358 | let api_clipboard_read = hx.commands.registerCommand('api.clipboard_read', () => {
359 | clipboard.clipboardRead();
360 | });
361 | context.subscriptions.push(api_clipboard_read);
362 |
363 | // authorize login
364 | let api_authorize_login = hx.commands.registerCommand('api.authorize_login', () => {
365 | authorize.login();
366 | });
367 | context.subscriptions.push(api_authorize_login);
368 |
369 | // authorize logout
370 | let api_authorize_logout = hx.commands.registerCommand('api.authorize_logout', () => {
371 | authorize.logout();
372 | });
373 | context.subscriptions.push(api_authorize_logout);
374 |
375 | //Api: treeview
376 | hx.window.createTreeView("api.treedemo", {
377 | showCollapseAll: true,
378 | treeDataProvider: new DemoTreeDataProvider()
379 | });
380 |
381 | // Api: webview
382 | let webviewPanel = hx.window.createWebView("api.WebView", {
383 | enableScritps: true
384 | });
385 | showWebView.showWebView(webviewPanel);
386 |
387 | let webviewPanel2 = hx.window.createWebView("api.WebView2", {
388 | enableScritps: true
389 | });
390 | showWebView.showWebView(webviewPanel2);
391 |
392 | // Api: 自定义编辑器 customEditor
393 | let provider = new CatCustomEditorProvider({
394 | supportsMultipleEditorsPerDocument: true
395 | });
396 | hx.window.registerCustomEditorProvider("catEdit.catScratch", provider);
397 |
398 | let CustomEditorTest = hx.commands.registerCommand('api.CustomEditor', (param) => {
399 | let f = path.join(__dirname, "api", "customEditor", "test.cscratch");
400 | hx.workspace.openTextDocument(f);
401 | });
402 | context.subscriptions.push(CustomEditorTest);
403 |
404 | // 操作json
405 | let hjson = hx.commands.registerCommand('api.util_handleJson', () => {
406 | let rwJson = new handleJson();
407 | rwJson.main();
408 | });
409 | context.subscriptions.push(hjson);
410 | };
411 |
412 |
413 | //该方法将在插件禁用的时候调用(目前是在插件卸载的时候触发)
414 | function deactivate() {
415 |
416 | };
417 |
418 |
419 | module.exports = {
420 | activate,
421 | deactivate
422 | };
423 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "hbuilderx-extension-samples",
3 | "description": "HBuilderX插件扩展api示例",
4 | "version": "0.0.2",
5 | "publisher": "wdl",
6 | "engines": {
7 | "HBuilderX": "^2.7.0"
8 | },
9 | "categories": ["Other"],
10 | "main": "./extension",
11 | "activationEvents": ["onCommand:api.commands", "onCommand:api.CommandPanel",
12 | "onCommand:api.status_bar_info_message", "onCommand:api.status_bar_warn_message",
13 | "onCommand:api.status_bar_error_message", "onCommand:api.status_bar_timeout_message",
14 | "onCommand:api.clear_status_bar_message", "onCommand:api.show_error_message",
15 | "onCommand:api.show_info_message", "onCommand:api.show_warning_message",
16 | "onCommand:api.window_show_quick_pick", "onCommand:api.window_show_input_box",
17 | "onCommand:api.window_show_message_box", "onCommand:api.window_WebviewDialog",
18 | "onCommand:api.window_showFormDialog", "onCommand:api.window_createStatusBarItem",
19 | "onCommand:api.get_active_text_editor", "onCommand:api.get_active_text_editor_for_nature",
20 | "onCommand:api.get_active_text_editor_for_project_name", "onCommand:api.window_create_output_channel",
21 | "onCommand:api.open_text_document", "onCommand:api.on_will_save_text_document",
22 | "onCommand:api.on_did_change_text_document", "onCommand:api.on_did_open_text_document",
23 | "onCommand:api.workspace_apply_edit", "onCommand:api.workspace_get_configuration",
24 | "onCommand:api.workspace_update_configuration", "onCommand:api.workspace_add_configuration",
25 | "onCommand:api.get_workspace_folders", "onCommand:api.get_workspace_folder",
26 | "onCommand:api.on_did_chanage_configuration", "onCommand:api.on_did_change_forkspace_folders",
27 | "onCommand:api.workspace_copy_file_with_prompt", "onCommand:api.text_editor",
28 | "onCommand:api.text_editor_linetext", "onCommand:api.text_editor_line_to_upper_case",
29 | "onCommand:api.text_editor_indent", "onCommand:api.text_lineFromPosition", "onCommand:api.text_lineAt",
30 | "onCommand:api.text_getText", "onCommand:api.set_selection", "onCommand:api.uri",
31 | "onCommand:api.languages_create_diagnostics_collection", "onCommand:api.open_help",
32 | "onCommand:api.openExternal_url", "onCommand:api.openExternal_mail", "onCommand:api.clipboard_write",
33 | "onCommand:api.clipboard_read", "onCommand:api.authorize_login", "onCommand:api.authorize_logout",
34 | "onCommand:api.util_handleJson", "onView:api.treedemo", "onView:api.WebView", "onView:api.WebView2",
35 | "onCommand:api.runtest", "onCommand:api.CustomEditor", "onCustomEditor:catEdit.catScratch",
36 | "onAppService:api.pack_example"
37 | ],
38 | "contributes": {
39 | "viewsContainers": {
40 | "activitybar": [{
41 | "id": "demoview",
42 | "title": "DemoView"
43 | }, {
44 | "id": "WebViewcontainerId2",
45 | "title": "webview好好工作"
46 | }],
47 | "rightside": [{
48 | "id": "WebViewcontainerId",
49 | "title": "webview好好学习"
50 | }]
51 | },
52 | "views": {
53 | "demoview": [{
54 | "id": "api.treedemo",
55 | "name": "DemoView"
56 | }],
57 | "WebViewcontainerId": [{
58 | "id": "api.WebView",
59 | "title": "webview - 好好工作"
60 | }],
61 | "WebViewcontainerId2": [{
62 | "id": "api.WebView2",
63 | "title": "webview - 好好学习"
64 | }]
65 | },
66 | "app-services": [{
67 | "title": "打包扩展",
68 | "handler": "api.pack_example"
69 | }],
70 | "customEditors": [{
71 | "viewType": "catEdit.catScratch",
72 | "displayName": "Cat Scratch",
73 | "selector": [{
74 | "fileNamePattern": "*.cscratch"
75 | }],
76 | "priority": "default"
77 | }],
78 | "snippets": [{
79 | "language": "python",
80 | "path": "./snippets/python.json"
81 | }],
82 | "configuration": {
83 | "title": "hbuilderx-extension-samples",
84 | "properties": {
85 | "hbuilderx-extension-samples.pluginsTest1": {
86 | "type": "boolean",
87 | "default": true,
88 | "description": "测试:1"
89 | },
90 | "hbuilderx-extension-samples.pluginsTest2": {
91 | "type": "boolean",
92 | "default": false,
93 | "description": "测试:2"
94 | }
95 | }
96 | },
97 | "icons": {
98 | "message": {
99 | "description": "message icon",
100 | "default": {
101 | "fontPath": "./static/fileiconfont.ttf",
102 | "fontCharacter": "\\E90A",
103 | "fontColor": "#C1A766"
104 | }
105 | }
106 | },
107 | "commands": [{
108 | "command": "api.runtest",
109 | "title": "api 测试"
110 | }, {
111 | "command": "api.CommandPanel",
112 | "title": "打开API命令面板"
113 | }, {
114 | "command": "api.commands",
115 | "title": "执行内置命令"
116 | }, {
117 | "command": "api.status_bar_info_message",
118 | "title": "setStatusBarMessage 状态栏info消息"
119 | }, {
120 | "command": "api.status_bar_warn_message",
121 | "title": "setStatusBarMessage 状态栏warn消息"
122 | }, {
123 | "command": "api.status_bar_error_message",
124 | "title": "setStatusBarMessage 状态栏error消息"
125 | }, {
126 | "command": "api.status_bar_timeout_message",
127 | "title": "setStatusBarMessage 状态栏消息: 2s自动隐藏"
128 | }, {
129 | "command": "api.clear_status_bar_message",
130 | "title": "clearStatusBarMessage 清空状态栏消息"
131 | }, {
132 | "command": "api.show_error_message",
133 | "title": "showErrorMessage 右下角error通知框"
134 | }, {
135 | "command": "api.show_info_message",
136 | "title": "showInformationMessage 右下角info通知框"
137 | }, {
138 | "command": "api.show_warning_message",
139 | "title": "showWarningMessage 右下角warning通知框"
140 | }, {
141 | "command": "api.window_show_message_box",
142 | "title": "showMessageBox 对话框"
143 | }, {
144 | "command": "api.window_WebviewDialog",
145 | "title": "WebviewDialog"
146 | }, {
147 | "command": "api.window_showFormDialog",
148 | "title": "showFormDialog"
149 | }, {
150 | "command": "api.window_show_quick_pick",
151 | "title": "showQuickPick 在窗口中间弹出一个可搜索的建议选择列表"
152 | }, {
153 | "command": "api.window_createStatusBarItem",
154 | "title": "创建一个状态栏元素"
155 | }, {
156 | "command": "api.get_active_text_editor",
157 | "title": "getActiveTextEditor 当前激活的编辑器名称"
158 | }, {
159 | "command": "api.get_active_text_editor_for_nature",
160 | "title": "getActiveTextEditor 获取项目类型"
161 | }, {
162 | "command": "api.get_active_text_editor_for_project_name",
163 | "title": "getActiveTextEditor 获取项目名称"
164 | }, {
165 | "command": "api.window_create_output_channel",
166 | "title": "createOutputChannel 创建输出控制台"
167 | }, {
168 | "command": "api.window_show_input_box",
169 | "title": "输入框"
170 | }, {
171 | "command": "api.open_text_document",
172 | "title": "openTextDocument 打开指定文档"
173 | }, {
174 | "command": "api.on_will_save_text_document",
175 | "title": "onWillSaveTextDocument 文档即将要保存的事件"
176 | }, {
177 | "command": "api.on_did_change_text_document",
178 | "title": "onDidChangeTextDocument 文档被修改时的事件"
179 | }, {
180 | "command": "api.on_did_save_text_document",
181 | "title": "onDidSaveTextDocument 文档被保存时的事件"
182 | }, {
183 | "command": "api.on_did_open_text_document",
184 | "title": "onDidOpenTextDocument 文档打开时的事件"
185 | }, {
186 | "command": "api.on_did_change_forkspace_folders",
187 | "title": "onDidChangeWorkspaceFolders 项目管理器内的项目新增或者移除时产生的事件"
188 | }, {
189 | "command": "api.get_workspace_folders",
190 | "title": "getWorkspaceFolders 获取项目管理器下所有的项目对象"
191 | }, {
192 | "command": "api.get_workspace_folder",
193 | "title": "getWorkspaceFolder 获取某个文件所在的项目"
194 | }, {
195 | "command": "api.on_did_chanage_configuration",
196 | "title": "onDidChangeConfiguration 全局配置改变事件"
197 | }, {
198 | "command": "api.workspace_copy_file_with_prompt",
199 | "title": "copyFileWithPrompt 复制文件"
200 | }, {
201 | "command": "api.workspace_apply_edit",
202 | "title": "applyEdit 执行指定的文档编辑操作"
203 | }, {
204 | "command": "api.workspace_get_configuration",
205 | "title": "getCongiguration 根据指定的section获取对应配置"
206 | }, {
207 | "command": "api.workspace_update_configuration",
208 | "title": "getCongiguration 根据指定的section更新对应配置"
209 | }, {
210 | "command": "api.workspace_add_configuration",
211 | "title": "getCongiguration 插入新值"
212 | }, {
213 | "command": "api.uri",
214 | "title": "getActiveTextEditor uri"
215 | }, {
216 | "command": "api.text_editor",
217 | "title": "TextEditor"
218 | }, {
219 | "command": "api.text_editor_linetext",
220 | "title": "TextEditor 当前光标所在行内容"
221 | }, {
222 | "command": "api.text_editor_line_to_upper_case",
223 | "title": "TextEditor 当前选中内容,由小写转换大写"
224 | }, {
225 | "command": "api.text_editor_indent",
226 | "title": "TextEditor 获取当前文件缩进符长度"
227 | }, {
228 | "command": "api.text_lineFromPosition",
229 | "title": "TextEditor 获取当前光标所在行内容"
230 | }, {
231 | "command": "api.text_lineAt",
232 | "title": "TextEditor 获取指定行内容"
233 | }, {
234 | "command": "api.text_getText",
235 | "title": "TextEditor 获取指定区域内容"
236 | }, {
237 | "command": "api.set_selection",
238 | "title": "TextEditor setSelection"
239 | }, {
240 | "command": "api.languages_create_diagnostics_collection",
241 | "title": "创建问题集合"
242 | }, {
243 | "command": "api.open_help",
244 | "title": "HBuilderX插件开发文档"
245 | }, {
246 | "command": "api.openExternal_url",
247 | "title": "打开外部链接"
248 | }, {
249 | "command": "api.openExternal_mail",
250 | "title": "发送邮件"
251 | }, {
252 | "command": "api.clipboard_write",
253 | "title": "写入剪切板"
254 | }, {
255 | "command": "api.clipboard_read",
256 | "title": "读取剪切板"
257 | }, {
258 | "command": "api.CustomEditor",
259 | "title": "打开自定义编辑器"
260 | }, {
261 | "command": "api.authorize_login",
262 | "title": "用户认证"
263 | }, {
264 | "command": "api.authorize_logout",
265 | "title": "用户退出登录"
266 | }, {
267 | "command": "api.util_handleJson",
268 | "title": "操作json"
269 | }],
270 | "menus": {
271 | "explorer/context": [],
272 | "menubar/tool": [{
273 | "command": "api.CommandPanel",
274 | "title": "HBuilderX API命令面板"
275 | }],
276 | "menubar/help": [{
277 | "command": "api.open_help",
278 | "title": "HBuilderX插件开发文档",
279 | "group": "documents"
280 | }],
281 | "editor/context": [{
282 | "title": "插件api: commands",
283 | "group": "z_commands",
284 | "id": "builtIn"
285 | }, {
286 | "command": "api.commands",
287 | "title": "执行内置命令: 关闭所有打开的编辑器",
288 | "group": "builtIn@1"
289 | }, {
290 | "title": "插件api: 状态栏消息",
291 | "group": "z_commands",
292 | "id": "statusBarMessage"
293 | }, {
294 | "command": "api.status_bar_info_message",
295 | "title": "info消息",
296 | "group": "statusBarMessage@1"
297 | }, {
298 | "command": "api.status_bar_error_message",
299 | "title": "error消息",
300 | "group": "statusBarMessage@2"
301 | }, {
302 | "command": "api.status_bar_warn_message",
303 | "title": "warning消息",
304 | "group": "statusBarMessage@3"
305 | }, {
306 | "command": "api.status_bar_timeout_message",
307 | "title": "2s后自动隐藏",
308 | "group": "statusBarMessage@4"
309 | }, {
310 | "command": "api.clear_status_bar_message",
311 | "title": "清空状态栏消息",
312 | "group": "statusBarMessage@5"
313 | }, {
314 | "title": "插件api: 右下角通知框",
315 | "group": "z_commands",
316 | "id": "message"
317 | }, {
318 | "command": "api.show_error_message",
319 | "title": "error通知框",
320 | "group": "message@1"
321 | }, {
322 | "command": "api.show_info_message",
323 | "title": "info通知框",
324 | "group": "message@2"
325 | }, {
326 | "command": "api.show_warning_message",
327 | "title": "warning通知框",
328 | "group": "message@3"
329 | }, {
330 | "title": "插件api: window",
331 | "group": "z_commands",
332 | "id": "window"
333 | }, {
334 | "command": "api.window_show_quick_pick",
335 | "title": "QuickPick",
336 | "group": "window@1"
337 | }, {
338 | "command": "api.window_create_output_channel",
339 | "title": "创建输出控制台",
340 | "group": "window@2"
341 | }, {
342 | "command": "api.window_show_input_box",
343 | "title": "显示输入框",
344 | "group": "window@3"
345 | }, {
346 | "command": "api.window_show_message_box",
347 | "title": "显示对话框",
348 | "group": "window@4"
349 | }, {
350 | "command": "api.window_WebviewDialog",
351 | "title": "WebviewDialog",
352 | "group": "window@5"
353 | }, {
354 | "command": "api.window_showFormDialog",
355 | "title": "showFormDialog",
356 | "group": "window@6"
357 | }, {
358 | "command": "api.window_createStatusBarItem",
359 | "title": "createStatusBarItem",
360 | "group": "window@7"
361 | }, {
362 | "title": "插件api: workspace",
363 | "id": "workspace",
364 | "group": "z_commands"
365 | }, {
366 | "command": "api.open_text_document",
367 | "title": "openTextDocument",
368 | "group": "workspace@1"
369 | }, {
370 | "command": "api.on_will_save_text_document",
371 | "title": "onWillSaveTextDocument",
372 | "group": "workspace@2"
373 | }, {
374 | "command": "api.on_did_change_text_document",
375 | "title": "onDidChangeTextDocument",
376 | "group": "workspace@3"
377 | }, {
378 | "command": "api.on_did_save_text_document",
379 | "title": "onDidSaveTextDocument",
380 | "group": "workspace@4"
381 | }, {
382 | "command": "api.on_did_open_text_document",
383 | "title": "onDidOpenTextDocument",
384 | "group": "workspace@5"
385 | }, {
386 | "group": "workspace@6"
387 | }, {
388 | "command": "api.on_did_change_forkspace_folders",
389 | "title": "onDidChangeWorkspaceFolders",
390 | "group": "workspace@6"
391 | }, {
392 | "command": "api.get_workspace_folders",
393 | "title": "获取项目管理器下所有的项目对象",
394 | "group": "workspace@6"
395 | }, {
396 | "command": "api.get_workspace_folder",
397 | "title": "获取某个文件所在的项目",
398 | "group": "workspace@6"
399 | }, {
400 | "group": "workspace@7"
401 | }, {
402 | "command": "api.workspace_apply_edit",
403 | "title": "applyEdit",
404 | "group": "workspace@7"
405 | }, {
406 | "group": "workspace@8"
407 | }, {
408 | "command": "api.workspace_get_configuration",
409 | "title": "获取配置 getConfiguration",
410 | "group": "workspace@9"
411 | }, {
412 | "command": "api.workspace_update_configuration",
413 | "title": "更新配置 getConfiguration",
414 | "group": "workspace@10"
415 | }, {
416 | "command": "api.workspace_add_configuration",
417 | "title": "新增配置 getConfiguration",
418 | "group": "workspace@11"
419 | }, {
420 | "command": "api.on_did_chanage_configuration",
421 | "title": "onDidChangeConfiguration",
422 | "group": "workspace@12"
423 | }, {
424 | "command": "api.workspace_copy_file_with_prompt",
425 | "title": "copyFileWithPrompt",
426 | "group": "workspace@13"
427 | }, {
428 | "title": "插件api: getActiveTextEditor",
429 | "id": "getActiveTextEditor",
430 | "group": "z_commands"
431 | }, {
432 | "command": "api.get_active_text_editor",
433 | "title": "显示当前激活的编辑器名称",
434 | "group": "getActiveTextEditor@1"
435 | }, {
436 | "command": "api.get_active_text_editor_for_nature",
437 | "title": "获取项目类型",
438 | "group": "getActiveTextEditor@2"
439 | }, {
440 | "command": "api.get_active_text_editor_for_project_name",
441 | "title": "获取项目名称",
442 | "group": "getActiveTextEditor@3"
443 | }, {
444 | "title": "插件api: TextEditor",
445 | "id": "TextEditor",
446 | "group": "z_commands"
447 | }, {
448 | "command": "api.uri",
449 | "title": "uri: 显示所有uri信息",
450 | "group": "TextEditor@1"
451 | }, {
452 | "group": "TextEditor@1"
453 | }, {
454 | "command": "api.text_editor",
455 | "title": "document: 文件编辑器对象",
456 | "group": "TextEditor@1"
457 | }, {
458 | "command": "api.text_editor_linetext",
459 | "title": "selection: 当前光标所在行内容",
460 | "group": "TextEditor@2"
461 | }, {
462 | "command": "api.text_editor_line_to_upper_case",
463 | "title": "selection: 当前选中内容,由小写转换大写",
464 | "group": "TextEditor@3"
465 | }, {
466 | "command": "api.text_editor_indent",
467 | "title": "options: 获取当前文件缩进符长度",
468 | "group": "TextEditor@4"
469 | }, {
470 | "group": "TextEditor@5"
471 | }, {
472 | "command": "api.text_lineFromPosition",
473 | "title": "lineFromPosition 当前光标所在行内容",
474 | "group": "TextEditor@5"
475 | }, {
476 | "command": "api.text_lineAt",
477 | "title": "lineAt 获取指定行(第3行)内容",
478 | "group": "TextEditor@5"
479 | }, {
480 | "command": "api.text_getText",
481 | "title": "getText 获取指定区域内容(0,50)",
482 | "group": "TextEditor@5"
483 | }, {
484 | "command": "api.set_selection",
485 | "title": "setSelection 增加新的选择区域",
486 | "group": "TextEditor@6"
487 | }, {
488 | "title": "插件api: 问题集合",
489 | "id": "Diagnostic",
490 | "group": "z_commands"
491 | }, {
492 | "command": "api.languages_create_diagnostics_collection",
493 | "title": "创建问题集合",
494 | "group": "Diagnostic@1"
495 | }, {
496 | "title": "插件api: env",
497 | "id": "env",
498 | "group": "z_commands"
499 | }, {
500 | "command": "api.openExternal_url",
501 | "title": "打开外部链接",
502 | "group": "env@1"
503 | }, {
504 | "command": "api.openExternal_mail",
505 | "title": "发送email",
506 | "group": "env@2"
507 | }, {
508 | "command": "api.clipboard_write",
509 | "title": "写入剪切板",
510 | "group": "env@3"
511 | }, {
512 | "command": "api.clipboard_read",
513 | "title": "读取剪切板",
514 | "group": "env@4"
515 | }, {
516 | "title": "插件api: authorize",
517 | "id": "authorize",
518 | "group": "z_commands"
519 | }, {
520 | "command": "api.authorize_login",
521 | "title": "用户登录",
522 | "group": "authorize@1"
523 | }, {
524 | "command": "api.authorize_logout",
525 | "title": "用户退出登录",
526 | "group": "authorize@2"
527 | }, {
528 | "command": "api.CustomEditor",
529 | "title": "插件api: 自定义编辑器",
530 | "group": "z_commands"
531 | }, {
532 | "title": "插件api: util",
533 | "id": "util",
534 | "group": "z_commands"
535 | }, {
536 | "command": "api.util_handleJson",
537 | "title": "读写json",
538 | "group": "util@1"
539 | }, {
540 | "group": "z_commands"
541 | }]
542 | }
543 | },
544 | "extensionDependencies": ["plugin-manager"],
545 | "dependencies": {}
546 | }
547 |
--------------------------------------------------------------------------------
/snippets/c.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dcloudio/hbuilderx-extension-samples/b7ba7189bcfa7e1256227b22c38fb96ae55dce25/snippets/c.json
--------------------------------------------------------------------------------
/snippets/python.json:
--------------------------------------------------------------------------------
1 | {
2 | "Python": {
3 | "prefix": "py",
4 | "body": ["#!/usr/bin/env python", "#-*- coding:utf-8 -*-", "", "$1"],
5 | "description": "python解释器"
6 | },
7 | "doc": {
8 | "prefix": "doc str",
9 | "body": ["\"\"\"${1:document String}\"\"\""],
10 | "description": "文档字符串"
11 | },
12 | "@wraps": {
13 | "prefix": "@wraps",
14 | "body": ["@wraps($1)"],
15 | "description": "装饰器"
16 | },
17 | "@classmethod": {
18 | "prefix": "@classmethod",
19 | "body": ["@classmethod"],
20 | "description": "类方法, classmethod 修饰符对应的函数不需要实例化,不需要 self 参数"
21 | },
22 | "@staticmethod": {
23 | "prefix": "@staticmethod",
24 | "body": ["@staticmethod"],
25 | "description": "staticmethod 返回函数的静态方法"
26 | },
27 | "import": {
28 | "prefix": "im",
29 | "body": ["import ${1:name}", "$0"],
30 | "description": ""
31 | },
32 | "from import": {
33 | "prefix": "fi",
34 | "body": ["from ${1:name} import ${1:name}", "$0"],
35 | "description": ""
36 | },
37 | "print": {
38 | "prefix": "p",
39 | "body": ["print($1)"],
40 | "description": ""
41 | },
42 | "print/format": {
43 | "prefix": "pf",
44 | "body": ["print(\"${1:{0}}\".format(${2:str}))"],
45 | "description": ""
46 | },
47 | "pprint": {
48 | "prefix": "pp",
49 | "body": ["pprint.pprint($1)"],
50 | "description": ""
51 | },
52 | "return": {
53 | "prefix": "return",
54 | "body": ["return ${1:value}"],
55 | "description": ""
56 | },
57 | "assert": {
58 | "prefix": "assert",
59 | "body": ["assert ${1:value}"],
60 | "description": ""
61 | },
62 | "raise": {
63 | "prefix": "raise",
64 | "body": ["raise ${1:value}"],
65 | "description": ""
66 | },
67 | "int": {
68 | "prefix": "int",
69 | "body": ["int(${1:str})"],
70 | "description": ""
71 | },
72 | "long": {
73 | "prefix": "long",
74 | "body": ["login(${1:str}, base=10)"],
75 | "description": ""
76 | },
77 | "float": {
78 | "prefix": "float",
79 | "body": ["float($1)"],
80 | "description": ""
81 | },
82 | "str": {
83 | "prefix": "str",
84 | "body": ["str($1)"],
85 | "description": ""
86 | },
87 | "round": {
88 | "prefix": "round",
89 | "body": ["round($1,$0)"],
90 | "description": ""
91 | },
92 | "isinstance ": {
93 | "prefix": "isinstance",
94 | "body": ["isinstance(${1:value},${0:data_type)"],
95 | "description": "判断一个对象是否是一个已知的类型"
96 | },
97 | "repr": {
98 | "prefix": "repr",
99 | "body": ["repr($1)"],
100 | "description": ""
101 | },
102 | "eval": {
103 | "prefix": "eval",
104 | "body": ["eval($1)"],
105 | "description": ""
106 | },
107 | "tuple": {
108 | "prefix": "tuple",
109 | "body": ["tuple($1)"],
110 | "description": ""
111 | },
112 | "list": {
113 | "prefix": "list",
114 | "body": ["list($1)"],
115 | "description": ""
116 | },
117 | "set": {
118 | "prefix": "set",
119 | "body": ["set($1)"],
120 | "description": ""
121 | },
122 | "dict": {
123 | "prefix": "dict",
124 | "body": ["dict($1)"],
125 | "description": ""
126 | },
127 | "frozenset": {
128 | "prefix": "frozenset",
129 | "body": ["frozenset($1)"]
130 | },
131 | "chr": {
132 | "prefix": "chr",
133 | "body": ["chr($1)"]
134 | },
135 | "unichr": {
136 | "prefix": "unichr",
137 | "body": ["unichr($1)"]
138 | },
139 | "ord": {
140 | "prefix": "ord",
141 | "body": ["ord($1)"]
142 | },
143 | "hex": {
144 | "prefix": "hex",
145 | "body": ["hex($1)"]
146 | },
147 | "oct": {
148 | "prefix": "oct",
149 | "body": ["oct($1)"]
150 | },
151 | "format": {
152 | "prefix": "format",
153 | "body": ["format($1)"],
154 | "triggerAssist": false
155 | },
156 | "join": {
157 | "prefix": "join",
158 | "body": ["'$1'.join($0)"]
159 | },
160 | "replace": {
161 | "prefix": "replace",
162 | "body": ["${1:str}.replace(\"${2:str1}\",\"${3:str2}\")"]
163 | },
164 | "len": {
165 | "prefix": "len",
166 | "body": ["len($1)"],
167 | "description": ""
168 | },
169 | "max": {
170 | "prefix": "max",
171 | "body": ["max($1)"],
172 | "description": ""
173 | },
174 | "min": {
175 | "prefix": "min",
176 | "body": ["min($1)"],
177 | "description": ""
178 | },
179 | "lower": {
180 | "prefix": "lower",
181 | "body": ["lower()"],
182 | "description": "字符串转为小写"
183 | },
184 | "sum": {
185 | "prefix": "sum",
186 | "body": ["sum($1)"],
187 | "description": ""
188 | },
189 | "reversed": {
190 | "prefix": "reversed",
191 | "body": ["reversed($1)"],
192 | "description": ""
193 | },
194 | "del": {
195 | "prefix": "del",
196 | "body": ["del"],
197 | "description": ""
198 | },
199 | "count": {
200 | "prefix": "count",
201 | "body": ["count($1)"],
202 | "description": ""
203 | },
204 | "type": {
205 | "prefix": "type",
206 | "body": ["type($1)"],
207 | "description": ""
208 | },
209 | "super": {
210 | "prefix": "super()",
211 | "body": ["super()"],
212 | "description": ""
213 | },
214 | "xrange": {
215 | "prefix": "xrange()",
216 | "body": ["xrange($1)"],
217 | "description": ""
218 | },
219 | "range": {
220 | "prefix": "range()",
221 | "body": ["range($1)"],
222 | "description": ""
223 | },
224 | "sorted": {
225 | "prefix": "sorted()",
226 | "body": ["sorted($1)"],
227 | "description": ""
228 | },
229 | "reduce": {
230 | "prefix": "reduce()",
231 | "body": ["reduce(${1:function},${2:iterable})"],
232 | "description": ""
233 | },
234 | "zip": {
235 | "prefix": "zip",
236 | "body": ["zip($1,$2)"],
237 | "description": ""
238 | },
239 | "list derivation": {
240 | "prefix": "list derivation",
241 | "body": ["${1:list_name} = [ i for i in ${2:list_name} ]"],
242 | "description": "列表推导式"
243 | },
244 | "list derivation if": {
245 | "prefix": "list derivation if",
246 | "body": ["${1:list_name} = [ i for i in ${2:list_name} if ${3:String} in i ]"],
247 | "description": "列表推导式,包含if条件"
248 | },
249 | "dict.clear()": {
250 | "prefix": "dict.clear()",
251 | "body": ["${1:dict}.clear()"],
252 | "description": ""
253 | },
254 | "dict.copy()": {
255 | "prefix": "dict.copy()",
256 | "body": ["${1:dict}.copy()"],
257 | "description": ""
258 | },
259 | "dict.fromkeys()": {
260 | "prefix": "dict.fromkeys()",
261 | "body": ["dict.fromkeys(${1:dictname})"],
262 | "description": ""
263 | },
264 | "dict.get()": {
265 | "prefix": "dict.get()",
266 | "body": ["${1:dict}..get(${1:value})"],
267 | "description": ""
268 | },
269 | "dict.has_key()": {
270 | "prefix": "dict.has_key()",
271 | "body": ["${1:dict}.has_key(${2:value})"],
272 | "description": ""
273 | },
274 | "dict.items()": {
275 | "prefix": "dict.items()",
276 | "body": ["${1:dict}.items()"],
277 | "description": ""
278 | },
279 | "dict.setdefault()": {
280 | "prefix": "dict.setdefault()",
281 | "body": ["${1:dict}.setdefault($2,$0)"],
282 | "description": ""
283 | },
284 | "dict.update()": {
285 | "prefix": "dict.update()",
286 | "body": ["${1:dict}.update(${2:dict2})"],
287 | "description": ""
288 | },
289 | "dict.values()": {
290 | "prefix": "dict.values()",
291 | "body": ["${1:dict}.values()"],
292 | "description": ""
293 | },
294 | "dict.pop()": {
295 | "prefix": "dict.pop()",
296 | "body": ["${1:dict}.pop(${2:value})"],
297 | "description": ""
298 | },
299 | "dict.popitem()": {
300 | "prefix": "dict.popitem()",
301 | "body": ["${1:dict}.popitem()"],
302 | "description": ""
303 | },
304 | "enumerate": {
305 | "prefix": "for in enumerate",
306 | "body": ["for idx, val in enumerate(${1:data}, 1):", "\t${0:print(idx,val)}"],
307 | "description": ""
308 | },
309 | "map": {
310 | "prefix": "map()",
311 | "body": ["map(${1:function}, ${2:iterable})"],
312 | "description": ""
313 | },
314 | "for in": {
315 | "prefix": "for",
316 | "body": ["for ${1:target_list} in ${2:expression_list}:", "\t${0:pass}"],
317 | "description": "for语句"
318 | },
319 | "for else": {
320 | "prefix": "for else",
321 | "body": ["for ${1:target_list} in ${2:expression_list}:", "\t${3:pass}", "else:", "\t${0:pass}"],
322 | "description": "for else语句"
323 | },
324 | "yield": {
325 | "prefix": "yield",
326 | "body": ["yield"],
327 | "description": ""
328 | },
329 | "while": {
330 | "prefix": "while",
331 | "body": ["while ${1:condition}:", "\t${0:pass}"],
332 | "description": "while循环"
333 | },
334 | "break": {
335 | "prefix": "break",
336 | "body": ["break"],
337 | "description": "break 语句,和 C 中的类似,用于跳出最近的 for 或 while 循环."
338 | },
339 | "continue": {
340 | "prefix": "continue",
341 | "body": ["continue"],
342 | "description": "表示继续循环中的下一次迭代"
343 | },
344 | "if": {
345 | "prefix": "if",
346 | "body": ["if ${1:expression}:", "\t${2:pass}"],
347 | "description": "if条件判断"
348 | },
349 | "if/else": {
350 | "prefix": "ife",
351 | "body": ["if ${1:condition}", "\t${2:pass}", "else:", "\t${0:pass}"],
352 | "description": "if else语句"
353 | },
354 | "if/elif/else": {
355 | "prefix": "ifee",
356 | "body": ["if ${1:condition}", "\t${2:pass}", "elif ${3:condition}:", "\t${4:pass}", "else:", "\t${0:pass}"],
357 | "description": "if elif else语句"
358 | },
359 | "if in": {
360 | "prefix": "ifi",
361 | "body": ["if ${1:String} in ${2:String}:", "\t${2:pass}"],
362 | "description": "if in语句"
363 | },
364 | "if not": {
365 | "prefix": "ifn",
366 | "body": ["if not ${1:String}:", "\t${0:pass}"],
367 | "description": "if not "
368 | },
369 | "if not in": {
370 | "prefix": "ifni",
371 | "body": ["if ${1:String} not in ${2:String}:", "\t${2:pass}"],
372 | "description": "if not in"
373 | },
374 | "def function": {
375 | "prefix": "def",
376 | "body": ["def ${1:funcname}($2):", "\t\"\"\"${2: Documentation Strings}\"\"\"", "\t${0:pass}"],
377 | "description": "def函数"
378 | },
379 | "def function class": {
380 | "prefix": "def (class method)",
381 | "body": ["def ${1:funcname}(self):", "\t\"\"\"${2: Documentation Strings}\"\"\"", "\t${0:pass}"],
382 | "description": "def函数,用于class内使用"
383 | },
384 | "def args kwargs": {
385 | "prefix": "def function(*args, **kwargs)",
386 | "body": ["def ${1:funcname}(*args, **kwargs):", "\t\"\"\"${2: Documentation Strings}\"\"\"", "\t${0:pass}"],
387 | "description": ""
388 | },
389 | "__init__()": {
390 | "prefix": "__init__()",
391 | "body": ["def __init__(self,$1):", "\t${0:pass}"],
392 | "description": ""
393 | },
394 | "__set__()": {
395 | "prefix": "__set__()",
396 | "body": ["def __set__(self,$1):", "\t${0:pass}"],
397 | "description": ""
398 | },
399 | "__delete__()": {
400 | "prefix": "__delete__()",
401 | "body": ["def __delete__(self,$1):", "\t${0:pass}"],
402 | "description": ""
403 | },
404 | "__new__()": {
405 | "prefix": "__new__()",
406 | "body": ["def __new__(self,$1):", "\t${0:pass}"],
407 | "description": ""
408 | },
409 | "__call__()": {
410 | "prefix": "__call__()",
411 | "body": ["def __call__(self,$1):", "\t${0:pass}"],
412 | "description": ""
413 | },
414 | "__get__()": {
415 | "prefix": "__get__()",
416 | "body": ["def __get__(self,$1):", "\t${0:pass}"],
417 | "description": ""
418 | },
419 | "def decorator": {
420 | "prefix": "def decorator",
421 | "body": ["def ${1:funcname}(${2:argv}):", "\tdef ${3:funcname}():", "\t\t${4:pass}", "\treturn ${0:funcname}"],
422 | "description": "装饰器"
423 | },
424 | "lambda": {
425 | "prefix": "lambda",
426 | "body": ["lambda ${1:parameter_list}: ${2:expression}"],
427 | "description": "用于创建匿名函数"
428 | },
429 | "class": {
430 | "prefix": "cls",
431 | "body": ["class ${1:classname}:", "\t\"\"\"${2: Documentation Strings}\"\"\"", "\t", "\tdef __init__(self):",
432 | "\t\t${3:pass}", "\t", "\tdef ${4:funcname}(self):", "\t\t${0:pass}"
433 | ],
434 | "description": ""
435 | },
436 | "try/except": {
437 | "prefix": "te",
438 | "body": ["try:", "\t${1:pass}", "except Exception as e:", "\t${2:pass}"],
439 | "description": ""
440 | },
441 | "try/except/else": {
442 | "prefix": "tee",
443 | "body": ["try:", "\t${1:pass}", "except Exception as e:", "\t${2:pass}", "else:", "\t${0:pass}"],
444 | "description": ""
445 | },
446 | "try/except/else/finally": {
447 | "prefix": "teef",
448 | "body": ["try:", "\t${1:pass}", "except Exception as e:", "\t${2:pass}", "else:", "\t${3:pass}", "finally:",
449 | "\t${0:pass}"
450 | ],
451 | "description": ""
452 | },
453 | "try/finally": {
454 | "prefix": "tf",
455 | "body": ["try:", "\t${1:pass}", "finally:", "\t${2:pass}"],
456 | "description": ""
457 | },
458 | "try/except/finally": {
459 | "prefix": "tef",
460 | "body": ["try:", "\t${1:pass}", "except Exception as e:", "\t${2:pass}", "finally:", "\t${0:pass}"],
461 | "description": ""
462 | },
463 | "file/read": {
464 | "prefix": "fd",
465 | "body": ["with open(${1:filename},\"r\",encoding=\"utf-8\") as f:", "\t${0:data}=f.read()"],
466 | "description": "使用with方式读取文件"
467 | },
468 | "file/write": {
469 | "prefix": "fw",
470 | "body": ["with open(${1:filename},\"w\") as f:", "\tf.write(${0})"],
471 | "description": "使用with方式写入文件"
472 | },
473 | "json": {
474 | "prefix": "json",
475 | "body": ["json"],
476 | "description": "json库"
477 | },
478 | "json/dumps": {
479 | "prefix": "json/dumps",
480 | "body": ["json.dumps(${1:data},indent=${2:4},encoding=\"${3:utf-8}\")"],
481 | "description": "将 obj 序列化为 JSON 格式的 str"
482 | },
483 | "json/loads": {
484 | "prefix": "json/loads",
485 | "body": ["json.loads($0)"],
486 | "description": "将 (一个包含 JSON 文档的 str, bytes 或 bytearray 实例) 反序列化为 Python 对象"
487 | },
488 | "os": {
489 | "prefix": "os",
490 | "body": ["os"],
491 | "description": ""
492 | },
493 | "os.listdir": {
494 | "prefix": "os.listdir",
495 | "body": ["os.listdir(${1:dirname})"],
496 | "description": "用于返回指定的文件夹包含的文件或文件夹的名字的列表"
497 | },
498 | "os.walk": {
499 | "prefix": "os.walk",
500 | "body": ["os.walk(${1:dirname})"],
501 | "description": "生成目录树中的文件名,方式是按上->下或下->上顺序浏览目录树。对于以 top 为根的目录树中的每个目录(包括 top 本身),它都会生成一个三元组 (dirpath, dirnames, filenames)"
502 | },
503 | "os.getcwd": {
504 | "prefix": "os.getcwd",
505 | "body": ["os.getcwd()"],
506 | "description": ""
507 | },
508 | "os.chdir": {
509 | "prefix": "os.chdir",
510 | "body": ["os.chdir(${1:dirname})"],
511 | "description": "切换工作目录"
512 | },
513 | "os.mkdir": {
514 | "prefix": "os.mkdir",
515 | "body": ["os.mkdir(${1:dirname})"],
516 | "description": "创建目录;如果目录已存在,则抛出 FileExistsError 异常"
517 | },
518 | "os.makedirs": {
519 | "prefix": "os.makedirs",
520 | "body": ["os.makedirs(${1:dirname})"],
521 | "description": "递归目录创建函数"
522 | },
523 | "os.removedirs": {
524 | "prefix": "os.removedirs",
525 | "body": ["os.removedirs(${1:dirname})"],
526 | "description": "递归删除目录"
527 | },
528 | "os.rmdir": {
529 | "prefix": "os.rmdir",
530 | "body": ["os.rmdir(${1:dirname})"],
531 | "description": "移除(删除)目录 path。如果目录不存在或不为空,则会分别抛出 FileNotFoundError 或 OSError 异常。"
532 | },
533 | "os.remove": {
534 | "prefix": "os.remove",
535 | "body": ["os.remove(${1:filename})"],
536 | "description": "移除(删除)文件 path"
537 | },
538 | "os.stat": {
539 | "prefix": "os.stat",
540 | "body": ["os.stat(${1:file})"],
541 | "description": "获取文件/目录信息"
542 | },
543 | "os.path.getsize": {
544 | "prefix": "os.path.getsize",
545 | "body": ["os.path.getsize(${1:path})"],
546 | "description": "获取文件大小"
547 | },
548 | "os.path.islink": {
549 | "prefix": "os.path.islink",
550 | "body": ["os.path.islink(${1:path})"],
551 | "description": "判断路径是否为链接"
552 | },
553 | "os.path.ismount": {
554 | "prefix": "os.path.ismount",
555 | "body": ["os.path.ismount(${1:path})"],
556 | "description": "判断路径是否为挂载点"
557 | },
558 | "os.path.splitext": {
559 | "prefix": "os.path.splitext",
560 | "body": ["os.path.splitext(${1:path})"],
561 | "description": "分割路径,返回路径名和文件扩展名的元组"
562 | },
563 | "os.path.split": {
564 | "prefix": "os.path.split",
565 | "body": ["os.path.split(${1:path})"],
566 | "description": ""
567 | },
568 | "os.path.abspath": {
569 | "prefix": "os.path.abspath",
570 | "body": ["os.path.abspath(${1:path})"],
571 | "description": "返回路径 path 的绝对路径"
572 | },
573 | "os.path.dirname": {
574 | "prefix": "os.path.dirname",
575 | "body": ["os.path.dirname(${1:path})"],
576 | "description": "返回路径 path 的目录名称"
577 | },
578 | "os.path.basename": {
579 | "prefix": "os.path.basename",
580 | "body": ["os.path.basename(${1:path})"],
581 | "description": "返回路径 path 的基本名称"
582 | },
583 | "os.path.exists": {
584 | "prefix": "os.path.exists",
585 | "body": ["os.path.exists(${1:path})"],
586 | "description": "判断目录是否存在"
587 | },
588 | "os.path.isabs": {
589 | "prefix": "os.path.isabs",
590 | "body": ["os.path.isabs(${1:path})"],
591 | "description": "如果 path 是一个绝对路径,则返回 True"
592 | },
593 | "os.path.isfile": {
594 | "prefix": "os.path.isfile",
595 | "body": ["os.path.isfile(${1:path})"],
596 | "description": "判断路径是否是一个文件"
597 | },
598 | "os.path.isdir": {
599 | "prefix": "os.path.isdir",
600 | "body": ["os.path.isdir(${1:path})"],
601 | "description": "判断路径是否是一个目录"
602 | },
603 | "os.path.join": {
604 | "prefix": "os.path.join",
605 | "body": ["os.path.join(${1:path1},${2:path2})"],
606 | "description": "路径拼接"
607 | },
608 | "os.path.getctime": {
609 | "prefix": "os.path.getctime",
610 | "body": ["os.path.getctime(${1:path})"],
611 | "description": "获取文件创建时间"
612 | },
613 | "os.path.getatime": {
614 | "prefix": "os.path.getatime",
615 | "body": ["os.path.getatime(${1:path})"],
616 | "description": "文件或者目录的最后存取时间"
617 | },
618 | "os.path.getmtime": {
619 | "prefix": "os.path.getmtime",
620 | "body": ["os.path.getmtime(${1:path})"],
621 | "description": "文件或者目录的最后修改时间"
622 | },
623 | "os.ctermid": {
624 | "prefix": "os.ctermid",
625 | "body": ["os.ctermid(${1:pid})"],
626 | "description": "返回与进程控制终端对应的文件名"
627 | },
628 | "os.environ": {
629 | "prefix": "os.environ",
630 | "body": ["os.environ"],
631 | "description": ""
632 | },
633 | "os.getenv": {
634 | "prefix": "os.getenv",
635 | "body": ["os.getenv(${1:key})"],
636 | "description": "如果存在,返回环境变量 key 的值,否则返回 default"
637 | },
638 | "os.lstat": {
639 | "prefix": "os.lstat",
640 | "body": ["os.lstat(${1:path})"],
641 | "description": ""
642 | },
643 | "os.system": {
644 | "prefix": "os.system",
645 | "body": ["os.system(${1:cmd})"],
646 | "description": ""
647 | },
648 | "os.popen": {
649 | "prefix": "os.popen",
650 | "body": ["os.popen(${1:cmd})"],
651 | "description": ""
652 | },
653 | "os.sep": {
654 | "prefix": "os.sep",
655 | "body": ["os.sep($1)"],
656 | "description": "返回路径分隔符"
657 | },
658 | "os.getlogin": {
659 | "prefix": "os.getlogin",
660 | "body": ["os.getlogin()"],
661 | "description": "返回当前系统的登录用户名,适用于unix"
662 | },
663 | "os.kill": {
664 | "prefix": "os.kill",
665 | "body": ["os.kill($1)"],
666 | "description": "结束进程"
667 | },
668 | "sys": {
669 | "prefix": "sys",
670 | "body": ["sys"],
671 | "description": ""
672 | },
673 | "sys.path": {
674 | "prefix": "sys.path",
675 | "body": ["sys.path"],
676 | "description": ""
677 | },
678 | "sys.stderr": {
679 | "prefix": "sys.stderr",
680 | "body": ["sys.stderr"],
681 | "description": ""
682 | },
683 | "sys.stdout": {
684 | "prefix": "sys.stdout",
685 | "body": ["sys.stdout"],
686 | "description": ""
687 | },
688 | "sys.stdin": {
689 | "prefix": "sys.stdin",
690 | "body": ["sys.stdin"],
691 | "description": ""
692 | },
693 | "sys.argv": {
694 | "prefix": "sys.argv",
695 | "body": ["sys.argv"],
696 | "description": "获取运行 Python 程序的命令行参数"
697 | },
698 | "sys.exit()": {
699 | "prefix": "sys.exit()",
700 | "body": ["sys.exit()"],
701 | "description": "通过引发 SystemExit 异常来退出程序,默认为0"
702 | },
703 | "sys.platform": {
704 | "prefix": "sys.platform",
705 | "body": ["sys.platform"],
706 | "description": "当前正在运行的平台名称"
707 | },
708 | "sys.version": {
709 | "prefix": "sys.version",
710 | "body": ["sys.version"],
711 | "description": "返回当前 Python 解释器的版本信息"
712 | },
713 | "re": {
714 | "prefix": "re",
715 | "body": ["re"],
716 | "description": "正则表达式操作"
717 | },
718 | "re.compile": {
719 | "prefix": "re.compile",
720 | "body": ["re.compile(${1:str})"],
721 | "description": "该函数用于将正则表达式字符串编译成 _sre.SRE_Pattern 对象"
722 | },
723 | "re.search": {
724 | "prefix": "re.search",
725 | "body": ["re.search(${1:str1},${2:str2})"],
726 | "description": "扫描整个字符串,并返回字符串中第一处匹配 pattern 的匹配对象"
727 | },
728 | "re.findall": {
729 | "prefix": "re.findall",
730 | "body": ["re.findall(${1:pattern},${2:string},flags=0)"],
731 | "description": "扫描整个字符串,并返回字符串中所有匹配 pattern 的子串组成的列表。其中 pattern 参数代表正则表达式;string 代表被匹配的宇符串;flags 则代表正则表达式的匹配旗标。"
732 | },
733 | "re.finditer": {
734 | "prefix": "re.finditer",
735 | "body": ["re.finditer(${1:pattern},${2:string},flags=0)"],
736 | "description": ""
737 | },
738 | "re.fullmatch": {
739 | "prefix": "re.fullmatch",
740 | "body": ["re.fullmatch(${1:pattern},${2:string},flags=0)"],
741 | "description": ""
742 | },
743 | "re.sub": {
744 | "prefix": "re.sub",
745 | "body": ["re.sub($1)"],
746 | "description": ""
747 | },
748 | "re.split": {
749 | "prefix": "re.split",
750 | "body": ["re.split($1,$2)"],
751 | "description": "用 pattern 分开 string。 re.split(pattern, string, maxsplit=0, flags=0)"
752 | },
753 | "time": {
754 | "prefix": "time",
755 | "body": ["time"],
756 | "description": "该模块提供了各种时间相关的函数"
757 | },
758 | "datetime": {
759 | "prefix": "datetime",
760 | "body": ["datetime"],
761 | "description": "datetime 模块提供用于处理日期和时间的类"
762 | },
763 | "time Y-m-d": {
764 | "prefix": "time Y-m-d",
765 | "body": ["time.strftime(\"%Y-%m-%d\", time.localtime())"],
766 | "description": "返回 %Y-%m-%d 格式"
767 | },
768 | "time H:M:S": {
769 | "prefix": "time H:M:S",
770 | "body": ["time.strftime(\"%H:%M:%S\", time.localtime())"],
771 | "description": "返回 %H:%M:%S 格式"
772 | },
773 | "time Y-m-d H:M:S": {
774 | "prefix": "time Y-m-d H:M:S",
775 | "body": ["time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime())"],
776 | "description": "返回%Y-%m-%d %H:%M:%S格式"
777 | },
778 | "time.time": {
779 | "prefix": "time.time()",
780 | "body": ["time.time()"],
781 | "description": ""
782 | },
783 | "time.localtime": {
784 | "prefix": "time.localtime",
785 | "body": ["time.localtime($1)"],
786 | "description": ""
787 | },
788 | "time.clock": {
789 | "prefix": "time.clock",
790 | "body": ["time.clock($1)"],
791 | "description": ""
792 | },
793 | "time.mktime": {
794 | "prefix": "time.mktime",
795 | "body": ["time.mktime($1)"],
796 | "description": ""
797 | },
798 | "time.sleep": {
799 | "prefix": "time.sleep",
800 | "body": ["time.sleep($1)"],
801 | "description": "暂停执行调用线程达到给定的秒数。参数可以是浮点数,以指示更精确的睡眠时间。"
802 | },
803 | "timedelta": {
804 | "prefix": "timedelta",
805 | "body": ["timedelta($1)"],
806 | "description": ""
807 | },
808 | "datetime strptime": {
809 | "prefix": "datetime.strptime",
810 | "body": ["datetime.strptime(${1:text}, '%Y-%m-%d %H:%M:%S')"],
811 | "description": "字符串转换为日期"
812 | },
813 | "strptime Y-m-d": {
814 | "prefix": "strptime Y-m-d",
815 | "body": ["datetime.strptime(${1:text}, '%Y-%m-%d')"],
816 | "description": "字符串转换为日期"
817 | },
818 | "strptime H-M-S": {
819 | "prefix": "strptime H-M-S",
820 | "body": ["datetime.strptime(${1:text}, '%H:%M:%S')"],
821 | "description": "字符串转换为日期"
822 | },
823 | "calendar": {
824 | "prefix": "calendar",
825 | "body": ["calendar"],
826 | "description": "日历库"
827 | },
828 | "calendar.isleap": {
829 | "prefix": "calendar.isleap",
830 | "body": ["calendar.isleap(${1:year})"],
831 | "description": "判断是否闰年,闰年返回true"
832 | },
833 | "calendar.month": {
834 | "prefix": "calendar.month",
835 | "body": ["calendar.month($1)"],
836 | "description": ""
837 | },
838 | "requests": {
839 | "prefix": "requests",
840 | "body": ["requests"],
841 | "description": "requests 网络请求库"
842 | },
843 | "requests.get": {
844 | "prefix": "requests.get",
845 | "body": ["requests.get(${1:url})"],
846 | "description": "Request Get请求"
847 | },
848 | "requests.post": {
849 | "prefix": "requests.post",
850 | "body": ["requests.post(${1:url},data=${2:data})"],
851 | "description": "Request post请求"
852 | },
853 | "glob": {
854 | "prefix": "glob",
855 | "body": ["glob"],
856 | "description": "global 语句是作用于整个当前代码块的声明"
857 | },
858 | "except Exception": {
859 | "prefix": "Exception",
860 | "body": ["Exception"],
861 | "description": "异常 Exception"
862 | },
863 | "__main__": {
864 | "prefix": "__main__",
865 | "body": ["if __name__ == \"__main__\":", "\t${1:pass}"],
866 | "description": ""
867 | }
868 | }
869 |
--------------------------------------------------------------------------------
/static/exmaple.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dcloudio/hbuilderx-extension-samples/b7ba7189bcfa7e1256227b22c38fb96ae55dce25/static/exmaple.jpg
--------------------------------------------------------------------------------
/static/fileiconfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dcloudio/hbuilderx-extension-samples/b7ba7189bcfa7e1256227b22c38fb96ae55dce25/static/fileiconfont.ttf
--------------------------------------------------------------------------------
/static/message.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | const hx = require('hbuilderx');
2 |
3 | const allCommands = [
4 | "api.commands",
5 | "api.status_bar_info_message",
6 | "api.status_bar_warn_message",
7 | "api.status_bar_error_message",
8 | "api.status_bar_timeout_message",
9 | "api.clear_status_bar_message",
10 | "api.show_error_message",
11 | "api.show_info_message",
12 | "api.show_warning_message",
13 | "api.window_show_quick_pick",
14 | "api.window_show_input_box",
15 | "api.get_active_text_editor",
16 | "api.get_active_text_editor_for_nature",
17 | "api.get_active_text_editor_for_project_name",
18 | "api.window_create_output_channel",
19 | "api.open_text_document",
20 | "api.on_will_save_text_document",
21 | "api.on_did_change_text_document",
22 | "api.on_did_open_text_document",
23 | "api.workspace_apply_edit",
24 | "api.workspace_get_configuration",
25 | "api.workspace_update_configuration",
26 | "api.workspace_add_configuration",
27 | "api.get_workspace_folders",
28 | "api.get_workspace_folder",
29 | "api.on_did_chanage_configuration",
30 | "api.on_did_change_forkspace_folders",
31 | "api.text_editor",
32 | "api.text_editor_linetext",
33 | "api.text_editor_line_to_upper_case",
34 | "api.text_editor_indent",
35 | "api.text_lineFromPosition",
36 | "api.text_lineAt",
37 | "api.text_getText",
38 | "api.set_selection",
39 | "api.uri",
40 | "api.languages_create_diagnostics_collection",
41 | "open_help",
42 | "api.openExternal_url",
43 | "api.openExternal_mail",
44 | "api.clipboard_write",
45 | "api.clipboard_read"
46 | ]
47 |
48 | async function runtest() {
49 | for (let s of allCommands) {
50 | let result = await hx.commands.executeCommand(s);
51 | console.log("...",s,result);
52 | }
53 | };
54 |
55 | module.exports = {
56 | runtest
57 | }
--------------------------------------------------------------------------------