vscode自定义插件核心代码

package.json

{
  "name": "gitlab2td",
  "displayName": "gitlab2td",
  "description": "",
  "version": "0.0.1",
  "engines": {
    "vscode": "^1.54.0"
  },
  "categories": [
    "Other"
  ],
  "activationEvents": [],
  "main": "./out/extension.js",
  "contributes": {
    "viewsContainers": {
      "activitybar": [{
        "id": "gitlab2td-custom-view-container",
        "title": "gitlab2td",
        "icon": "$(github-inverted)",
        "activationEvents": [
          "onView:gitlab2td-custom-view-container"
        ]
      }]
    },
    "views": {
      "gitlab2td-custom-view-container": [{
        "id": "gitlab2td-custom-view-container",
        "type": "webview",
        "name": "gitlab2td"
      }]
    }
  },
  "scripts": {
    "vscode:prepublish": "yarn run compile",
    "compile": "tsc -p ./",
    "watch": "tsc -watch -p ./",
    "pretest": "yarn run compile && yarn run lint",
    "lint": "eslint src --ext ts",
    "test": "node ./out/test/runTest.js"
  },
  "devDependencies": {
    "@types/vscode": "^1.54.0",
    "@types/mocha": "^10.0.3",
    "@types/node": "18.x",
    "@typescript-eslint/eslint-plugin": "^6.9.0",
    "@typescript-eslint/parser": "^6.9.0",
    "eslint": "^8.52.0",
    "glob": "^10.3.10",
    "mocha": "^10.2.0",
    "typescript": "^5.2.2",
    "@vscode/test-electron": "^2.3.6"
  }
}

extension.ts

import * as vscode from 'vscode';
import { gitlab2tdCustomView } from './treeViewProvider';

export function activate(context: vscode.ExtensionContext) {
	const sidebarPanel = new gitlab2tdCustomView(context.extensionUri);

	context.subscriptions.push(
		vscode.window.registerWebviewViewProvider("gitlab2td-custom-view-container", sidebarPanel),
	);

}

export function deactivate() { }

treeViewProvider.ts

import * as vscode from "vscode";

export class gitlab2tdCustomView implements vscode.WebviewViewProvider {
    constructor(private readonly _extensionUri: vscode.Uri) { }

    resolveWebviewView(
        webviewView: vscode.WebviewView,
    ): void | Thenable<void> {

        webviewView.webview.options = {
            enableScripts: true,
            localResourceRoots: [this._extensionUri],
        };

        webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
    }

    private _getHtmlForWebview(webview: vscode.Webview) {
        return `<!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>Your Webview</title>
            </head>
            <body>
                <h1>Hello abu</h1>
                <input type="text" id="input">
            </body>
            </html>`;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值