diff --git a/media/IC Coder主页标志.png b/media/IC Coder主页标志.png new file mode 100644 index 0000000..9293c28 Binary files /dev/null and b/media/IC Coder主页标志.png differ diff --git a/media/图案(方底).png b/media/图案(方底).png new file mode 100644 index 0000000..f607935 Binary files /dev/null and b/media/图案(方底).png differ diff --git a/package.json b/package.json index 4c0fa8d..b753bf7 100644 --- a/package.json +++ b/package.json @@ -1,23 +1,62 @@ { - "name": "ic-coder", + "name": "ic-coder-plugin", "displayName": "IC Coder plugin", "description": "Agentic Verilog Coding Platform for Real-World FPGAs", - "version": "0.0.1", + "version": "0.0.2", "engines": { - "vscode": "^1.107.0" + "vscode": "^1.106.3" }, + "icon": "media/IC Coder主页标志.png", "categories": [ "Other" ], - "activationEvents": [], + "keywords": [ + "IC", + "coder", + "verilog", + "FPGA", + "eda", + "assistant" + ], + "activationEvents": [ + "onCommand:ic-coder.openPanel", + "onView:ic-coder-sidebar", + "onLanguage:verilog", + "onLanguage:vhdl", + "onStartupFinished" + ], "main": "./dist/extension.js", "contributes": { "commands": [ { - "command": "ic-coder.helloWorld", - "title": "Hello World" + "command": "ic-coder.openPanel", + "title": "打开 IC Coder 助手", + "category": "IC Coder" + }, + { + "command": "ic-coder.openChat", + "title": "IC Coder: 打开聊天", + "category": "IC Coder" } - ] + ], + "viewsContainers": { + "activitybar": [ + { + "id": "ic-coder-sidebar", + "title": "IC Coder", + "icon": "media/图案(方底).png" + } + ] + }, + "views": { + "ic-coder-sidebar": [ + { + "id": "ic-coder.mainView", + "name": "IC 助手", + "type": "webview" + } + ] + } }, "scripts": { "vscode:prepublish": "pnpm run package", @@ -28,7 +67,8 @@ "watch-tests": "tsc -p . -w --outDir out", "pretest": "pnpm run compile-tests && pnpm run compile && pnpm run lint", "lint": "eslint src", - "test": "vscode-test" + "test": "vscode-test", + "build": "pnpm run compile" }, "devDependencies": { "@types/vscode": "^1.107.0", diff --git a/src/extension.ts b/src/extension.ts index 24968e9..a269c57 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,26 +1,39 @@ -// 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'; +import * as vscode from "vscode"; +import { ICViewProvider } from "./views/ICViewProvider"; +import { showICHelperPanel } from "./panels/ICHelperPanel"; -// 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) { + console.log("🎉 IC Coder 插件已激活!"); - // 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 "ic-coder" is now active!'); + // 注册命令:打开助手面板 + const openPanelCommand = vscode.commands.registerCommand( + "ic-coder.openPanel", + () => { + showICHelperPanel(context); + } + ); - // 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('ic-coder.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 IC Coder plugin!'); - }); + // 注册命令:打开聊天(用于侧边栏) + const openChatCommand = vscode.commands.registerCommand( + "ic-coder.openChat", + () => { + showICHelperPanel(context); + } + ); - context.subscriptions.push(disposable); + // 注册侧边栏视图 + const viewProvider = new ICViewProvider(); + const viewRegistration = vscode.window.registerWebviewViewProvider( + "ic-coder.mainView", + viewProvider + ); + + // 添加到订阅 + context.subscriptions.push( + openPanelCommand, + openChatCommand, + viewRegistration + ); } -// This method is called when your extension is deactivated export function deactivate() {} diff --git a/src/panels/ICHelperPanel.ts b/src/panels/ICHelperPanel.ts new file mode 100644 index 0000000..d0224e0 --- /dev/null +++ b/src/panels/ICHelperPanel.ts @@ -0,0 +1,41 @@ +import * as vscode from "vscode"; +import { getWebviewContent } from "../utils/webviewContent"; +import { handleUserMessage, insertCodeToEditor } from "../utils/messageHandler"; + +/** + * 创建并显示 IC 助手面板 + */ +export function showICHelperPanel(context: vscode.ExtensionContext) { + // 创建WebView面板 + const panel = vscode.window.createWebviewPanel( + "icCoder", // 面板ID + "IC Coder", // 面板标题 + vscode.ViewColumn.Beside, // 显示在旁边 + { + enableScripts: true, + retainContextWhenHidden: true, + } + ); + + // 设置HTML内容 + panel.webview.html = getWebviewContent(); + + // 处理消息 + panel.webview.onDidReceiveMessage( + (message) => { + switch (message.command) { + case "sendMessage": + handleUserMessage(panel, message.text); + break; + case "insertCode": + insertCodeToEditor(message.code); + break; + case "showInfo": + vscode.window.showInformationMessage(message.text); + break; + } + }, + undefined, + context.subscriptions + ); +} diff --git a/src/utils/messageHandler.ts b/src/utils/messageHandler.ts new file mode 100644 index 0000000..19389f2 --- /dev/null +++ b/src/utils/messageHandler.ts @@ -0,0 +1,67 @@ +import * as vscode from "vscode"; + +/** + * 处理用户消息 + */ +export function handleUserMessage(panel: vscode.WebviewPanel, text: string) { + // 模拟AI回复 + const reply = getMockReply(text); + + // 延迟回复,模拟AI思考 + setTimeout(() => { + panel.webview.postMessage({ + command: "receiveMessage", + text: reply, + }); + }, 500); +} + +/** + * 获取模拟回复 + */ +function getMockReply(question: string): string { + const replies = [ + `已收到您的问题:"${question}" + +这是一个演示版本,实际需要连接AI服务。 + +示例回复:这是一个计数器模板: +\`\`\`verilog +module counter ( + input clk, + input rst_n, + output reg [3:0] count +); + always @(posedge clk or negedge rst_n) begin + if (!rst_n) count <= 0; + else count <= count + 1; + end +endmodule +\`\`\``, + + `感谢提问!关于"${question}",在真实版本中我会: +1. 分析您的代码上下文 +2. 提供优化建议 +3. 生成完整代码 +4. 解释设计原理 + +当前是演示版,请点击侧边栏按钮快速生成代码。`, + ]; + + return replies[Math.floor(Math.random() * replies.length)]; +} + +/** + * 将代码插入到编辑器 + */ +export function insertCodeToEditor(code: string) { + const editor = vscode.window.activeTextEditor; + if (editor) { + editor.edit((editBuilder) => { + editBuilder.insert(editor.selection.active, code); + }); + vscode.window.showInformationMessage("代码已插入"); + } else { + vscode.window.showWarningMessage("请先打开一个编辑器"); + } +} diff --git a/src/utils/webviewContent.ts b/src/utils/webviewContent.ts new file mode 100644 index 0000000..d893e63 --- /dev/null +++ b/src/utils/webviewContent.ts @@ -0,0 +1,177 @@ +/** + * 获取 WebView 面板的 HTML 内容 + */ +export function getWebviewContent(): string { + return ` + + + + + IC Coder 助手 + + + +
+

IC Coder

+

专注于真实FPGA研发的Verilog智能体编程平台

+
+ +
+
+
+ 👋 你好!我是 IC Coder 助手,可以帮你生成代码、回答问题。 +
+
+ +
+ + + +
+ +
+
+ + +
+
+
+ + + +`; +} diff --git a/src/views/ICViewProvider.ts b/src/views/ICViewProvider.ts new file mode 100644 index 0000000..d8be605 --- /dev/null +++ b/src/views/ICViewProvider.ts @@ -0,0 +1,176 @@ +import * as vscode from "vscode"; + +/** + * 侧边栏视图提供者 + */ +export class ICViewProvider implements vscode.WebviewViewProvider { + resolveWebviewView(webviewView: vscode.WebviewView) { + webviewView.webview.options = { + enableScripts: true, + }; + + webviewView.webview.html = this.getWebviewContent(); + + // 处理侧边栏的消息 + webviewView.webview.onDidReceiveMessage((message) => { + if (message.command === "openChat") { + vscode.commands.executeCommand("ic-coder.openChat"); + } + }); + } + + private getWebviewContent(): string { + return ` + + + + + + + + +
+

快速生成

+ + + +
+ + + + + `; + } +} diff --git a/tsconfig.json b/tsconfig.json index cb35375..36fb68b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,9 @@ { - "compilerOptions": { - "module": "Node16", - "target": "ES2022", - "lib": [ - "ES2022" - ], - "sourceMap": true, - "rootDir": "src", - "strict": true, /* enable all strict type-checking options */ - /* Additional Checks */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - } + "compilerOptions": { + "module": "commonjs", + "target": "ES2020", + "outDir": "./dist", + "rootDir": "./src", + "strict": true + } }