diff --git a/icons/protocol.svg b/icons/protocol.svg new file mode 100644 index 0000000..87e1b72 --- /dev/null +++ b/icons/protocol.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/package.json b/package.json index b93cc6e..bd56223 100644 --- a/package.json +++ b/package.json @@ -1,47 +1,58 @@ { - "name": "openmcp", - "displayName": "openmcp", - "description": "A MCP Client for MCP/OpenMCP", - "version": "0.0.1", - "engines": { - "vscode": "^1.98.0" - }, - "categories": [ - "Other" - ], - "activationEvents": [], - "main": "./dist/extension.js", - "contributes": { - "commands": [ - { - "command": "openmcp.helloWorld", - "title": "Hello World" - } - ] - }, - "scripts": { - "vscode:prepublish": "npm run package", - "compile": "webpack", - "watch": "webpack --watch", - "package": "webpack --mode production --devtool hidden-source-map", - "compile-tests": "tsc -p . --outDir out", - "watch-tests": "tsc -p . -w --outDir out", - "pretest": "npm run compile-tests && npm run compile && npm run lint", - "lint": "eslint src", - "test": "vscode-test" - }, - "devDependencies": { - "@types/vscode": "^1.98.0", - "@types/mocha": "^10.0.10", - "@types/node": "20.x", - "@typescript-eslint/eslint-plugin": "^8.25.0", - "@typescript-eslint/parser": "^8.25.0", - "eslint": "^9.21.0", - "typescript": "^5.7.3", - "ts-loader": "^9.5.2", - "webpack": "^5.98.0", - "webpack-cli": "^6.0.1", - "@vscode/test-cli": "^0.0.10", - "@vscode/test-electron": "^2.4.1" - } -} + "name": "openmcp", + "displayName": "openmcp", + "description": "A MCP Client for MCP/OpenMCP", + "version": "0.0.1", + "engines": { + "vscode": "^1.98.0" + }, + "categories": [ + "Other" + ], + "activationEvents": [ + "*" + ], + "main": "./dist/extension.js", + "contributes": { + "commands": [ + { + "command": "openmcp.helloWorld", + "title": "Hello World" + } + ], + "views": { + "explorer": [ + { + "id": "webview-sidebar.view", + "icon": "./icons/protocol.svg", + "name": "WebView" + } + ] + } + }, + "scripts": { + "vscode:prepublish": "npm run package", + "compile": "webpack", + "watch": "webpack --watch", + "package": "webpack --mode production --devtool hidden-source-map", + "compile-tests": "tsc -p . --outDir out", + "watch-tests": "tsc -p . -w --outDir out", + "pretest": "npm run compile-tests && npm run compile && npm run lint", + "lint": "eslint src", + "test": "vscode-test" + }, + "devDependencies": { + "@types/vscode": "^1.98.0", + "@types/mocha": "^10.0.10", + "@types/node": "20.x", + "@typescript-eslint/eslint-plugin": "^8.25.0", + "@typescript-eslint/parser": "^8.25.0", + "eslint": "^9.21.0", + "typescript": "^5.7.3", + "ts-loader": "^9.5.2", + "webpack": "^5.98.0", + "webpack-cli": "^6.0.1", + "@vscode/test-cli": "^0.0.10", + "@vscode/test-electron": "^2.4.1" + } +} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 080b70f..4628923 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,26 +1,50 @@ -// The module 'vscode' contains the VS Code extensibility API -// Import the module and reference it with the alias vscode in your code below import * as vscode from 'vscode'; -// This method is called when your extension is activated -// Your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { + // 注册 WebView 视图 + console.log('activate'); + + const provider = new WebviewViewProvider(context.extensionUri); - // Use the console to output diagnostic information (console.log) and errors (console.error) - // This line of code will only be executed once when your extension is activated - console.log('Congratulations, your extension "openmcp" is now active!'); + context.subscriptions.push( + vscode.commands.registerCommand('openmcp.helloWorld', () => { + vscode.window.showInformationMessage('Hello World!'); + }) + ) - // The command has been defined in the package.json file - // Now provide the implementation of the command with registerCommand - // The commandId parameter must match the command field in package.json - const disposable = vscode.commands.registerCommand('openmcp.helloWorld', () => { - // The code you place here will be executed every time your command is executed - // Display a message box to the user - vscode.window.showInformationMessage('Hello World from openmcp!'); - }); - - context.subscriptions.push(disposable); + context.subscriptions.push( + vscode.window.registerWebviewViewProvider('webview-sidebar.view', provider) + ); } -// This method is called when your extension is deactivated -export function deactivate() {} +class WebviewViewProvider implements vscode.WebviewViewProvider { + constructor(private readonly _extensionUri: vscode.Uri) {} + + public resolveWebviewView(webviewView: vscode.WebviewView) { + webviewView.webview.options = { + enableScripts: true, // 启用 JavaScript + }; + + // 设置 WebView 的 HTML 内容 + webviewView.webview.html = getWebviewContent(); + } +} + +function getWebviewContent(): string { + return ` + + +
+ + +This is a custom WebView in VS Code Sidebar.
+ + + `; +} + +export function deactivate() {} \ No newline at end of file