feat:将extension文件拆分成不同功能的独立组件

This commit is contained in:
Roe-xin
2025-12-11 10:54:46 +08:00
parent eec915421a
commit b3c8344d82
9 changed files with 547 additions and 40 deletions

176
src/views/ICViewProvider.ts Normal file
View File

@ -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 `
<!DOCTYPE html>
<html>
<head>
<style>
body {
padding: 10px;
font-family: var(--vscode-font-family);
color: var(--vscode-foreground);
}
.btn {
width: 100%;
padding: 8px 12px;
margin: 4px 0;
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: none;
border-radius: 4px;
cursor: pointer;
text-align: center;
}
.btn:hover {
background: var(--vscode-button-hoverBackground);
}
.section {
margin: 15px 0;
}
h3 {
margin: 0 0 8px 0;
font-size: 12px;
color: var(--vscode-descriptionForeground);
}
</style>
</head>
<body>
<button class="btn" onclick="openChat()">💬 打开聊天助手</button>
<div class="section">
<h3>快速生成</h3>
<button class="btn" onclick="generateCode('counter')">🔢 计数器</button>
<button class="btn" onclick="generateCode('fsm')">🔄 状态机</button>
<button class="btn" onclick="generateCode('fifo')">📦 FIFO</button>
</div>
<script>
const vscode = acquireVsCodeApi();
function openChat() {
vscode.postMessage({ command: 'openChat' });
}
function generateCode(type) {
const code = getCodeTemplate(type);
vscode.postMessage({
command: 'insertCode',
code: code
});
}
function getCodeTemplate(type) {
const templates = {
counter: \`module counter #(
parameter WIDTH = 4
)(
input wire clk,
input wire rst_n,
input wire enable,
output reg [WIDTH-1:0] count
);
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
count <= 0;
end else if (enable) begin
count <= count + 1;
end
end
endmodule\`,
fsm: \`module fsm (
input wire clk,
input wire rst_n,
input wire start,
output reg done
);
parameter IDLE = 2'b00;
parameter STATE1 = 2'b01;
parameter STATE2 = 2'b10;
reg [1:0] state, next_state;
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
state <= IDLE;
end else begin
state <= next_state;
end
end
always @(*) begin
case (state)
IDLE: next_state = start ? STATE1 : IDLE;
STATE1: next_state = STATE2;
STATE2: next_state = IDLE;
default: next_state = IDLE;
endcase
end
assign done = (state == STATE2);
endmodule\`,
fifo: \`module sync_fifo #(
parameter DATA_WIDTH = 8,
parameter DEPTH = 16
)(
input wire clk,
input wire rst_n,
input wire wr_en,
input wire [DATA_WIDTH-1:0] din,
input wire rd_en,
output reg [DATA_WIDTH-1:0] dout,
output wire full,
output wire empty
);
reg [DATA_WIDTH-1:0] mem [0:DEPTH-1];
reg [$clog2(DEPTH):0] wr_ptr, rd_ptr;
assign full = (wr_ptr == rd_ptr + DEPTH);
assign empty = (wr_ptr == rd_ptr);
always @(posedge clk) begin
if (!rst_n) wr_ptr <= 0;
else if (wr_en && !full) begin
mem[wr_ptr] <= din;
wr_ptr <= wr_ptr + 1;
end
end
always @(posedge clk) begin
if (!rst_n) begin
rd_ptr <= 0;
dout <= 0;
end else if (rd_en && !empty) begin
dout <= mem[rd_ptr];
rd_ptr <= rd_ptr + 1;
end
end
endmodule\`
};
return templates[type] || '// 代码模板';
}
</script>
</body>
</html>
`;
}
}