Compare commits
34 Commits
feat/front
...
feat/Delet
| Author | SHA1 | Date | |
|---|---|---|---|
| ea19dfcbe6 | |||
| fa55e32153 | |||
| f6b1f5c45a | |||
| 1f9a1822c9 | |||
| 63015c6bbc | |||
| 24b30df992 | |||
| 67b1003831 | |||
| 00d37bdaf0 | |||
| c5fcb1427e | |||
| 9118ebd662 | |||
| 19cdf47bed | |||
| 95bac94479 | |||
| 421a8934a7 | |||
| f7f45668d3 | |||
| c8e9a5b897 | |||
| a1bfa62796 | |||
| 64e11cbc3c | |||
| 15445aa13c | |||
| 52834047f2 | |||
| 76817675f1 | |||
| 2cce8f94c9 | |||
| 9b5f102d9f | |||
| 68de33165e | |||
| f56ad33366 | |||
| 35c63802b5 | |||
| 3458f6fe23 | |||
| 8f305033f7 | |||
| 4a18f1c418 | |||
| 373edb6d80 | |||
| 1c66e0e599 | |||
| 536e7720cb | |||
| 75eac4b1ce | |||
| 9ed0afee6b | |||
| f700473967 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,8 +4,7 @@ node_modules
|
|||||||
.vscode-test/
|
.vscode-test/
|
||||||
*.vsix
|
*.vsix
|
||||||
|
|
||||||
# waveform_trace 打包产物(exe 太大,通过 Release 发布)
|
# waveform_trace 打包产物
|
||||||
tools/waveform_trace/bin/
|
|
||||||
tools/waveform_trace/src/build/
|
tools/waveform_trace/src/build/
|
||||||
tools/waveform_trace/src/dist/
|
tools/waveform_trace/src/dist/
|
||||||
tools/waveform_trace/src/*.spec
|
tools/waveform_trace/src/*.spec
|
||||||
|
|||||||
28
.vscodeignore
Normal file
28
.vscodeignore
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# 开发文件
|
||||||
|
.vscode/**
|
||||||
|
.vscode-test/**
|
||||||
|
src/**
|
||||||
|
.gitignore
|
||||||
|
.yarnrc
|
||||||
|
vsc-extension-quickstart.md
|
||||||
|
**/tsconfig.json
|
||||||
|
**/.eslintrc.json
|
||||||
|
**/*.map
|
||||||
|
**/*.ts
|
||||||
|
|
||||||
|
# 测试文件
|
||||||
|
out/test/**
|
||||||
|
|
||||||
|
# 依赖
|
||||||
|
node_modules/**
|
||||||
|
|
||||||
|
# 文档(避免中文文件名打包问题)
|
||||||
|
docs/**
|
||||||
|
PUBLISH.md
|
||||||
|
|
||||||
|
# 只排除 waveform_trace 的 src/dist 目录
|
||||||
|
tools/waveform_trace/src/dist/**
|
||||||
|
|
||||||
|
# Git 相关
|
||||||
|
.git/**
|
||||||
|
.github/**
|
||||||
45
CHANGELOG.md
45
CHANGELOG.md
@ -2,6 +2,51 @@
|
|||||||
|
|
||||||
所有重要的项目变更都将记录在此文件中。
|
所有重要的项目变更都将记录在此文件中。
|
||||||
|
|
||||||
|
## [1.0.9] - 2026-03-04
|
||||||
|
|
||||||
|
### 优化
|
||||||
|
|
||||||
|
- 将工具折叠图标颜色从蓝色改为灰色
|
||||||
|
- 统一使用蓝色主题色
|
||||||
|
- 优化打包配置,排除重复的 exe 文件
|
||||||
|
|
||||||
|
### 修复
|
||||||
|
|
||||||
|
- 修复代码变更继续对话查找不到之前的代码变更信息的 bug
|
||||||
|
- 修复对话展示两遍的问题
|
||||||
|
|
||||||
|
## [1.0.8] - 2026-03-03
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- 删除文件确认功能
|
||||||
|
- 文件路径标签显示
|
||||||
|
- 企业试用用户欢迎弹窗优化
|
||||||
|
|
||||||
|
### 修复
|
||||||
|
|
||||||
|
- 修复继续对话时消息覆盖问题
|
||||||
|
- 修复试用用户欢迎弹窗显示逻辑
|
||||||
|
- 修复企业试用用户仍弹出邀请码的问题
|
||||||
|
- 修复登录过期点击重新登录失败的问题
|
||||||
|
|
||||||
|
## [1.0.7] - 2026-03-02
|
||||||
|
|
||||||
|
### 修复
|
||||||
|
|
||||||
|
- 修复 AI 响应内容重复显示问题
|
||||||
|
|
||||||
|
## [1.0.6] - 2026-03-02
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- Git Diff 功能:支持查看当前文件的 Git 差异对比
|
||||||
|
|
||||||
|
### 修复
|
||||||
|
|
||||||
|
- 修复添加上下文搜索选择文件不匹配的问题
|
||||||
|
- 修复过期认证状态未清除导致重新登录失败的问题
|
||||||
|
|
||||||
## [1.0.4] - 2026-01-28
|
## [1.0.4] - 2026-01-28
|
||||||
|
|
||||||
IC Coder插件端正式上线。
|
IC Coder插件端正式上线。
|
||||||
|
|||||||
27
PUBLISH.md
27
PUBLISH.md
@ -88,6 +88,7 @@ CO03l8nmFBBTNPDg7lN9a9fYwDdgsRIDVDwTrx6Esggi6HnzmrMTJQQJ99BLACAAAAAAAAAAAAAGAZDO
|
|||||||
5. 点击 **Create** 完成创建
|
5. 点击 **Create** 完成创建
|
||||||
|
|
||||||
**注意事项:**
|
**注意事项:**
|
||||||
|
|
||||||
- Publisher ID 一旦创建无法修改
|
- Publisher ID 一旦创建无法修改
|
||||||
- Publisher ID 必须全局唯一
|
- Publisher ID 必须全局唯一
|
||||||
- 建议使用有意义且专业的 ID
|
- 建议使用有意义且专业的 ID
|
||||||
@ -126,6 +127,7 @@ CO03l8nmFBBTNPDg7lN9a9fYwDdgsRIDVDwTrx6Esggi6HnzmrMTJQQJ99BLACAAAAAAAAAAAAAGAZDO
|
|||||||
## [0.0.2] - 2025-12-29
|
## [0.0.2] - 2025-12-29
|
||||||
|
|
||||||
### 新增
|
### 新增
|
||||||
|
|
||||||
- 添加发送和暂停按钮功能
|
- 添加发送和暂停按钮功能
|
||||||
- 添加一键优化按钮组件
|
- 添加一键优化按钮组件
|
||||||
- 添加 Plan 开关组件
|
- 添加 Plan 开关组件
|
||||||
@ -133,11 +135,13 @@ CO03l8nmFBBTNPDg7lN9a9fYwDdgsRIDVDwTrx6Esggi6HnzmrMTJQQJ99BLACAAAAAAAAAAAAAGAZDO
|
|||||||
- 添加上下文压缩功能
|
- 添加上下文压缩功能
|
||||||
|
|
||||||
### 改进
|
### 改进
|
||||||
|
|
||||||
- 优化用户界面交互体验
|
- 优化用户界面交互体验
|
||||||
|
|
||||||
## [0.0.1] - 2025-12-XX
|
## [0.0.1] - 2025-12-XX
|
||||||
|
|
||||||
### 新增
|
### 新增
|
||||||
|
|
||||||
- 初始版本发布
|
- 初始版本发布
|
||||||
- Verilog 代码智能生成
|
- Verilog 代码智能生成
|
||||||
- 集成 iverilog 仿真工具
|
- 集成 iverilog 仿真工具
|
||||||
@ -161,6 +165,7 @@ in the Software without restriction...
|
|||||||
### 4. 优化 README.md
|
### 4. 优化 README.md
|
||||||
|
|
||||||
确保 README 包含:
|
确保 README 包含:
|
||||||
|
|
||||||
- 清晰的功能介绍
|
- 清晰的功能介绍
|
||||||
- 使用截图或 GIF 演示
|
- 使用截图或 GIF 演示
|
||||||
- 详细的使用说明
|
- 详细的使用说明
|
||||||
@ -219,6 +224,7 @@ pnpm vsce publish
|
|||||||
**步骤:**
|
**步骤:**
|
||||||
|
|
||||||
1. 本地打包插件:
|
1. 本地打包插件:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm run package
|
pnpm run package
|
||||||
pnpm vsce package[pnpm vsce package --no-dependencies]
|
pnpm vsce package[pnpm vsce package --no-dependencies]
|
||||||
@ -257,7 +263,7 @@ pnpm vsce publish major
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 发布指定版本
|
# 发布指定版本
|
||||||
pnpm vsce publish 0.0.3
|
npx vsce publish --packagePath iccoder-1.0.7.vsix
|
||||||
```
|
```
|
||||||
|
|
||||||
### 更新流程建议
|
### 更新流程建议
|
||||||
@ -268,8 +274,6 @@ pnpm vsce publish 0.0.3
|
|||||||
4. 执行发布命令
|
4. 执行发布命令
|
||||||
5. 验证市场上的插件是否正常
|
5. 验证市场上的插件是否正常
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 更新流程
|
## 更新流程
|
||||||
|
|
||||||
1. 修改版本号
|
1. 修改版本号
|
||||||
@ -281,10 +285,10 @@ pnpm vsce publish 0.0.3
|
|||||||
```bash
|
```bash
|
||||||
#补丁版本 (1.0.0 -> 1.0.1)
|
#补丁版本 (1.0.0 -> 1.0.1)
|
||||||
pnpm version patch
|
pnpm version patch
|
||||||
|
|
||||||
#次要版本 (1.0.0 -> 1.1.0)
|
#次要版本 (1.0.0 -> 1.1.0)
|
||||||
pnpm version minor
|
pnpm version minor
|
||||||
|
|
||||||
#主要版本 (1.0.0 -> 2.0.0)
|
#主要版本 (1.0.0 -> 2.0.0)
|
||||||
pnpm version major
|
pnpm version major
|
||||||
```
|
```
|
||||||
@ -294,18 +298,15 @@ pnpm vsce publish 0.0.3
|
|||||||
```bash
|
```bash
|
||||||
#先编译
|
#先编译
|
||||||
pnpm run compile
|
pnpm run compile
|
||||||
|
|
||||||
#中间build
|
#中间build
|
||||||
pnpm run build
|
pnpm run build
|
||||||
|
|
||||||
#后打包成.vsix
|
#后打包成.vsix
|
||||||
pnpm vsce package --no-dependencies
|
pnpm vsce package --no-dependencies
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
3. 手动上传/命令上传
|
3. 手动上传/命令上传
|
||||||
|
|
||||||
- https://marketplace.visualstudio.com/ 在这个里面手动上传 更新就选择update
|
- https://marketplace.visualstudio.com/ 在这个里面手动上传 更新就选择update
|
||||||
- 命令上传:vsce publish
|
- 命令上传:vsce publish
|
||||||
|
|
||||||
@ -318,6 +319,7 @@ pnpm vsce publish 0.0.3
|
|||||||
**原因:** PAT Token 无效或过期
|
**原因:** PAT Token 无效或过期
|
||||||
|
|
||||||
**解决方案:**
|
**解决方案:**
|
||||||
|
|
||||||
- 重新生成 PAT Token
|
- 重新生成 PAT Token
|
||||||
- 重新登录:`pnpm vsce login ic-coder-team`
|
- 重新登录:`pnpm vsce login ic-coder-team`
|
||||||
|
|
||||||
@ -326,6 +328,7 @@ pnpm vsce publish 0.0.3
|
|||||||
**原因:** Publisher ID 不存在或不匹配
|
**原因:** Publisher ID 不存在或不匹配
|
||||||
|
|
||||||
**解决方案:**
|
**解决方案:**
|
||||||
|
|
||||||
- 检查 `package.json` 中的 `publisher` 字段
|
- 检查 `package.json` 中的 `publisher` 字段
|
||||||
- 确认已在市场创建对应的 Publisher
|
- 确认已在市场创建对应的 Publisher
|
||||||
|
|
||||||
@ -334,17 +337,20 @@ pnpm vsce publish 0.0.3
|
|||||||
**原因:** 必需文件缺失
|
**原因:** 必需文件缺失
|
||||||
|
|
||||||
**解决方案:**
|
**解决方案:**
|
||||||
|
|
||||||
- 确保 `dist/` 目录存在且包含编译后的代码
|
- 确保 `dist/` 目录存在且包含编译后的代码
|
||||||
- 运行 `pnpm run package` 重新构建
|
- 运行 `pnpm run package` 重新构建
|
||||||
|
|
||||||
### 4. 插件审核被拒
|
### 4. 插件审核被拒
|
||||||
|
|
||||||
**常见原因:**
|
**常见原因:**
|
||||||
|
|
||||||
- 插件名称或描述违反市场规则
|
- 插件名称或描述违反市场规则
|
||||||
- 图标不符合要求(建议 128x128 PNG)
|
- 图标不符合要求(建议 128x128 PNG)
|
||||||
- README 内容不完整
|
- README 内容不完整
|
||||||
|
|
||||||
**解决方案:**
|
**解决方案:**
|
||||||
|
|
||||||
- 查看审核反馈邮件
|
- 查看审核反馈邮件
|
||||||
- 修改相关内容后重新发布
|
- 修改相关内容后重新发布
|
||||||
|
|
||||||
@ -366,6 +372,7 @@ code --install-extension ic-coder-plugin-0.0.2.vsix
|
|||||||
```
|
```
|
||||||
|
|
||||||
或者在 VS Code 中:
|
或者在 VS Code 中:
|
||||||
|
|
||||||
1. 打开扩展面板
|
1. 打开扩展面板
|
||||||
2. 点击 `...` 菜单
|
2. 点击 `...` 菜单
|
||||||
3. 选择 **Install from VSIX...**
|
3. 选择 **Install from VSIX...**
|
||||||
|
|||||||
261
docs/AskUserQuestion-API设计.md
Normal file
261
docs/AskUserQuestion-API设计.md
Normal file
@ -0,0 +1,261 @@
|
|||||||
|
# AskUserQuestion 多选支持 - API 设计文档
|
||||||
|
|
||||||
|
## 问题描述
|
||||||
|
|
||||||
|
当前 AI 询问用户问题时存在以下问题:
|
||||||
|
1. 后端返回的选项不准确
|
||||||
|
2. 多个问题只给几个选项
|
||||||
|
3. 不支持多选方式
|
||||||
|
|
||||||
|
## 需求
|
||||||
|
|
||||||
|
实现一个问题对应多个选项,支持多选的方式。
|
||||||
|
|
||||||
|
## 数据结构设计
|
||||||
|
|
||||||
|
### 后端返回格式
|
||||||
|
|
||||||
|
后端通过 SSE 的 `ask_user` 事件返回以下格式:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"askId": "ask_1234567890",
|
||||||
|
"questions": [
|
||||||
|
{
|
||||||
|
"question": "请确认 SPI 控制器的配置需求:工作模式?",
|
||||||
|
"options": [
|
||||||
|
"Master/8位/模式0/固定分频/需要CS",
|
||||||
|
"Master/可配置位宽/可配置模式/需要CS",
|
||||||
|
"Slave模式"
|
||||||
|
],
|
||||||
|
"multiSelect": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"question": "数据位宽?",
|
||||||
|
"options": [
|
||||||
|
"8位 还是其他?"
|
||||||
|
],
|
||||||
|
"multiSelect": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"question": "时钟极性和相位?",
|
||||||
|
"options": [
|
||||||
|
"CPOL=0/CPHA=0 (模式0) 还是其他模式?"
|
||||||
|
],
|
||||||
|
"multiSelect": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"question": "时钟分频?",
|
||||||
|
"options": [
|
||||||
|
"需要可配置的分频比吗?"
|
||||||
|
],
|
||||||
|
"multiSelect": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"question": "是否需要芯片选信号 (CS) 控制?",
|
||||||
|
"options": [
|
||||||
|
"是",
|
||||||
|
"否"
|
||||||
|
],
|
||||||
|
"multiSelect": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 前端数据结构
|
||||||
|
|
||||||
|
#### 1. API 类型定义 (`src/types/api.ts`)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
/** ask_user 事件数据 */
|
||||||
|
export interface AskUserEvent {
|
||||||
|
askId: string;
|
||||||
|
questions: QuestionItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 单个问题项 */
|
||||||
|
export interface QuestionItem {
|
||||||
|
question: string;
|
||||||
|
options: string[];
|
||||||
|
multiSelect?: boolean; // 是否支持多选,默认 false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. MessageSegment 类型 (`src/services/dialogService.ts`)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export interface MessageSegment {
|
||||||
|
type: "text" | "tool" | "question" | "agent" | "plan" | "progress";
|
||||||
|
// ... 其他字段
|
||||||
|
askId?: string;
|
||||||
|
questions?: QuestionItem[]; // 改为问题数组
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. 用户回答格式 (`src/types/api.ts`)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export interface AnswerRequest {
|
||||||
|
taskId: string;
|
||||||
|
askId: string;
|
||||||
|
answers: {
|
||||||
|
[questionIndex: number]: string[]; // 每个问题的答案数组(支持多选)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 前端实现要点
|
||||||
|
|
||||||
|
### 1. 显示多个问题
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 遍历 questions 数组,为每个问题生成 UI
|
||||||
|
segment.questions?.forEach((q, index) => {
|
||||||
|
// 显示问题标题
|
||||||
|
// 显示选项(单选或多选)
|
||||||
|
// 收集答案
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 多选支持
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
if (q.multiSelect) {
|
||||||
|
// 渲染复选框
|
||||||
|
// 允许选择多个选项
|
||||||
|
} else {
|
||||||
|
// 渲染单选按钮
|
||||||
|
// 只允许选择一个选项
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 提交答案
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const answers = {
|
||||||
|
0: ["Master/8位/模式0/固定分频/需要CS"], // 第1个问题的答案
|
||||||
|
1: ["8位 还是其他?"], // 第2个问题的答案
|
||||||
|
2: ["CPOL=0/CPHA=0 (模式0) 还是其他模式?"], // 第3个问题的答案
|
||||||
|
// ...
|
||||||
|
};
|
||||||
|
|
||||||
|
vscode.postMessage({
|
||||||
|
command: 'userAnswer',
|
||||||
|
askId: 'ask_1234567890',
|
||||||
|
answers: answers
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## 后端需要做的修改
|
||||||
|
|
||||||
|
### 1. 修改 AskUserQuestion 工具的返回格式
|
||||||
|
|
||||||
|
从:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"askId": "xxx",
|
||||||
|
"question": "单个问题",
|
||||||
|
"options": ["选项1", "选项2"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
改为:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"askId": "xxx",
|
||||||
|
"questions": [
|
||||||
|
{
|
||||||
|
"question": "问题1",
|
||||||
|
"options": ["选项1", "选项2"],
|
||||||
|
"multiSelect": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"question": "问题2",
|
||||||
|
"options": ["选项A", "选项B", "选项C"],
|
||||||
|
"multiSelect": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 接收答案的格式
|
||||||
|
|
||||||
|
从:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"taskId": "xxx",
|
||||||
|
"askId": "xxx",
|
||||||
|
"selected": ["选项1"],
|
||||||
|
"customInput": "自定义输入"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
改为:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"taskId": "xxx",
|
||||||
|
"askId": "xxx",
|
||||||
|
"answers": {
|
||||||
|
"0": ["选项1"], // 第1个问题的答案
|
||||||
|
"1": ["选项A", "选项B"] // 第2个问题的答案(多选)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 示例场景
|
||||||
|
|
||||||
|
### 场景:SPI 控制器配置
|
||||||
|
|
||||||
|
**后端发送:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"askId": "ask_spi_config",
|
||||||
|
"questions": [
|
||||||
|
{
|
||||||
|
"question": "工作模式?",
|
||||||
|
"options": [
|
||||||
|
"Master/8位/模式0/固定分频/需要CS",
|
||||||
|
"Master/可配置位宽/可配置模式/需要CS",
|
||||||
|
"Slave模式"
|
||||||
|
],
|
||||||
|
"multiSelect": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"question": "需要哪些功能?",
|
||||||
|
"options": [
|
||||||
|
"可配置时钟分频",
|
||||||
|
"可配置数据位宽",
|
||||||
|
"支持多个CS",
|
||||||
|
"DMA支持"
|
||||||
|
],
|
||||||
|
"multiSelect": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**用户选择:**
|
||||||
|
- 问题1:选择 "Master/8位/模式0/固定分频/需要CS"
|
||||||
|
- 问题2:选择 "可配置时钟分频" 和 "可配置数据位宽"
|
||||||
|
|
||||||
|
**前端提交:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"taskId": "task_xxx",
|
||||||
|
"askId": "ask_spi_config",
|
||||||
|
"answers": {
|
||||||
|
"0": ["Master/8位/模式0/固定分频/需要CS"],
|
||||||
|
"1": ["可配置时钟分频", "可配置数据位宽"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 总结
|
||||||
|
|
||||||
|
这个设计方案:
|
||||||
|
1. ✅ 支持多个问题
|
||||||
|
2. ✅ 每个问题有多个选项
|
||||||
|
3. ✅ 支持单选和多选
|
||||||
|
4. ✅ 数据结构清晰,易于扩展
|
||||||
|
5. ✅ 向后兼容(可以只有一个问题)
|
||||||
804
docs/VSCode-Extension-API-Guide.md
Normal file
804
docs/VSCode-Extension-API-Guide.md
Normal file
@ -0,0 +1,804 @@
|
|||||||
|
# VS Code Extension API 核心知识点
|
||||||
|
|
||||||
|
## 目录
|
||||||
|
- [1. Extension 生命周期](#1-extension-生命周期) ⭐⭐⭐
|
||||||
|
- [2. 激活事件 (Activation Events)](#2-激活事件-activation-events) ⭐⭐
|
||||||
|
- [3. 命令系统 (Commands)](#3-命令系统-commands) ⭐⭐
|
||||||
|
- [4. Webview API](#4-webview-api) ⭐⭐⭐⭐⭐ **面试重点**
|
||||||
|
- [5. TreeView 和自定义视图](#5-treeview-和自定义视图) ⭐⭐
|
||||||
|
- [6. 文件系统操作](#6-文件系统操作) ⭐⭐⭐
|
||||||
|
- [7. 配置和存储](#7-配置和存储) ⭐⭐⭐⭐ **面试重点**
|
||||||
|
- [8. 消息通知](#8-消息通知) ⭐
|
||||||
|
- [9. 语言特性支持](#9-语言特性支持) ⭐
|
||||||
|
- [10. 调试和诊断](#10-调试和诊断) ⭐
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Extension 生命周期 ⭐⭐⭐
|
||||||
|
|
||||||
|
### 1.1 核心函数 🔥必考
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// extension.ts
|
||||||
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
|
// 插件激活时调用(只调用一次)
|
||||||
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
|
console.log('Extension is now active!');
|
||||||
|
|
||||||
|
// 注册命令、视图、事件监听等
|
||||||
|
// 使用 context.subscriptions 管理资源
|
||||||
|
}
|
||||||
|
|
||||||
|
// 插件停用时调用(清理资源)
|
||||||
|
export function deactivate() {
|
||||||
|
console.log('Extension is deactivated');
|
||||||
|
// 清理资源、关闭连接等
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 1.2 ExtensionContext 重要属性 🔥必考
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
interface ExtensionContext {
|
||||||
|
// 插件订阅管理(自动清理)
|
||||||
|
subscriptions: { dispose(): any }[];
|
||||||
|
|
||||||
|
// 工作区存储路径
|
||||||
|
storageUri: vscode.Uri | undefined;
|
||||||
|
globalStorageUri: vscode.Uri;
|
||||||
|
|
||||||
|
// 插件路径
|
||||||
|
extensionUri: vscode.Uri;
|
||||||
|
extensionPath: string;
|
||||||
|
|
||||||
|
// 状态存储
|
||||||
|
workspaceState: Memento; // 工作区级别
|
||||||
|
globalState: Memento; // 全局级别
|
||||||
|
secrets: SecretStorage; // 敏感信息存储
|
||||||
|
|
||||||
|
// 环境变量
|
||||||
|
environmentVariableCollection: EnvironmentVariableCollection;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 1.3 资源管理最佳实践 🔥必考
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
|
// ✅ 推荐:使用 context.subscriptions 自动管理
|
||||||
|
context.subscriptions.push(
|
||||||
|
vscode.commands.registerCommand('extension.command', () => {})
|
||||||
|
);
|
||||||
|
|
||||||
|
// ❌ 不推荐:手动管理容易忘记清理
|
||||||
|
const disposable = vscode.commands.registerCommand('extension.command', () => {});
|
||||||
|
// 需要在 deactivate 中手动调用 disposable.dispose()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 激活事件 (Activation Events) ⭐⭐
|
||||||
|
|
||||||
|
### 2.1 常用激活事件 📌重要
|
||||||
|
|
||||||
|
```json
|
||||||
|
// package.json
|
||||||
|
{
|
||||||
|
"activationEvents": [
|
||||||
|
// 启动时激活
|
||||||
|
"onStartupFinished",
|
||||||
|
|
||||||
|
// 执行命令时激活
|
||||||
|
"onCommand:extension.helloWorld",
|
||||||
|
|
||||||
|
// 打开特定语言文件时激活
|
||||||
|
"onLanguage:javascript",
|
||||||
|
"onLanguage:verilog",
|
||||||
|
|
||||||
|
// 打开特定文件类型时激活
|
||||||
|
"onFileSystem:sftp",
|
||||||
|
|
||||||
|
// 打开特定视图时激活
|
||||||
|
"onView:myCustomView",
|
||||||
|
|
||||||
|
// 调试时激活
|
||||||
|
"onDebug",
|
||||||
|
|
||||||
|
// 打开特定 URI 时激活
|
||||||
|
"onUri",
|
||||||
|
|
||||||
|
// Webview 恢复时激活
|
||||||
|
"onWebviewPanel:myWebview",
|
||||||
|
|
||||||
|
// 任务执行时激活
|
||||||
|
"onTaskType:npm"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2.2 延迟激活策略 🔥必考
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ✅ 推荐:使用 onStartupFinished 延迟激活
|
||||||
|
"activationEvents": ["onStartupFinished"]
|
||||||
|
|
||||||
|
// ❌ 不推荐:使用 * 会拖慢启动速度
|
||||||
|
"activationEvents": ["*"]
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 命令系统 (Commands)
|
||||||
|
|
||||||
|
### 3.1 注册命令
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 注册简单命令
|
||||||
|
const disposable = vscode.commands.registerCommand(
|
||||||
|
'extension.helloWorld',
|
||||||
|
() => {
|
||||||
|
vscode.window.showInformationMessage('Hello World!');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
context.subscriptions.push(disposable);
|
||||||
|
|
||||||
|
// 注册带参数的命令
|
||||||
|
vscode.commands.registerCommand(
|
||||||
|
'extension.openFile',
|
||||||
|
(filePath: string) => {
|
||||||
|
vscode.workspace.openTextDocument(filePath).then(doc => {
|
||||||
|
vscode.window.showTextDocument(doc);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.2 执行命令
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 执行内置命令
|
||||||
|
await vscode.commands.executeCommand('workbench.action.files.save');
|
||||||
|
|
||||||
|
// 执行自定义命令
|
||||||
|
await vscode.commands.executeCommand('extension.openFile', '/path/to/file');
|
||||||
|
|
||||||
|
// 获取所有可用命令
|
||||||
|
const commands = await vscode.commands.getCommands();
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.3 常用内置命令
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 文件操作
|
||||||
|
'workbench.action.files.save'
|
||||||
|
'workbench.action.files.saveAll'
|
||||||
|
'workbench.action.closeActiveEditor'
|
||||||
|
|
||||||
|
// 编辑器操作
|
||||||
|
'editor.action.formatDocument'
|
||||||
|
'editor.action.commentLine'
|
||||||
|
'editor.action.selectAll'
|
||||||
|
|
||||||
|
// 窗口操作
|
||||||
|
'workbench.action.toggleSidebarVisibility'
|
||||||
|
'workbench.action.terminal.new'
|
||||||
|
'workbench.action.quickOpen'
|
||||||
|
|
||||||
|
// Git 操作
|
||||||
|
'git.commit'
|
||||||
|
'git.push'
|
||||||
|
'git.pull'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Webview API ⭐⭐⭐⭐⭐ **面试重点**
|
||||||
|
|
||||||
|
### 4.1 创建 Webview Panel 🔥必考
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const panel = vscode.window.createWebviewPanel(
|
||||||
|
'myWebview', // viewType(唯一标识)
|
||||||
|
'My Webview', // 标题
|
||||||
|
vscode.ViewColumn.One, // 显示位置
|
||||||
|
{
|
||||||
|
enableScripts: true, // 启用 JavaScript
|
||||||
|
retainContextWhenHidden: true, // 隐藏时保留状态
|
||||||
|
localResourceRoots: [ // 允许访问的本地资源路径
|
||||||
|
vscode.Uri.joinPath(context.extensionUri, 'media')
|
||||||
|
]
|
||||||
|
}
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 设置 Webview 内容
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
panel.webview.html = getWebviewContent();
|
||||||
|
|
||||||
|
function getWebviewContent() {
|
||||||
|
return `<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>My Webview</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Hello from Webview!</h1>
|
||||||
|
<button onclick="sendMessage()">Send Message</button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const vscode = acquireVsCodeApi();
|
||||||
|
|
||||||
|
function sendMessage() {
|
||||||
|
vscode.postMessage({
|
||||||
|
command: 'alert',
|
||||||
|
text: 'Hello from Webview!'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 接收来自 Extension 的消息
|
||||||
|
window.addEventListener('message', event => {
|
||||||
|
const message = event.data;
|
||||||
|
console.log('Received:', message);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.3 Webview 消息通信 🔥必考(项目核心)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Extension → Webview
|
||||||
|
panel.webview.postMessage({
|
||||||
|
command: 'update',
|
||||||
|
data: 'some data'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Webview → Extension
|
||||||
|
panel.webview.onDidReceiveMessage(
|
||||||
|
message => {
|
||||||
|
switch (message.command) {
|
||||||
|
case 'alert':
|
||||||
|
vscode.window.showInformationMessage(message.text);
|
||||||
|
break;
|
||||||
|
case 'getData':
|
||||||
|
// 处理数据请求
|
||||||
|
panel.webview.postMessage({
|
||||||
|
command: 'dataResponse',
|
||||||
|
data: fetchData()
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
context.subscriptions
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.4 Webview 生命周期管理 📌重要
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 监听 Webview 关闭事件
|
||||||
|
panel.onDidDispose(
|
||||||
|
() => {
|
||||||
|
// 清理资源
|
||||||
|
console.log('Webview disposed');
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
context.subscriptions
|
||||||
|
);
|
||||||
|
|
||||||
|
// 监听 Webview 可见性变化
|
||||||
|
panel.onDidChangeViewState(
|
||||||
|
e => {
|
||||||
|
if (e.webviewPanel.visible) {
|
||||||
|
console.log('Webview is now visible');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
context.subscriptions
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.5 加载本地资源 📌重要
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 获取本地资源 URI
|
||||||
|
const scriptUri = panel.webview.asWebviewUri(
|
||||||
|
vscode.Uri.joinPath(context.extensionUri, 'media', 'script.js')
|
||||||
|
);
|
||||||
|
|
||||||
|
const styleUri = panel.webview.asWebviewUri(
|
||||||
|
vscode.Uri.joinPath(context.extensionUri, 'media', 'style.css')
|
||||||
|
);
|
||||||
|
|
||||||
|
// 在 HTML 中使用
|
||||||
|
const html = `
|
||||||
|
<link href="${styleUri}" rel="stylesheet">
|
||||||
|
<script src="${scriptUri}"></script>
|
||||||
|
`;
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.6 Webview 状态持久化 📌重要
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Webview 中保存状态
|
||||||
|
const vscode = acquireVsCodeApi();
|
||||||
|
const state = vscode.getState() || { count: 0 };
|
||||||
|
|
||||||
|
// 更新状态
|
||||||
|
state.count++;
|
||||||
|
vscode.setState(state);
|
||||||
|
|
||||||
|
// Extension 中序列化状态
|
||||||
|
panel.webview.options = {
|
||||||
|
enableScripts: true,
|
||||||
|
retainContextWhenHidden: true
|
||||||
|
};
|
||||||
|
|
||||||
|
// 恢复 Webview
|
||||||
|
vscode.window.registerWebviewPanelSerializer('myWebview', {
|
||||||
|
async deserializeWebviewPanel(webviewPanel, state) {
|
||||||
|
webviewPanel.webview.html = getWebviewContent();
|
||||||
|
// 恢复状态
|
||||||
|
webviewPanel.webview.postMessage({ command: 'restore', state });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. TreeView 和自定义视图
|
||||||
|
|
||||||
|
### 5.1 创建 TreeView Provider
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
class MyTreeDataProvider implements vscode.TreeDataProvider<TreeItem> {
|
||||||
|
private _onDidChangeTreeData = new vscode.EventEmitter<TreeItem | undefined>();
|
||||||
|
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;
|
||||||
|
|
||||||
|
refresh(): void {
|
||||||
|
this._onDidChangeTreeData.fire(undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
getTreeItem(element: TreeItem): vscode.TreeItem {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
getChildren(element?: TreeItem): Thenable<TreeItem[]> {
|
||||||
|
if (!element) {
|
||||||
|
// 返回根节点
|
||||||
|
return Promise.resolve([
|
||||||
|
new TreeItem('Item 1', vscode.TreeItemCollapsibleState.None),
|
||||||
|
new TreeItem('Item 2', vscode.TreeItemCollapsibleState.Collapsed)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
// 返回子节点
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TreeItem extends vscode.TreeItem {
|
||||||
|
constructor(
|
||||||
|
public readonly label: string,
|
||||||
|
public readonly collapsibleState: vscode.TreeItemCollapsibleState
|
||||||
|
) {
|
||||||
|
super(label, collapsibleState);
|
||||||
|
this.tooltip = `Tooltip for ${label}`;
|
||||||
|
this.command = {
|
||||||
|
command: 'extension.itemClicked',
|
||||||
|
title: 'Click Item',
|
||||||
|
arguments: [this]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.2 注册 TreeView
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const treeDataProvider = new MyTreeDataProvider();
|
||||||
|
const treeView = vscode.window.createTreeView('myTreeView', {
|
||||||
|
treeDataProvider,
|
||||||
|
showCollapseAll: true
|
||||||
|
});
|
||||||
|
|
||||||
|
context.subscriptions.push(treeView);
|
||||||
|
|
||||||
|
// 刷新视图
|
||||||
|
treeDataProvider.refresh();
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.3 WebviewView Provider(侧边栏 Webview)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
class MyWebviewViewProvider implements vscode.WebviewViewProvider {
|
||||||
|
resolveWebviewView(
|
||||||
|
webviewView: vscode.WebviewView,
|
||||||
|
context: vscode.WebviewViewResolveContext,
|
||||||
|
token: vscode.CancellationToken
|
||||||
|
) {
|
||||||
|
webviewView.webview.options = {
|
||||||
|
enableScripts: true
|
||||||
|
};
|
||||||
|
|
||||||
|
webviewView.webview.html = getWebviewContent();
|
||||||
|
|
||||||
|
webviewView.webview.onDidReceiveMessage(message => {
|
||||||
|
// 处理消息
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注册
|
||||||
|
vscode.window.registerWebviewViewProvider(
|
||||||
|
'myWebviewView',
|
||||||
|
new MyWebviewViewProvider()
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 文件系统操作 ⭐⭐⭐
|
||||||
|
|
||||||
|
### 6.1 读取文件 📌重要
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 读取文本文件
|
||||||
|
const uri = vscode.Uri.file('/path/to/file.txt');
|
||||||
|
const content = await vscode.workspace.fs.readFile(uri);
|
||||||
|
const text = Buffer.from(content).toString('utf8');
|
||||||
|
|
||||||
|
// 使用 TextDocument API
|
||||||
|
const document = await vscode.workspace.openTextDocument(uri);
|
||||||
|
const text = document.getText();
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6.2 写入文件
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 写入文件
|
||||||
|
const uri = vscode.Uri.file('/path/to/file.txt');
|
||||||
|
const content = Buffer.from('Hello World', 'utf8');
|
||||||
|
await vscode.workspace.fs.writeFile(uri, content);
|
||||||
|
|
||||||
|
// 使用 WorkspaceEdit
|
||||||
|
const edit = new vscode.WorkspaceEdit();
|
||||||
|
edit.createFile(uri, { overwrite: true });
|
||||||
|
edit.insert(uri, new vscode.Position(0, 0), 'Hello World');
|
||||||
|
await vscode.workspace.applyEdit(edit);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6.3 文件监听
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 监听文件变化
|
||||||
|
const watcher = vscode.workspace.createFileSystemWatcher('**/*.js');
|
||||||
|
|
||||||
|
watcher.onDidCreate(uri => {
|
||||||
|
console.log('File created:', uri.fsPath);
|
||||||
|
});
|
||||||
|
|
||||||
|
watcher.onDidChange(uri => {
|
||||||
|
console.log('File changed:', uri.fsPath);
|
||||||
|
});
|
||||||
|
|
||||||
|
watcher.onDidDelete(uri => {
|
||||||
|
console.log('File deleted:', uri.fsPath);
|
||||||
|
});
|
||||||
|
|
||||||
|
context.subscriptions.push(watcher);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6.4 工作区操作
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 获取工作区文件夹
|
||||||
|
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||||
|
if (workspaceFolders) {
|
||||||
|
const rootPath = workspaceFolders[0].uri.fsPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找文件
|
||||||
|
const files = await vscode.workspace.findFiles(
|
||||||
|
'**/*.ts', // include pattern
|
||||||
|
'**/node_modules/**' // exclude pattern
|
||||||
|
);
|
||||||
|
|
||||||
|
// 打开文件
|
||||||
|
const document = await vscode.workspace.openTextDocument(uri);
|
||||||
|
await vscode.window.showTextDocument(document);
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 配置和存储 ⭐⭐⭐⭐ **面试重点**
|
||||||
|
|
||||||
|
### 7.1 读取配置 📌重要
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 读取配置
|
||||||
|
const config = vscode.workspace.getConfiguration('myExtension');
|
||||||
|
const value = config.get<string>('settingName', 'defaultValue');
|
||||||
|
|
||||||
|
// 监听配置变化
|
||||||
|
vscode.workspace.onDidChangeConfiguration(e => {
|
||||||
|
if (e.affectsConfiguration('myExtension.settingName')) {
|
||||||
|
console.log('Configuration changed');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7.2 更新配置
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const config = vscode.workspace.getConfiguration('myExtension');
|
||||||
|
|
||||||
|
// 更新用户配置(全局)
|
||||||
|
await config.update('settingName', 'newValue', vscode.ConfigurationTarget.Global);
|
||||||
|
|
||||||
|
// 更新工作区配置
|
||||||
|
await config.update('settingName', 'newValue', vscode.ConfigurationTarget.Workspace);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7.3 状态存储 🔥必考
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 工作区状态(仅当前工作区)
|
||||||
|
await context.workspaceState.update('key', 'value');
|
||||||
|
const value = context.workspaceState.get('key');
|
||||||
|
|
||||||
|
// 全局状态(跨工作区)
|
||||||
|
await context.globalState.update('key', 'value');
|
||||||
|
const value = context.globalState.get('key');
|
||||||
|
|
||||||
|
// 存储对象
|
||||||
|
await context.globalState.update('userData', { name: 'John', age: 30 });
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7.4 敏感信息存储 🔥必考(Token 管理)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 存储密码、Token 等敏感信息
|
||||||
|
await context.secrets.store('apiToken', 'secret-token-value');
|
||||||
|
|
||||||
|
// 读取
|
||||||
|
const token = await context.secrets.get('apiToken');
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
await context.secrets.delete('apiToken');
|
||||||
|
|
||||||
|
// 监听变化
|
||||||
|
context.secrets.onDidChange(e => {
|
||||||
|
console.log('Secret changed:', e.key);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. 消息通知
|
||||||
|
|
||||||
|
### 8.1 信息提示
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 普通信息
|
||||||
|
vscode.window.showInformationMessage('Operation completed!');
|
||||||
|
|
||||||
|
// 警告
|
||||||
|
vscode.window.showWarningMessage('This action may cause issues');
|
||||||
|
|
||||||
|
// 错误
|
||||||
|
vscode.window.showErrorMessage('Operation failed!');
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8.2 带按钮的提示
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await vscode.window.showInformationMessage(
|
||||||
|
'Do you want to continue?',
|
||||||
|
'Yes',
|
||||||
|
'No',
|
||||||
|
'Cancel'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result === 'Yes') {
|
||||||
|
// 用户点击了 Yes
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8.3 输入框
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 简单输入
|
||||||
|
const input = await vscode.window.showInputBox({
|
||||||
|
prompt: 'Enter your name',
|
||||||
|
placeHolder: 'John Doe',
|
||||||
|
validateInput: (value) => {
|
||||||
|
return value.length < 3 ? 'Name too short' : null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 快速选择
|
||||||
|
const selected = await vscode.window.showQuickPick(
|
||||||
|
['Option 1', 'Option 2', 'Option 3'],
|
||||||
|
{
|
||||||
|
placeHolder: 'Select an option',
|
||||||
|
canPickMany: false
|
||||||
|
}
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8.4 进度提示
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
await vscode.window.withProgress(
|
||||||
|
{
|
||||||
|
location: vscode.ProgressLocation.Notification,
|
||||||
|
title: 'Processing...',
|
||||||
|
cancellable: true
|
||||||
|
},
|
||||||
|
async (progress, token) => {
|
||||||
|
token.onCancellationRequested(() => {
|
||||||
|
console.log('User canceled');
|
||||||
|
});
|
||||||
|
|
||||||
|
progress.report({ increment: 0, message: 'Starting...' });
|
||||||
|
await doWork1();
|
||||||
|
|
||||||
|
progress.report({ increment: 50, message: 'Half done...' });
|
||||||
|
await doWork2();
|
||||||
|
|
||||||
|
progress.report({ increment: 100, message: 'Complete!' });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. 语言特性支持
|
||||||
|
|
||||||
|
### 9.1 代码补全
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const provider = vscode.languages.registerCompletionItemProvider(
|
||||||
|
'javascript',
|
||||||
|
{
|
||||||
|
provideCompletionItems(document, position) {
|
||||||
|
const item = new vscode.CompletionItem('myFunction');
|
||||||
|
item.kind = vscode.CompletionItemKind.Function;
|
||||||
|
item.detail = 'My custom function';
|
||||||
|
item.documentation = 'This is a custom function';
|
||||||
|
item.insertText = new vscode.SnippetString('myFunction($1)$0');
|
||||||
|
|
||||||
|
return [item];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'.' // 触发字符
|
||||||
|
);
|
||||||
|
|
||||||
|
context.subscriptions.push(provider);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 9.2 悬停提示
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const provider = vscode.languages.registerHoverProvider('javascript', {
|
||||||
|
provideHover(document, position) {
|
||||||
|
const range = document.getWordRangeAtPosition(position);
|
||||||
|
const word = document.getText(range);
|
||||||
|
|
||||||
|
return new vscode.Hover([
|
||||||
|
`**${word}**`,
|
||||||
|
'This is a hover tooltip'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### 9.3 诊断(错误提示)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const diagnosticCollection = vscode.languages.createDiagnosticCollection('myExtension');
|
||||||
|
context.subscriptions.push(diagnosticCollection);
|
||||||
|
|
||||||
|
function updateDiagnostics(document: vscode.TextDocument) {
|
||||||
|
const diagnostics: vscode.Diagnostic[] = [];
|
||||||
|
|
||||||
|
const text = document.getText();
|
||||||
|
const regex = /TODO/g;
|
||||||
|
let match;
|
||||||
|
|
||||||
|
while ((match = regex.exec(text))) {
|
||||||
|
const range = new vscode.Range(
|
||||||
|
document.positionAt(match.index),
|
||||||
|
document.positionAt(match.index + match[0].length)
|
||||||
|
);
|
||||||
|
|
||||||
|
const diagnostic = new vscode.Diagnostic(
|
||||||
|
range,
|
||||||
|
'TODO found',
|
||||||
|
vscode.DiagnosticSeverity.Warning
|
||||||
|
);
|
||||||
|
|
||||||
|
diagnostics.push(diagnostic);
|
||||||
|
}
|
||||||
|
|
||||||
|
diagnosticCollection.set(document.uri, diagnostics);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. 调试和诊断
|
||||||
|
|
||||||
|
### 10.1 输出通道
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const outputChannel = vscode.window.createOutputChannel('My Extension');
|
||||||
|
context.subscriptions.push(outputChannel);
|
||||||
|
|
||||||
|
outputChannel.appendLine('Extension activated');
|
||||||
|
outputChannel.show(); // 显示输出面板
|
||||||
|
```
|
||||||
|
|
||||||
|
### 10.2 日志记录
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 使用 LogOutputChannel(带时间戳)
|
||||||
|
const logger = vscode.window.createOutputChannel('My Extension', { log: true });
|
||||||
|
|
||||||
|
logger.trace('Trace message');
|
||||||
|
logger.debug('Debug message');
|
||||||
|
logger.info('Info message');
|
||||||
|
logger.warn('Warning message');
|
||||||
|
logger.error('Error message');
|
||||||
|
```
|
||||||
|
|
||||||
|
### 10.3 错误处理
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
try {
|
||||||
|
await riskyOperation();
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
vscode.window.showErrorMessage(`Error: ${error.message}`);
|
||||||
|
logger.error(error.stack || error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 最佳实践总结
|
||||||
|
|
||||||
|
### ✅ 推荐做法
|
||||||
|
|
||||||
|
1. **资源管理**:所有 disposable 对象都放入 `context.subscriptions`
|
||||||
|
2. **延迟激活**:使用 `onStartupFinished` 而不是 `*`
|
||||||
|
3. **异步操作**:使用 `async/await` 处理异步操作
|
||||||
|
4. **错误处理**:捕获异常并给用户友好提示
|
||||||
|
5. **类型安全**:充分利用 TypeScript 类型系统
|
||||||
|
6. **状态持久化**:使用 `globalState`/`workspaceState` 保存状态
|
||||||
|
7. **敏感信息**:使用 `secrets` API 存储 Token、密码等
|
||||||
|
|
||||||
|
### ❌ 避免做法
|
||||||
|
|
||||||
|
1. 不要在 `activate` 中执行耗时操作
|
||||||
|
2. 不要忘记清理资源(监听器、Webview 等)
|
||||||
|
3. 不要在 Webview 中直接访问文件系统
|
||||||
|
4. 不要在配置中存储敏感信息
|
||||||
|
5. 不要阻塞主线程(使用 Worker 或异步操作)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 参考资源
|
||||||
|
|
||||||
|
- [VS Code Extension API 官方文档](https://code.visualstudio.com/api)
|
||||||
|
- [Extension Samples](https://github.com/microsoft/vscode-extension-samples)
|
||||||
|
- [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines)
|
||||||
294
docs/delete-file-confirmation.md
Normal file
294
docs/delete-file-confirmation.md
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
# 删除文件确认功能实现文档
|
||||||
|
|
||||||
|
## 1. 功能概述
|
||||||
|
|
||||||
|
在 AI 返回删除文件命令时,前端拦截并弹出确认对话框,用户确认后才执行删除操作。
|
||||||
|
|
||||||
|
## 2. 架构设计
|
||||||
|
|
||||||
|
### 2.1 消息流程
|
||||||
|
|
||||||
|
```
|
||||||
|
AI 后端 → 删除文件工具调用 → 前端拦截 → 用户确认对话框
|
||||||
|
↓
|
||||||
|
确定/取消
|
||||||
|
↓
|
||||||
|
执行删除/返回取消结果
|
||||||
|
↓
|
||||||
|
返回 TOOL_EXECUTION_RESULT
|
||||||
|
↓
|
||||||
|
AI 后端
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2.2 关键原则
|
||||||
|
|
||||||
|
**前端必须返回结果**:无论用户选择什么,前端都必须向后端返回 `TOOL_EXECUTION_RESULT`,否则后端会等待超时。
|
||||||
|
|
||||||
|
## 3. 实现方案
|
||||||
|
|
||||||
|
### 3.1 修改位置
|
||||||
|
|
||||||
|
文件:`src/utils/messageHandler.ts`
|
||||||
|
|
||||||
|
在处理工具调用的函数中,找到删除文件的工具处理逻辑。
|
||||||
|
|
||||||
|
### 3.2 核心代码实现
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
/**
|
||||||
|
* 处理删除文件工具调用(带用户确认)
|
||||||
|
*/
|
||||||
|
async function handleDeleteFileTool(
|
||||||
|
toolCall: any,
|
||||||
|
panel: vscode.WebviewPanel
|
||||||
|
): Promise<ToolExecutionResult> {
|
||||||
|
const filePath = toolCall.arguments.filePath; // 根据实际参数名调整
|
||||||
|
|
||||||
|
// 弹出确认对话框
|
||||||
|
const confirmed = await vscode.window.showWarningMessage(
|
||||||
|
`确定要删除文件吗?\n\n${filePath}`,
|
||||||
|
{
|
||||||
|
modal: true, // 模态对话框,阻止其他操作
|
||||||
|
detail: '此操作不可撤销'
|
||||||
|
},
|
||||||
|
'确定删除',
|
||||||
|
'取消'
|
||||||
|
);
|
||||||
|
|
||||||
|
// 用户确认删除
|
||||||
|
if (confirmed === '确定删除') {
|
||||||
|
try {
|
||||||
|
// 执行删除操作
|
||||||
|
const uri = vscode.Uri.file(filePath);
|
||||||
|
await vscode.workspace.fs.delete(uri, {
|
||||||
|
recursive: false, // 如果是目录需要设置为 true
|
||||||
|
useTrash: true // 移到回收站而非永久删除(推荐)
|
||||||
|
});
|
||||||
|
|
||||||
|
// 返回成功结果
|
||||||
|
return {
|
||||||
|
type: 'TOOL_EXECUTION_RESULT',
|
||||||
|
toolCallId: toolCall.id,
|
||||||
|
result: JSON.stringify({
|
||||||
|
success: true,
|
||||||
|
message: `文件已删除: ${filePath}`
|
||||||
|
})
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
// 删除失败
|
||||||
|
return {
|
||||||
|
type: 'TOOL_EXECUTION_RESULT',
|
||||||
|
toolCallId: toolCall.id,
|
||||||
|
result: JSON.stringify({
|
||||||
|
success: false,
|
||||||
|
error: `删除失败: ${error.message}`
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户取消或关闭对话框
|
||||||
|
return {
|
||||||
|
type: 'TOOL_EXECUTION_RESULT',
|
||||||
|
toolCallId: toolCall.id,
|
||||||
|
result: JSON.stringify({
|
||||||
|
success: false,
|
||||||
|
message: '用户取消了删除操作'
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.3 集成到消息处理流程
|
||||||
|
|
||||||
|
在 `messageHandler.ts` 的工具调用处理逻辑中:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 示例:在处理工具调用的地方
|
||||||
|
async function handleToolCall(toolCall: any, panel: vscode.WebviewPanel) {
|
||||||
|
switch (toolCall.name) {
|
||||||
|
case 'deleteFile': // 根据实际工具名称调整
|
||||||
|
return await handleDeleteFileTool(toolCall, panel);
|
||||||
|
|
||||||
|
case 'deleteDirectory': // 如果有删除目录的工具
|
||||||
|
return await handleDeleteDirectoryTool(toolCall, panel);
|
||||||
|
|
||||||
|
// ... 其他工具
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. 用户体验优化
|
||||||
|
|
||||||
|
### 4.1 对话框样式
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const confirmed = await vscode.window.showWarningMessage(
|
||||||
|
`确定要删除文件吗?\n\n📄 ${path.basename(filePath)}\n📁 ${path.dirname(filePath)}`,
|
||||||
|
{
|
||||||
|
modal: true,
|
||||||
|
detail: '⚠️ 文件将被移到回收站,可以恢复'
|
||||||
|
},
|
||||||
|
'确定删除',
|
||||||
|
'取消'
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 批量删除优化
|
||||||
|
|
||||||
|
如果 AI 一次返回多个删除操作:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 方案 1:逐个确认
|
||||||
|
for (const file of filesToDelete) {
|
||||||
|
await handleDeleteFileTool(file, panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 方案 2:批量确认(推荐)
|
||||||
|
const confirmed = await vscode.window.showWarningMessage(
|
||||||
|
`确定要删除以下 ${filesToDelete.length} 个文件吗?\n\n${filesToDelete.join('\n')}`,
|
||||||
|
{ modal: true },
|
||||||
|
'全部删除',
|
||||||
|
'取消'
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
## 5. 安全考虑
|
||||||
|
|
||||||
|
### 5.1 使用回收站
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
await vscode.workspace.fs.delete(uri, {
|
||||||
|
useTrash: true // 移到回收站,可恢复
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.2 路径验证
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 防止删除工作区外的文件
|
||||||
|
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||||
|
if (!workspaceFolders) {
|
||||||
|
return { success: false, error: '未打开工作区' };
|
||||||
|
}
|
||||||
|
|
||||||
|
const isInWorkspace = workspaceFolders.some(folder =>
|
||||||
|
filePath.startsWith(folder.uri.fsPath)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isInWorkspace) {
|
||||||
|
return { success: false, error: '只能删除工作区内的文件' };
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.3 敏感文件保护
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const protectedFiles = [
|
||||||
|
'package.json',
|
||||||
|
'tsconfig.json',
|
||||||
|
'.git',
|
||||||
|
'node_modules'
|
||||||
|
];
|
||||||
|
|
||||||
|
const fileName = path.basename(filePath);
|
||||||
|
if (protectedFiles.includes(fileName)) {
|
||||||
|
vscode.window.showErrorMessage(`不允许删除系统文件: ${fileName}`);
|
||||||
|
return { success: false, error: '受保护的文件' };
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 6. 错误处理
|
||||||
|
|
||||||
|
### 6.1 常见错误
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
try {
|
||||||
|
await vscode.workspace.fs.delete(uri, { useTrash: true });
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code === 'FileNotFound') {
|
||||||
|
return { success: false, error: '文件不存在' };
|
||||||
|
}
|
||||||
|
if (error.code === 'NoPermissions') {
|
||||||
|
return { success: false, error: '没有删除权限' };
|
||||||
|
}
|
||||||
|
return { success: false, error: error.message };
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 7. 测试场景
|
||||||
|
|
||||||
|
### 7.1 基本测试
|
||||||
|
|
||||||
|
- [ ] 用户点击"确定删除" → 文件被删除
|
||||||
|
- [ ] 用户点击"取消" → 文件保留,返回取消消息
|
||||||
|
- [ ] 用户关闭对话框 → 文件保留,返回取消消息
|
||||||
|
- [ ] 文件不存在 → 返回错误消息
|
||||||
|
- [ ] 没有删除权限 → 返回错误消息
|
||||||
|
|
||||||
|
### 7.2 边界测试
|
||||||
|
|
||||||
|
- [ ] 删除工作区外的文件 → 拒绝
|
||||||
|
- [ ] 删除受保护文件 → 拒绝
|
||||||
|
- [ ] 批量删除 → 正确处理
|
||||||
|
- [ ] 后端收到取消消息后继续对话 → 流程正常
|
||||||
|
|
||||||
|
## 8. 配置选项(可选)
|
||||||
|
|
||||||
|
可以添加用户设置来控制行为:
|
||||||
|
|
||||||
|
```json
|
||||||
|
// package.json
|
||||||
|
"configuration": {
|
||||||
|
"properties": {
|
||||||
|
"ic-coder.confirmDelete": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true,
|
||||||
|
"description": "删除文件前是否需要确认"
|
||||||
|
},
|
||||||
|
"ic-coder.useTrash": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true,
|
||||||
|
"description": "删除文件时移到回收站而非永久删除"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
读取配置:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const config = vscode.workspace.getConfiguration('ic-coder');
|
||||||
|
const needConfirm = config.get<boolean>('confirmDelete', true);
|
||||||
|
const useTrash = config.get<boolean>('useTrash', true);
|
||||||
|
|
||||||
|
if (needConfirm) {
|
||||||
|
// 弹出确认对话框
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 9. 总结
|
||||||
|
|
||||||
|
### 9.1 后端是否需要修改?
|
||||||
|
|
||||||
|
**不需要**。后端继续返回删除工具调用,前端负责:
|
||||||
|
1. 拦截工具调用
|
||||||
|
2. 弹出确认对话框
|
||||||
|
3. 执行或取消删除
|
||||||
|
4. **必须返回结果给后端**
|
||||||
|
|
||||||
|
### 9.2 关键要点
|
||||||
|
|
||||||
|
- ✅ 前端必须返回 `TOOL_EXECUTION_RESULT`
|
||||||
|
- ✅ 使用 `useTrash: true` 提高安全性
|
||||||
|
- ✅ 验证文件路径在工作区内
|
||||||
|
- ✅ 保护敏感文件
|
||||||
|
- ✅ 提供清晰的错误消息
|
||||||
|
|
||||||
|
### 9.3 下一步
|
||||||
|
|
||||||
|
1. 在 `messageHandler.ts` 中找到工具调用处理逻辑
|
||||||
|
2. 实现 `handleDeleteFileTool` 函数
|
||||||
|
3. 集成到现有流程
|
||||||
|
4. 测试各种场景
|
||||||
|
5. 考虑添加用户配置选项
|
||||||
161
docs/personal-rules-mvp-requirements.md
Normal file
161
docs/personal-rules-mvp-requirements.md
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
# 个人规则功能需求文档(方案 A:本地 `.md` 注入)
|
||||||
|
|
||||||
|
## 1. 文档目标
|
||||||
|
|
||||||
|
在不改动现有核心对话模式的前提下,实现“个人规则(Personal Rules)”能力:
|
||||||
|
用户可在插件内维护个人规则文本,插件保存到本地 `.md` 文件;每次发起对话时自动读取并随请求传递给后端,由后端注入模型上下文,影响回答风格与行为。
|
||||||
|
|
||||||
|
## 2. 范围定义
|
||||||
|
|
||||||
|
### 2.1 本期范围(MVP)
|
||||||
|
|
||||||
|
1. 支持用户编辑、保存、启用/停用个人规则。
|
||||||
|
2. 本地落盘为 `.md` 文件。
|
||||||
|
3. 发消息时自动加载规则并传给后端。
|
||||||
|
4. 后端接收结构化字段并注入提示词。
|
||||||
|
5. 基础异常处理和可观测提示。
|
||||||
|
|
||||||
|
### 2.2 非本期范围
|
||||||
|
|
||||||
|
1. 云端同步、多设备同步。
|
||||||
|
2. 规则版本历史/回滚。
|
||||||
|
3. 多规则集合管理(仅单份个人规则文本)。
|
||||||
|
4. 团队共享规则。
|
||||||
|
|
||||||
|
## 3. 术语与核心概念
|
||||||
|
|
||||||
|
1. `Personal Rules`:用户个人偏好与约束文本。
|
||||||
|
2. `Rules File`:本地规则文件,Markdown 格式。
|
||||||
|
3. `Rules Enabled`:规则开关;关闭时不注入。
|
||||||
|
4. `Rules Injection`:请求时将规则传后端并参与模型上下文构建。
|
||||||
|
|
||||||
|
## 4. 用户故事
|
||||||
|
|
||||||
|
1. 作为用户,我希望在插件里写下“回答风格、代码习惯、语言偏好”等个人规则。
|
||||||
|
2. 作为用户,我希望规则保存在本地可见文件中。
|
||||||
|
3. 作为用户,我希望发消息时自动生效,无需每次重复输入。
|
||||||
|
4. 作为用户,我希望可以一键关闭规则,临时不生效。
|
||||||
|
|
||||||
|
## 5. 功能需求(前端/Webview + 扩展端)
|
||||||
|
|
||||||
|
### 5.1 规则管理界面
|
||||||
|
|
||||||
|
1. 提供“个人规则”入口。
|
||||||
|
2. 提供多行编辑框(显示当前规则内容)。
|
||||||
|
3. 提供“保存”按钮。
|
||||||
|
4. 提供“启用/停用”开关。
|
||||||
|
5. 显示当前状态:
|
||||||
|
6. 规则是否启用。
|
||||||
|
7. 规则字数/长度。
|
||||||
|
8. 最近保存时间(可选)。
|
||||||
|
|
||||||
|
### 5.2 本地文件存储
|
||||||
|
|
||||||
|
1. 规则内容保存到本地 `.md`。
|
||||||
|
2. 推荐文件名:`personal-rules.md`。
|
||||||
|
3. 推荐路径(优先):插件全局存储目录下固定子路径。
|
||||||
|
4. 文件不存在时可自动创建。
|
||||||
|
5. 用户可通过“打开规则文件”查看(可选)。
|
||||||
|
|
||||||
|
### 5.3 对话发送前处理
|
||||||
|
|
||||||
|
1. 用户点击发送消息。
|
||||||
|
2. 扩展端检查规则开关:
|
||||||
|
3. 关闭:不读取规则,不传后端。
|
||||||
|
4. 开启:读取 `.md` 内容。
|
||||||
|
5. 读取成功且非空时,将规则文本附加到对话请求结构化字段。
|
||||||
|
6. 读取失败时:提示告警,但不阻断正常对话。
|
||||||
|
|
||||||
|
### 5.4 限制与防护
|
||||||
|
|
||||||
|
1. 规则长度上限(例如 4000 字符,可配置)。
|
||||||
|
2. 超限时保存被拒绝,提示用户缩短。
|
||||||
|
3. 空白内容视为“无规则”。
|
||||||
|
4. 不允许二进制或非文本写入。
|
||||||
|
|
||||||
|
## 6. 功能需求(后端)
|
||||||
|
|
||||||
|
### 6.1 请求协议扩展
|
||||||
|
|
||||||
|
在现有对话请求结构中增加字段:
|
||||||
|
|
||||||
|
1. `personalRules`:字符串,可选。
|
||||||
|
2. `rulesEnabled`:布尔,可选(便于追踪)。
|
||||||
|
3. `rulesMeta`:可选元信息(长度、来源)。
|
||||||
|
|
||||||
|
### 6.2 注入策略
|
||||||
|
|
||||||
|
1. 后端收到 `personalRules` 后,将其注入系统提示层(而非用户消息层)。
|
||||||
|
2. 注入顺序建议:
|
||||||
|
3. 系统安全与平台策略。
|
||||||
|
4. 产品默认系统提示。
|
||||||
|
5. 用户个人规则。
|
||||||
|
6. 用户输入。
|
||||||
|
7. 若 `personalRules` 为空或开关关闭,则跳过注入。
|
||||||
|
|
||||||
|
### 6.3 风险控制
|
||||||
|
|
||||||
|
1. 规则文本不允许覆盖平台安全策略。
|
||||||
|
2. 记录本次是否注入规则(日志字段即可)。
|
||||||
|
3. 异常不应导致整次对话失败(可降级为无规则对话)。
|
||||||
|
|
||||||
|
## 7. 前后端对接设计
|
||||||
|
|
||||||
|
### 7.1 消息链路
|
||||||
|
|
||||||
|
1. Webview 触发 `sendMessage`。
|
||||||
|
2. 扩展端 `messageHandler` 统一处理发送。
|
||||||
|
3. `messageHandler` 在调用 `dialogService.sendMessage` 前读取个人规则。
|
||||||
|
4. `dialogService` 组装 `DialogRequest`,带上 `personalRules`。
|
||||||
|
5. `sseHandler` 发起流式请求。
|
||||||
|
6. 后端注入规则后进入模型推理。
|
||||||
|
7. 正常走现有 SSE 回传流程。
|
||||||
|
|
||||||
|
### 7.2 职责边界
|
||||||
|
|
||||||
|
1. Webview:展示与编辑,不直接拼接最终请求。
|
||||||
|
2. 扩展端:规则文件读写、开关状态管理、请求组装。
|
||||||
|
3. 后端:规则注入、优先级控制、审计日志。
|
||||||
|
|
||||||
|
## 8. 数据与状态设计
|
||||||
|
|
||||||
|
### 8.1 本地文件
|
||||||
|
|
||||||
|
1. 文件格式:Markdown 纯文本。
|
||||||
|
2. 内容约定:无强制模板,允许自由文本。
|
||||||
|
3. 编码:UTF-8。
|
||||||
|
|
||||||
|
### 8.2 本地配置状态
|
||||||
|
|
||||||
|
1. `personalRulesEnabled`:是否启用。
|
||||||
|
2. `personalRulesPath`:规则文件路径(可固定也可配置)。
|
||||||
|
3. `lastSavedAt`:最近保存时间(可选)。
|
||||||
|
|
||||||
|
## 9. 异常与降级
|
||||||
|
|
||||||
|
1. 文件不存在:自动创建空文件,视为无规则。
|
||||||
|
2. 文件读取失败:弹出提示,继续无规则发送。
|
||||||
|
3. 文件写入失败:保存失败提示,不更新状态。
|
||||||
|
4. 后端字段不识别:请求兼容,后端忽略新字段。
|
||||||
|
5. 后端注入失败:降级为普通对话,记录日志。
|
||||||
|
|
||||||
|
## 10. 安全与合规要求
|
||||||
|
|
||||||
|
1. 个人规则属于用户本地数据,不主动上传除非发起对话。
|
||||||
|
2. 日志中避免完整打印规则正文(最多打印长度和哈希)。
|
||||||
|
3. 后端注入时必须确保平台安全策略优先级更高。
|
||||||
|
|
||||||
|
## 11. 验收标准(UAT)
|
||||||
|
|
||||||
|
1. 用户保存规则后,本地存在 `personal-rules.md` 且内容一致。
|
||||||
|
2. 开启规则发送消息时,请求中可观测到 `personalRules` 字段。
|
||||||
|
3. 关闭规则发送消息时,请求中不含该字段或为空。
|
||||||
|
4. 规则文件损坏/读取失败时,不影响正常聊天。
|
||||||
|
5. 超过长度上限时,前端保存被拒绝且提示明确。
|
||||||
|
6. 后端日志可确认“本次是否注入个人规则”。
|
||||||
|
|
||||||
|
## 12. 迭代建议(下一阶段)
|
||||||
|
|
||||||
|
1. 规则模板(代码风格、语言风格、测试偏好)。
|
||||||
|
2. 项目规则与个人规则合并策略。
|
||||||
|
3. 云端同步(按 `userId`),多端一致。
|
||||||
11
package.json
11
package.json
@ -2,7 +2,7 @@
|
|||||||
"name": "iccoder",
|
"name": "iccoder",
|
||||||
"displayName": "IC Coder: Agentic Verilog Platform",
|
"displayName": "IC Coder: Agentic Verilog Platform",
|
||||||
"description": "Agentic Verilog Coding Platform for Real-World FPGAs",
|
"description": "Agentic Verilog Coding Platform for Real-World FPGAs",
|
||||||
"version": "1.0.5",
|
"version": "1.0.11",
|
||||||
"publisher": "ICCoderAgenticVerilogPlatform",
|
"publisher": "ICCoderAgenticVerilogPlatform",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.80.0"
|
"vscode": "^1.80.0"
|
||||||
@ -135,6 +135,7 @@
|
|||||||
"@vscode/test-cli": "^0.0.12",
|
"@vscode/test-cli": "^0.0.12",
|
||||||
"@vscode/test-electron": "^2.5.2",
|
"@vscode/test-electron": "^2.5.2",
|
||||||
"@vscode/vsce": "^3.7.1",
|
"@vscode/vsce": "^3.7.1",
|
||||||
|
"copy-webpack-plugin": "^14.0.0",
|
||||||
"eslint": "^9.39.1",
|
"eslint": "^9.39.1",
|
||||||
"ts-loader": "^9.5.4",
|
"ts-loader": "^9.5.4",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
@ -142,14 +143,6 @@
|
|||||||
"webpack": "^5.103.0",
|
"webpack": "^5.103.0",
|
||||||
"webpack-cli": "^6.0.1"
|
"webpack-cli": "^6.0.1"
|
||||||
},
|
},
|
||||||
"files": [
|
|
||||||
"dist",
|
|
||||||
"media",
|
|
||||||
"tools",
|
|
||||||
"src/assets",
|
|
||||||
"LICENSE",
|
|
||||||
"CHANGELOG.md"
|
|
||||||
],
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@wavedrom/doppler": "^1.14.0",
|
"@wavedrom/doppler": "^1.14.0",
|
||||||
"eventsource-parser": "^3.0.6",
|
"eventsource-parser": "^3.0.6",
|
||||||
|
|||||||
24
pnpm-lock.yaml
generated
24
pnpm-lock.yaml
generated
@ -57,6 +57,9 @@ importers:
|
|||||||
'@vscode/vsce':
|
'@vscode/vsce':
|
||||||
specifier: ^3.7.1
|
specifier: ^3.7.1
|
||||||
version: 3.7.1
|
version: 3.7.1
|
||||||
|
copy-webpack-plugin:
|
||||||
|
specifier: ^14.0.0
|
||||||
|
version: 14.0.0(webpack@5.103.0)
|
||||||
eslint:
|
eslint:
|
||||||
specifier: ^9.39.1
|
specifier: ^9.39.1
|
||||||
version: 9.39.1
|
version: 9.39.1
|
||||||
@ -823,6 +826,12 @@ packages:
|
|||||||
convert-source-map@2.0.0:
|
convert-source-map@2.0.0:
|
||||||
resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==}
|
resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==}
|
||||||
|
|
||||||
|
copy-webpack-plugin@14.0.0:
|
||||||
|
resolution: {integrity: sha512-3JLW90aBGeaTLpM7mYQKpnVdgsUZRExY55giiZgLuX/xTQRUs1dOCwbBnWnvY6Q6rfZoXMNwzOQJCSZPppfqXA==}
|
||||||
|
engines: {node: '>= 20.9.0'}
|
||||||
|
peerDependencies:
|
||||||
|
webpack: ^5.1.0
|
||||||
|
|
||||||
core-util-is@1.0.3:
|
core-util-is@1.0.3:
|
||||||
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
|
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
|
||||||
|
|
||||||
@ -1928,6 +1937,10 @@ packages:
|
|||||||
serialize-javascript@6.0.2:
|
serialize-javascript@6.0.2:
|
||||||
resolution: {integrity: sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==}
|
resolution: {integrity: sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==}
|
||||||
|
|
||||||
|
serialize-javascript@7.0.4:
|
||||||
|
resolution: {integrity: sha512-DuGdB+Po43Q5Jxwpzt1lhyFSYKryqoNjQSA9M92tyw0lyHIOur+XCalOUe0KTJpyqzT8+fQ5A0Jf7vCx/NKmIg==}
|
||||||
|
engines: {node: '>=20.0.0'}
|
||||||
|
|
||||||
setimmediate@1.0.5:
|
setimmediate@1.0.5:
|
||||||
resolution: {integrity: sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==}
|
resolution: {integrity: sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==}
|
||||||
|
|
||||||
@ -3297,6 +3310,15 @@ snapshots:
|
|||||||
|
|
||||||
convert-source-map@2.0.0: {}
|
convert-source-map@2.0.0: {}
|
||||||
|
|
||||||
|
copy-webpack-plugin@14.0.0(webpack@5.103.0):
|
||||||
|
dependencies:
|
||||||
|
glob-parent: 6.0.2
|
||||||
|
normalize-path: 3.0.0
|
||||||
|
schema-utils: 4.3.3
|
||||||
|
serialize-javascript: 7.0.4
|
||||||
|
tinyglobby: 0.2.15
|
||||||
|
webpack: 5.103.0(webpack-cli@6.0.1)
|
||||||
|
|
||||||
core-util-is@1.0.3: {}
|
core-util-is@1.0.3: {}
|
||||||
|
|
||||||
cross-spawn@7.0.6:
|
cross-spawn@7.0.6:
|
||||||
@ -4431,6 +4453,8 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
randombytes: 2.1.0
|
randombytes: 2.1.0
|
||||||
|
|
||||||
|
serialize-javascript@7.0.4: {}
|
||||||
|
|
||||||
setimmediate@1.0.5: {}
|
setimmediate@1.0.5: {}
|
||||||
|
|
||||||
shallow-clone@3.0.1:
|
shallow-clone@3.0.1:
|
||||||
|
|||||||
@ -159,20 +159,32 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||||||
// 注册命令:用户登录
|
// 注册命令:用户登录
|
||||||
const loginCommand = vscode.commands.registerCommand(
|
const loginCommand = vscode.commands.registerCommand(
|
||||||
"ic-coder.login",
|
"ic-coder.login",
|
||||||
async () => {
|
async (options?: { forceReauth?: boolean }) => {
|
||||||
try {
|
try {
|
||||||
// 先清除 session 偏好,避免 VSCode 弹出"账户不一致"确认框
|
const forceReauth = options?.forceReauth === true;
|
||||||
try {
|
const session = await vscode.authentication.getSession("iccoder", [], {
|
||||||
await vscode.authentication.getSession("iccoder", [], {
|
createIfNone: false,
|
||||||
clearSessionPreference: true,
|
});
|
||||||
createIfNone: false
|
const expired = session?.accessToken
|
||||||
});
|
? isTokenExpired(session.accessToken)
|
||||||
} catch {
|
: null;
|
||||||
// 忽略错误
|
|
||||||
|
// 会话仍有效时,直接打开聊天面板
|
||||||
|
if (session && expired === false && !forceReauth) {
|
||||||
|
vscode.commands.executeCommand("ic-coder.openChat");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建新 session
|
// 1) 清空当前登录状态信息
|
||||||
await vscode.authentication.getSession("iccoder", [], { createIfNone: true });
|
await authProvider.clearSessionsForRelogin();
|
||||||
|
await context.globalState.update("icCoderSessions", []);
|
||||||
|
await context.globalState.update("icCoderUserInfo", undefined);
|
||||||
|
|
||||||
|
// 2) 重新登录(强制新会话)
|
||||||
|
await vscode.authentication.getSession("iccoder", [], {
|
||||||
|
clearSessionPreference: true,
|
||||||
|
forceNewSession: true,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
vscode.window.showErrorMessage(`登录失败: ${error}`);
|
vscode.window.showErrorMessage(`登录失败: ${error}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,7 +53,7 @@ function getTierIconUri(
|
|||||||
const iconUri = webview.asWebviewUri(
|
const iconUri = webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(
|
vscode.Uri.joinPath(
|
||||||
context.extensionUri,
|
context.extensionUri,
|
||||||
"src",
|
"dist",
|
||||||
"assets",
|
"assets",
|
||||||
"titleIcon",
|
"titleIcon",
|
||||||
iconFile,
|
iconFile,
|
||||||
@ -91,7 +91,9 @@ export async function showICHelperPanel(
|
|||||||
"立即登录",
|
"立即登录",
|
||||||
);
|
);
|
||||||
if (action === "立即登录") {
|
if (action === "立即登录") {
|
||||||
vscode.commands.executeCommand("ic-coder.login");
|
vscode.commands.executeCommand("ic-coder.login", {
|
||||||
|
forceReauth: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -106,7 +108,9 @@ export async function showICHelperPanel(
|
|||||||
.showWarningMessage("请先登录后再使用 IC Coder", "立即登录")
|
.showWarningMessage("请先登录后再使用 IC Coder", "立即登录")
|
||||||
.then((selection) => {
|
.then((selection) => {
|
||||||
if (selection === "立即登录") {
|
if (selection === "立即登录") {
|
||||||
vscode.commands.executeCommand("ic-coder.login");
|
vscode.commands.executeCommand("ic-coder.login", {
|
||||||
|
forceReauth: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -116,7 +120,9 @@ export async function showICHelperPanel(
|
|||||||
.showWarningMessage("请先登录后再使用 IC Coder", "立即登录")
|
.showWarningMessage("请先登录后再使用 IC Coder", "立即登录")
|
||||||
.then((selection) => {
|
.then((selection) => {
|
||||||
if (selection === "立即登录") {
|
if (selection === "立即登录") {
|
||||||
vscode.commands.executeCommand("ic-coder.login");
|
vscode.commands.executeCommand("ic-coder.login", {
|
||||||
|
forceReauth: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -132,7 +138,7 @@ export async function showICHelperPanel(
|
|||||||
retainContextWhenHidden: true,
|
retainContextWhenHidden: true,
|
||||||
localResourceRoots: [
|
localResourceRoots: [
|
||||||
vscode.Uri.joinPath(context.extensionUri, "media"),
|
vscode.Uri.joinPath(context.extensionUri, "media"),
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets"),
|
vscode.Uri.joinPath(context.extensionUri, "dist", "assets"),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -160,7 +166,7 @@ export async function showICHelperPanel(
|
|||||||
const autoIconUri = panel.webview.asWebviewUri(
|
const autoIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(
|
vscode.Uri.joinPath(
|
||||||
context.extensionUri,
|
context.extensionUri,
|
||||||
"src",
|
"dist",
|
||||||
"assets",
|
"assets",
|
||||||
"model",
|
"model",
|
||||||
"Auto.png",
|
"Auto.png",
|
||||||
@ -169,7 +175,7 @@ export async function showICHelperPanel(
|
|||||||
const liteIconUri = panel.webview.asWebviewUri(
|
const liteIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(
|
vscode.Uri.joinPath(
|
||||||
context.extensionUri,
|
context.extensionUri,
|
||||||
"src",
|
"dist",
|
||||||
"assets",
|
"assets",
|
||||||
"model",
|
"model",
|
||||||
"lite.png",
|
"lite.png",
|
||||||
@ -178,7 +184,7 @@ export async function showICHelperPanel(
|
|||||||
const syIconUri = panel.webview.asWebviewUri(
|
const syIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(
|
vscode.Uri.joinPath(
|
||||||
context.extensionUri,
|
context.extensionUri,
|
||||||
"src",
|
"dist",
|
||||||
"assets",
|
"assets",
|
||||||
"model",
|
"model",
|
||||||
"Sy.png",
|
"Sy.png",
|
||||||
@ -187,7 +193,7 @@ export async function showICHelperPanel(
|
|||||||
const maxIconUri = panel.webview.asWebviewUri(
|
const maxIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(
|
vscode.Uri.joinPath(
|
||||||
context.extensionUri,
|
context.extensionUri,
|
||||||
"src",
|
"dist",
|
||||||
"assets",
|
"assets",
|
||||||
"model",
|
"model",
|
||||||
"Max.png",
|
"Max.png",
|
||||||
@ -198,7 +204,7 @@ export async function showICHelperPanel(
|
|||||||
const qrCodeUri = panel.webview.asWebviewUri(
|
const qrCodeUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(
|
vscode.Uri.joinPath(
|
||||||
context.extensionUri,
|
context.extensionUri,
|
||||||
"src",
|
"dist",
|
||||||
"assets",
|
"assets",
|
||||||
"QRCode",
|
"QRCode",
|
||||||
"wx.png",
|
"wx.png",
|
||||||
@ -430,6 +436,7 @@ export async function showICHelperPanel(
|
|||||||
message.askId,
|
message.askId,
|
||||||
message.selected,
|
message.selected,
|
||||||
message.customInput,
|
message.customInput,
|
||||||
|
message.answers
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
// 新增:中止对话
|
// 新增:中止对话
|
||||||
@ -533,25 +540,39 @@ export async function showICHelperPanel(
|
|||||||
// 检查是否需要显示欢迎弹窗
|
// 检查是否需要显示欢迎弹窗
|
||||||
{
|
{
|
||||||
console.log("[ICHelperPanel] 收到 checkWelcomeModal 消息");
|
console.log("[ICHelperPanel] 收到 checkWelcomeModal 消息");
|
||||||
const showWelcome = context.globalState.get("showWelcomeModal");
|
const userInfo = getCachedUserInfo();
|
||||||
console.log(
|
|
||||||
"[ICHelperPanel] showWelcomeModal 标记值:",
|
|
||||||
showWelcome,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (showWelcome) {
|
console.log("[ICHelperPanel] 用户信息:", userInfo);
|
||||||
// 清除标记并显示欢迎弹窗
|
console.log("[ICHelperPanel] isPluginTrial:", userInfo?.isPluginTrial);
|
||||||
await context.globalState.update("showWelcomeModal", undefined);
|
console.log("[ICHelperPanel] pluginTrialExpiresAt:", userInfo?.pluginTrialExpiresAt);
|
||||||
console.log(
|
|
||||||
"[ICHelperPanel] ✅ 发送 showWelcomeModal 命令到前端",
|
if (userInfo?.isPluginTrial === true) {
|
||||||
);
|
// undefined 表示无效,不显示
|
||||||
|
if (userInfo.pluginTrialExpiresAt === undefined) {
|
||||||
|
console.log("[ICHelperPanel] pluginTrialExpiresAt 未设置,不显示欢迎弹窗");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// null 表示长期有效,显示弹窗
|
||||||
|
// 有值则检查是否过期
|
||||||
|
if (userInfo.pluginTrialExpiresAt !== null) {
|
||||||
|
const now = Date.now();
|
||||||
|
const isExpired = now >= userInfo.pluginTrialExpiresAt;
|
||||||
|
console.log("[ICHelperPanel] 是否过期:", isExpired);
|
||||||
|
|
||||||
|
if (isExpired) {
|
||||||
|
console.log("[ICHelperPanel] 试用已过期,不显示欢迎弹窗");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 未过期或长期有效(null),显示欢迎弹窗
|
||||||
|
console.log("[ICHelperPanel] ✅ 发送 showWelcomeModal 命令到前端");
|
||||||
panel.webview.postMessage({
|
panel.webview.postMessage({
|
||||||
command: "showWelcomeModal",
|
command: "showWelcomeModal",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log("[ICHelperPanel] 非试用用户");
|
||||||
"[ICHelperPanel] showWelcomeModal 标记为 false,不显示弹窗",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -752,6 +773,23 @@ export async function showICHelperPanel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
// 打开文件
|
||||||
|
case "openFile":
|
||||||
|
{
|
||||||
|
let filePath = message.filePath;
|
||||||
|
if (filePath) {
|
||||||
|
// 如果是相对路径,转换为绝对路径
|
||||||
|
if (!require("path").isAbsolute(filePath)) {
|
||||||
|
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
|
||||||
|
if (workspaceFolder) {
|
||||||
|
filePath = require("path").join(workspaceFolder.uri.fsPath, filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const uri = vscode.Uri.file(filePath);
|
||||||
|
vscode.window.showTextDocument(uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
// 新增:检查工作区状态
|
// 新增:检查工作区状态
|
||||||
case "checkWorkspace":
|
case "checkWorkspace":
|
||||||
const hasWorkspace = !!(
|
const hasWorkspace = !!(
|
||||||
|
|||||||
@ -18,6 +18,12 @@ class ChangeTrackerService {
|
|||||||
* 开始新的变更会话
|
* 开始新的变更会话
|
||||||
*/
|
*/
|
||||||
startSession(sessionId: string): void {
|
startSession(sessionId: string): void {
|
||||||
|
// 如果已有 session(无论状态),重用并重置为 active
|
||||||
|
if (this.currentSession) {
|
||||||
|
this.currentSession.status = 'active';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.currentSession = {
|
this.currentSession = {
|
||||||
sessionId,
|
sessionId,
|
||||||
startTime: Date.now(),
|
startTime: Date.now(),
|
||||||
@ -71,7 +77,6 @@ class ChangeTrackerService {
|
|||||||
this.notifyListeners();
|
this.notifyListeners();
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
this.currentSession = null;
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -43,8 +43,7 @@ export interface MessageSegment {
|
|||||||
toolResult?: string;
|
toolResult?: string;
|
||||||
toolDescription?: string;
|
toolDescription?: string;
|
||||||
askId?: string;
|
askId?: string;
|
||||||
question?: string;
|
questions?: import("../types/api").QuestionItem[];
|
||||||
options?: string[];
|
|
||||||
// 智能体相关字段
|
// 智能体相关字段
|
||||||
agentId?: string;
|
agentId?: string;
|
||||||
agentName?: string;
|
agentName?: string;
|
||||||
@ -97,7 +96,7 @@ export interface DialogCallbacks {
|
|||||||
summary: string
|
summary: string
|
||||||
) => void;
|
) => void;
|
||||||
/** 显示问题(ask_user) */
|
/** 显示问题(ask_user) */
|
||||||
onQuestion?: (askId: string, question: string, options: string[]) => void;
|
onQuestion?: (askId: string, questions: import("../types/api").QuestionItem[]) => void;
|
||||||
/** 实时更新段落(流式过程中) */
|
/** 实时更新段落(流式过程中) */
|
||||||
onSegmentUpdate?: (segments: MessageSegment[]) => void;
|
onSegmentUpdate?: (segments: MessageSegment[]) => void;
|
||||||
/** 对话完成,返回所有段落 */
|
/** 对话完成,返回所有段落 */
|
||||||
@ -449,7 +448,9 @@ export class DialogSession {
|
|||||||
.showErrorMessage("登录已过期,请重新登录", "重新登录")
|
.showErrorMessage("登录已过期,请重新登录", "重新登录")
|
||||||
.then((selection) => {
|
.then((selection) => {
|
||||||
if (selection === "重新登录") {
|
if (selection === "重新登录") {
|
||||||
vscode.commands.executeCommand("iccoder.login");
|
vscode.commands.executeCommand("ic-coder.login", {
|
||||||
|
forceReauth: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
throw new Error("登录已过期,请重新登录");
|
throw new Error("登录已过期,请重新登录");
|
||||||
@ -645,8 +646,11 @@ export class DialogSession {
|
|||||||
this.segments.push({
|
this.segments.push({
|
||||||
type: "question",
|
type: "question",
|
||||||
askId: askId,
|
askId: askId,
|
||||||
question: question,
|
questions: [{
|
||||||
options: ["确认执行", "取消"],
|
question: question,
|
||||||
|
options: ["确认执行", "取消"],
|
||||||
|
multiSelect: false
|
||||||
|
}],
|
||||||
});
|
});
|
||||||
|
|
||||||
// 实时发送段落更新
|
// 实时发送段落更新
|
||||||
@ -664,8 +668,11 @@ export class DialogSession {
|
|||||||
await userInteractionManager.handleAskUser(
|
await userInteractionManager.handleAskUser(
|
||||||
{
|
{
|
||||||
askId: askId,
|
askId: askId,
|
||||||
question: question,
|
questions: [{
|
||||||
options: ["确认执行", "取消"],
|
question: question,
|
||||||
|
options: ["确认执行", "取消"],
|
||||||
|
multiSelect: false
|
||||||
|
}]
|
||||||
} as AskUserEvent,
|
} as AskUserEvent,
|
||||||
this.taskId
|
this.taskId
|
||||||
);
|
);
|
||||||
@ -712,8 +719,11 @@ export class DialogSession {
|
|||||||
// 注册问题到前端(类似 askUser),以便用户回答时能找到
|
// 注册问题到前端(类似 askUser),以便用户回答时能找到
|
||||||
const planEvent = {
|
const planEvent = {
|
||||||
askId: askId,
|
askId: askId,
|
||||||
question: `请确认执行计划:${data.title}`,
|
questions: [{
|
||||||
options: ["确认执行", "修改计划", "取消"],
|
question: `请确认执行计划:${data.title}`,
|
||||||
|
options: ["确认执行", "修改计划", "取消"],
|
||||||
|
multiSelect: false
|
||||||
|
}]
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
await userInteractionManager.handleAskUser(
|
await userInteractionManager.handleAskUser(
|
||||||
@ -854,13 +864,12 @@ export class DialogSession {
|
|||||||
this.segments.push({
|
this.segments.push({
|
||||||
type: "question",
|
type: "question",
|
||||||
askId: data.askId,
|
askId: data.askId,
|
||||||
question: data.question,
|
questions: data.questions,
|
||||||
options: data.options,
|
|
||||||
});
|
});
|
||||||
// 实时发送段落更新(包含问题)
|
// 实时发送段落更新(包含问题)
|
||||||
callbacks.onSegmentUpdate?.(this.segments);
|
callbacks.onSegmentUpdate?.(this.segments);
|
||||||
// 同时调用 onQuestion 用于更新状态栏等
|
// 同时调用 onQuestion 用于更新状态栏等
|
||||||
callbacks.onQuestion?.(data.askId, data.question, data.options);
|
callbacks.onQuestion?.(data.askId, data.questions);
|
||||||
try {
|
try {
|
||||||
await userInteractionManager.handleAskUser(data, this.taskId);
|
await userInteractionManager.handleAskUser(data, this.taskId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -894,7 +903,9 @@ export class DialogSession {
|
|||||||
.showErrorMessage("登录状态已过期,请重新登录", "重新登录")
|
.showErrorMessage("登录状态已过期,请重新登录", "重新登录")
|
||||||
.then((selection) => {
|
.then((selection) => {
|
||||||
if (selection === "重新登录") {
|
if (selection === "重新登录") {
|
||||||
vscode.commands.executeCommand("ic-coder.login");
|
vscode.commands.executeCommand("ic-coder.login", {
|
||||||
|
forceReauth: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 登录过期错误已处理,不再传递给外部
|
// 登录过期错误已处理,不再传递给外部
|
||||||
@ -1106,7 +1117,8 @@ export class DialogSession {
|
|||||||
async submitAnswer(
|
async submitAnswer(
|
||||||
askId: string,
|
askId: string,
|
||||||
selected?: string[],
|
selected?: string[],
|
||||||
customInput?: string
|
customInput?: string,
|
||||||
|
answers?: { [questionIndex: string]: string[] }
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// 直接调用 receiveAnswer,传递 taskId 作为 fallbackTaskId
|
// 直接调用 receiveAnswer,传递 taskId 作为 fallbackTaskId
|
||||||
// 如果 pendingQuestions 中有问题,走正常流程
|
// 如果 pendingQuestions 中有问题,走正常流程
|
||||||
@ -1115,6 +1127,7 @@ export class DialogSession {
|
|||||||
askId,
|
askId,
|
||||||
selected,
|
selected,
|
||||||
customInput,
|
customInput,
|
||||||
|
answers,
|
||||||
this.taskId
|
this.taskId
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -176,6 +176,28 @@ export class ICCoderAuthenticationProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear local authentication state without window reload.
|
||||||
|
* Used by re-login flow when session is expired.
|
||||||
|
*/
|
||||||
|
async clearSessionsForRelogin(): Promise<void> {
|
||||||
|
if (this._sessions.length === 0) {
|
||||||
|
await clearUserInfo();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const removed = [...this._sessions];
|
||||||
|
this._sessions = [];
|
||||||
|
await this.saveSessions();
|
||||||
|
await clearUserInfo();
|
||||||
|
|
||||||
|
this._onDidChangeSessions.fire({
|
||||||
|
added: [],
|
||||||
|
removed,
|
||||||
|
changed: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成会话 ID
|
* 生成会话 ID
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -2,23 +2,31 @@
|
|||||||
* 工具执行器
|
* 工具执行器
|
||||||
* 接收后端的 tool_call 事件,执行本地工具,返回结果
|
* 接收后端的 tool_call 事件,执行本地工具,返回结果
|
||||||
*/
|
*/
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from "vscode";
|
||||||
import * as path from 'path';
|
import * as path from "path";
|
||||||
import * as os from 'os';
|
import * as os from "os";
|
||||||
import * as fs from 'fs';
|
import * as fs from "fs";
|
||||||
import { readFileContent, readDirectory } from '../utils/readFiles';
|
import { readFileContent, readDirectory } from "../utils/readFiles";
|
||||||
import { createOrOverwriteFile } from '../utils/createFiles';
|
import { createOrOverwriteFile } from "../utils/createFiles";
|
||||||
import { resolveWorkspaceFilePath, showFileDiff } from '../utils/fileDiff';
|
import { resolveWorkspaceFilePath, showFileDiff } from "../utils/fileDiff";
|
||||||
import { changeTracker } from './changeTracker';
|
import { changeTracker } from "./changeTracker";
|
||||||
import { generateVCD, checkIverilogAvailable, generateMultiVCD, DumpModule } from '../utils/iverilogRunner';
|
import {
|
||||||
import { analyzeVcdFile } from '../utils/vcdParser';
|
generateVCD,
|
||||||
import { executeWaveformTrace, WaveformTraceArgs } from '../utils/waveformTracer';
|
checkIverilogAvailable,
|
||||||
|
generateMultiVCD,
|
||||||
|
DumpModule,
|
||||||
|
} from "../utils/iverilogRunner";
|
||||||
|
import { analyzeVcdFile } from "../utils/vcdParser";
|
||||||
|
import {
|
||||||
|
executeWaveformTrace,
|
||||||
|
WaveformTraceArgs,
|
||||||
|
} from "../utils/waveformTracer";
|
||||||
import {
|
import {
|
||||||
submitToolResult,
|
submitToolResult,
|
||||||
createSuccessResult,
|
createSuccessResult,
|
||||||
createBusinessErrorResult,
|
createBusinessErrorResult,
|
||||||
createSystemErrorResult
|
createSystemErrorResult,
|
||||||
} from './apiClient';
|
} from "./apiClient";
|
||||||
import type {
|
import type {
|
||||||
ToolCallRequest,
|
ToolCallRequest,
|
||||||
ToolName,
|
ToolName,
|
||||||
@ -31,8 +39,8 @@ import type {
|
|||||||
SimulationArgs,
|
SimulationArgs,
|
||||||
WaveformSummaryArgs,
|
WaveformSummaryArgs,
|
||||||
KnowledgeSaveArgs,
|
KnowledgeSaveArgs,
|
||||||
KnowledgeLoadArgs
|
KnowledgeLoadArgs,
|
||||||
} from '../types/api';
|
} from "../types/api";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 工具执行器上下文
|
* 工具执行器上下文
|
||||||
@ -51,7 +59,7 @@ export interface ToolExecutorContext {
|
|||||||
*/
|
*/
|
||||||
export async function executeToolCall(
|
export async function executeToolCall(
|
||||||
request: ToolCallRequest,
|
request: ToolCallRequest,
|
||||||
context: ToolExecutorContext
|
context: ToolExecutorContext,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const toolName = request.params.name as ToolName;
|
const toolName = request.params.name as ToolName;
|
||||||
const args = request.params.arguments;
|
const args = request.params.arguments;
|
||||||
@ -63,37 +71,53 @@ export async function executeToolCall(
|
|||||||
let resultText: string;
|
let resultText: string;
|
||||||
|
|
||||||
switch (toolName) {
|
switch (toolName) {
|
||||||
case 'file_read':
|
case "file_read":
|
||||||
resultText = await executeFileRead(args as unknown as FileReadArgs);
|
resultText = await executeFileRead(args as unknown as FileReadArgs);
|
||||||
break;
|
break;
|
||||||
case 'file_write':
|
case "file_write":
|
||||||
resultText = await executeFileWrite(args as unknown as FileWriteArgs);
|
resultText = await executeFileWrite(args as unknown as FileWriteArgs);
|
||||||
break;
|
break;
|
||||||
case 'file_delete':
|
case "file_delete":
|
||||||
resultText = await executeFileDelete(args as unknown as FileDeleteArgs);
|
resultText = await executeFileDelete(args as unknown as FileDeleteArgs);
|
||||||
break;
|
break;
|
||||||
case 'file_list':
|
case "file_list":
|
||||||
resultText = await executeFileList(args as unknown as FileListArgs);
|
resultText = await executeFileList(args as unknown as FileListArgs);
|
||||||
break;
|
break;
|
||||||
case 'syntax_check':
|
case "syntax_check":
|
||||||
resultText = await executeSyntaxCheck(args as unknown as SyntaxCheckArgs, context);
|
resultText = await executeSyntaxCheck(
|
||||||
|
args as unknown as SyntaxCheckArgs,
|
||||||
|
context,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'iverilog':
|
case "iverilog":
|
||||||
resultText = await executeIverilog(args as unknown as IverilogArgs, context);
|
resultText = await executeIverilog(
|
||||||
|
args as unknown as IverilogArgs,
|
||||||
|
context,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'simulation':
|
case "simulation":
|
||||||
resultText = await executeSimulation(args as unknown as SimulationArgs, context);
|
resultText = await executeSimulation(
|
||||||
|
args as unknown as SimulationArgs,
|
||||||
|
context,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'waveform_summary':
|
case "waveform_summary":
|
||||||
resultText = await executeWaveformSummary(args as unknown as WaveformSummaryArgs);
|
resultText = await executeWaveformSummary(
|
||||||
|
args as unknown as WaveformSummaryArgs,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'waveform_trace':
|
case "waveform_trace":
|
||||||
resultText = await executeWaveformTrace(args as unknown as WaveformTraceArgs, context);
|
resultText = await executeWaveformTrace(
|
||||||
|
args as unknown as WaveformTraceArgs,
|
||||||
|
context,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'knowledge_save':
|
case "knowledge_save":
|
||||||
resultText = await executeKnowledgeSave(args as unknown as KnowledgeSaveArgs);
|
resultText = await executeKnowledgeSave(
|
||||||
|
args as unknown as KnowledgeSaveArgs,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'knowledge_load':
|
case "knowledge_load":
|
||||||
resultText = await executeKnowledgeLoad();
|
resultText = await executeKnowledgeLoad();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -104,10 +128,12 @@ export async function executeToolCall(
|
|||||||
const result = createSuccessResult(callId, resultText);
|
const result = createSuccessResult(callId, resultText);
|
||||||
await submitToolResult(result);
|
await submitToolResult(result);
|
||||||
console.log(`[ToolExecutor] 工具执行成功: ${toolName}, callId=${callId}`);
|
console.log(`[ToolExecutor] 工具执行成功: ${toolName}, callId=${callId}`);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = error instanceof Error ? error.message : '未知错误';
|
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
||||||
console.error(`[ToolExecutor] 工具执行失败: ${toolName}, callId=${callId}`, error);
|
console.error(
|
||||||
|
`[ToolExecutor] 工具执行失败: ${toolName}, callId=${callId}`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
|
||||||
// 提交错误结果
|
// 提交错误结果
|
||||||
const result = createBusinessErrorResult(callId, errorMessage);
|
const result = createBusinessErrorResult(callId, errorMessage);
|
||||||
@ -129,7 +155,7 @@ async function executeFileRead(args: FileReadArgs): Promise<string> {
|
|||||||
async function executeFileWrite(args: FileWriteArgs): Promise<string> {
|
async function executeFileWrite(args: FileWriteArgs): Promise<string> {
|
||||||
const absolutePath = resolveWorkspaceFilePath(args.path);
|
const absolutePath = resolveWorkspaceFilePath(args.path);
|
||||||
const existedBeforeWrite = fs.existsSync(absolutePath);
|
const existedBeforeWrite = fs.existsSync(absolutePath);
|
||||||
const oldContent = existedBeforeWrite ? await readFileContent(args.path) : '';
|
const oldContent = existedBeforeWrite ? await readFileContent(args.path) : "";
|
||||||
|
|
||||||
await createOrOverwriteFile(args.path, args.content);
|
await createOrOverwriteFile(args.path, args.content);
|
||||||
|
|
||||||
@ -137,11 +163,11 @@ async function executeFileWrite(args: FileWriteArgs): Promise<string> {
|
|||||||
try {
|
try {
|
||||||
changeTracker.trackChange(args.path, oldContent, args.content);
|
changeTracker.trackChange(args.path, oldContent, args.content);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('[ToolExecutor] 记录文件变更失败:', error);
|
console.warn("[ToolExecutor] 记录文件变更失败:", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verilog 文件添加知识图谱提示
|
// Verilog 文件添加知识图谱提示
|
||||||
const isVerilogFile = args.path.endsWith('.v') || args.path.endsWith('.sv');
|
const isVerilogFile = args.path.endsWith(".v") || args.path.endsWith(".sv");
|
||||||
if (isVerilogFile) {
|
if (isVerilogFile) {
|
||||||
return `文件已写入: ${args.path}\n\n[提示] 如有新信号或规则,请更新知识图谱`;
|
return `文件已写入: ${args.path}\n\n[提示] 如有新信号或规则,请更新知识图谱`;
|
||||||
}
|
}
|
||||||
@ -151,7 +177,7 @@ async function executeFileWrite(args: FileWriteArgs): Promise<string> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行 file_delete 工具
|
* 执行 file_delete 工具
|
||||||
* 删除指定路径的文件
|
* 删除指定路径的文件(带用户确认)
|
||||||
*/
|
*/
|
||||||
async function executeFileDelete(args: FileDeleteArgs): Promise<string> {
|
async function executeFileDelete(args: FileDeleteArgs): Promise<string> {
|
||||||
const filePath = args.path;
|
const filePath = args.path;
|
||||||
@ -159,7 +185,7 @@ async function executeFileDelete(args: FileDeleteArgs): Promise<string> {
|
|||||||
// 获取工作区路径
|
// 获取工作区路径
|
||||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||||
if (!workspaceFolders || workspaceFolders.length === 0) {
|
if (!workspaceFolders || workspaceFolders.length === 0) {
|
||||||
throw new Error('请先打开一个工作区');
|
throw new Error("请先打开一个工作区");
|
||||||
}
|
}
|
||||||
|
|
||||||
const workspacePath = workspaceFolders[0].uri.fsPath;
|
const workspacePath = workspaceFolders[0].uri.fsPath;
|
||||||
@ -180,18 +206,60 @@ async function executeFileDelete(args: FileDeleteArgs): Promise<string> {
|
|||||||
throw new Error(`不能删除目录,请指定文件路径: ${filePath}`);
|
throw new Error(`不能删除目录,请指定文件路径: ${filePath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 验证文件路径在工作区内
|
||||||
|
const isInWorkspace = workspaceFolders.some((folder) =>
|
||||||
|
absolutePath.startsWith(folder.uri.fsPath),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isInWorkspace) {
|
||||||
|
throw new Error("只能删除工作区内的文件");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保护敏感文件
|
||||||
|
const protectedFiles = [
|
||||||
|
"package.json",
|
||||||
|
"tsconfig.json",
|
||||||
|
".git",
|
||||||
|
"node_modules",
|
||||||
|
];
|
||||||
|
|
||||||
|
const fileName = path.basename(absolutePath);
|
||||||
|
if (protectedFiles.includes(fileName)) {
|
||||||
|
throw new Error(`不允许删除系统文件: ${fileName}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 弹出确认对话框
|
||||||
|
const confirmed = await vscode.window.showWarningMessage(
|
||||||
|
`确定要删除文件吗?\n\n📄 ${path.basename(filePath)}\n📁 ${path.dirname(filePath)}`,
|
||||||
|
{
|
||||||
|
modal: true, // 模态对话框,阻止其他操作
|
||||||
|
detail: "⚠️ 文件将被移到回收站,可以恢复",
|
||||||
|
},
|
||||||
|
"确定删除",
|
||||||
|
"取消",
|
||||||
|
);
|
||||||
|
|
||||||
|
// 用户取消或关闭对话框
|
||||||
|
if (confirmed !== "确定删除") {
|
||||||
|
throw new Error("用户取消了删除操作");
|
||||||
|
}
|
||||||
|
|
||||||
// 读取文件内容用于变更追踪
|
// 读取文件内容用于变更追踪
|
||||||
const oldContent = fs.readFileSync(absolutePath, 'utf-8');
|
const oldContent = fs.readFileSync(absolutePath, "utf-8");
|
||||||
|
|
||||||
// 记录删除变更
|
// 记录删除变更
|
||||||
const relativePath = path.relative(workspacePath, absolutePath);
|
const relativePath = path.relative(workspacePath, absolutePath);
|
||||||
changeTracker.trackChange(relativePath, oldContent, '');
|
changeTracker.trackChange(relativePath, oldContent, "");
|
||||||
|
|
||||||
// 删除文件
|
// 删除文件(移到回收站)
|
||||||
fs.unlinkSync(absolutePath);
|
const uri = vscode.Uri.file(absolutePath);
|
||||||
|
await vscode.workspace.fs.delete(uri, {
|
||||||
|
recursive: false, // 不是目录,设为 false
|
||||||
|
useTrash: true, // 移到回收站而非永久删除
|
||||||
|
});
|
||||||
|
|
||||||
// Verilog 文件添加知识图谱提示
|
// Verilog 文件添加知识图谱提示
|
||||||
const isVerilogFile = filePath.endsWith('.v') || filePath.endsWith('.sv');
|
const isVerilogFile = filePath.endsWith(".v") || filePath.endsWith(".sv");
|
||||||
if (isVerilogFile) {
|
if (isVerilogFile) {
|
||||||
return `文件已删除: ${filePath}\n\n[提示] 请删除知识图谱中相关节点`;
|
return `文件已删除: ${filePath}\n\n[提示] 请删除知识图谱中相关节点`;
|
||||||
}
|
}
|
||||||
@ -203,13 +271,13 @@ async function executeFileDelete(args: FileDeleteArgs): Promise<string> {
|
|||||||
* 执行 file_list 工具
|
* 执行 file_list 工具
|
||||||
*/
|
*/
|
||||||
async function executeFileList(args: FileListArgs): Promise<string> {
|
async function executeFileList(args: FileListArgs): Promise<string> {
|
||||||
const dirPath = args.path || '.';
|
const dirPath = args.path || ".";
|
||||||
const extensions = args.extension ? [args.extension] : undefined;
|
const extensions = args.extension ? [args.extension] : undefined;
|
||||||
|
|
||||||
const files = await readDirectory(dirPath, extensions);
|
const files = await readDirectory(dirPath, extensions);
|
||||||
const fileList = files.map(f => f.path).join('\n');
|
const fileList = files.map((f) => f.path).join("\n");
|
||||||
|
|
||||||
return fileList || '(目录为空)';
|
return fileList || "(目录为空)";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -218,7 +286,7 @@ async function executeFileList(args: FileListArgs): Promise<string> {
|
|||||||
*/
|
*/
|
||||||
async function executeSyntaxCheck(
|
async function executeSyntaxCheck(
|
||||||
args: SyntaxCheckArgs,
|
args: SyntaxCheckArgs,
|
||||||
context: ToolExecutorContext
|
context: ToolExecutorContext,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
// 检查 iverilog 是否可用
|
// 检查 iverilog 是否可用
|
||||||
const iverilogCheck = await checkIverilogAvailable(context.extensionPath);
|
const iverilogCheck = await checkIverilogAvailable(context.extensionPath);
|
||||||
@ -232,33 +300,33 @@ async function executeSyntaxCheck(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// 写入代码到临时文件
|
// 写入代码到临时文件
|
||||||
fs.writeFileSync(tempFile, args.code, 'utf-8');
|
fs.writeFileSync(tempFile, args.code, "utf-8");
|
||||||
|
|
||||||
// 调用 iverilog 进行语法检查
|
// 调用 iverilog 进行语法检查
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require("child_process");
|
||||||
const iverilogPath = getIverilogPath(context.extensionPath);
|
const iverilogPath = getIverilogPath(context.extensionPath);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const child = spawn(iverilogPath, ['-t', 'null', tempFile], {
|
const child = spawn(iverilogPath, ["-t", "null", tempFile], {
|
||||||
cwd: tempDir,
|
cwd: tempDir,
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
IVERILOG_ROOT: path.join(context.extensionPath, 'tools', 'iverilog')
|
IVERILOG_ROOT: path.join(context.extensionPath, "tools", "iverilog"),
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let stdout = '';
|
let stdout = "";
|
||||||
let stderr = '';
|
let stderr = "";
|
||||||
|
|
||||||
child.stdout.on('data', (data: Buffer) => {
|
child.stdout.on("data", (data: Buffer) => {
|
||||||
stdout += data.toString();
|
stdout += data.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
child.stderr.on('data', (data: Buffer) => {
|
child.stderr.on("data", (data: Buffer) => {
|
||||||
stderr += data.toString();
|
stderr += data.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
child.on('close', (code: number) => {
|
child.on("close", (code: number) => {
|
||||||
// 清理临时文件
|
// 清理临时文件
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(tempFile);
|
fs.unlinkSync(tempFile);
|
||||||
@ -267,13 +335,13 @@ async function executeSyntaxCheck(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
resolve('语法检查通过,无错误。');
|
resolve("语法检查通过,无错误。");
|
||||||
} else {
|
} else {
|
||||||
resolve(`语法检查发现错误:\n${stderr || stdout}`);
|
resolve(`语法检查发现错误:\n${stderr || stdout}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
child.on('error', (error: Error) => {
|
child.on("error", (error: Error) => {
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(tempFile);
|
fs.unlinkSync(tempFile);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -282,7 +350,6 @@ async function executeSyntaxCheck(
|
|||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// 确保清理临时文件
|
// 确保清理临时文件
|
||||||
try {
|
try {
|
||||||
@ -300,7 +367,7 @@ async function executeSyntaxCheck(
|
|||||||
*/
|
*/
|
||||||
async function executeIverilog(
|
async function executeIverilog(
|
||||||
args: IverilogArgs,
|
args: IverilogArgs,
|
||||||
context: ToolExecutorContext
|
context: ToolExecutorContext,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
// 检查 iverilog 是否可用
|
// 检查 iverilog 是否可用
|
||||||
const iverilogCheck = await checkIverilogAvailable(context.extensionPath);
|
const iverilogCheck = await checkIverilogAvailable(context.extensionPath);
|
||||||
@ -311,7 +378,7 @@ async function executeIverilog(
|
|||||||
// 获取工作目录
|
// 获取工作目录
|
||||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||||
if (!workspaceFolders || workspaceFolders.length === 0) {
|
if (!workspaceFolders || workspaceFolders.length === 0) {
|
||||||
throw new Error('没有打开的工作区');
|
throw new Error("没有打开的工作区");
|
||||||
}
|
}
|
||||||
const projectPath = workspaceFolders[0].uri.fsPath;
|
const projectPath = workspaceFolders[0].uri.fsPath;
|
||||||
const workDir = args.workDir
|
const workDir = args.workDir
|
||||||
@ -320,32 +387,32 @@ async function executeIverilog(
|
|||||||
|
|
||||||
// 解析参数
|
// 解析参数
|
||||||
const iverilogPath = getIverilogPath(context.extensionPath);
|
const iverilogPath = getIverilogPath(context.extensionPath);
|
||||||
const cmdArgs = args.args.split(/\s+/).filter(a => a.length > 0);
|
const cmdArgs = args.args.split(/\s+/).filter((a) => a.length > 0);
|
||||||
|
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require("child_process");
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const child = spawn(iverilogPath, cmdArgs, {
|
const child = spawn(iverilogPath, cmdArgs, {
|
||||||
cwd: workDir,
|
cwd: workDir,
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
IVERILOG_ROOT: path.join(context.extensionPath, 'tools', 'iverilog')
|
IVERILOG_ROOT: path.join(context.extensionPath, "tools", "iverilog"),
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let stdout = '';
|
let stdout = "";
|
||||||
let stderr = '';
|
let stderr = "";
|
||||||
|
|
||||||
child.stdout.on('data', (data: Buffer) => {
|
child.stdout.on("data", (data: Buffer) => {
|
||||||
stdout += data.toString();
|
stdout += data.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
child.stderr.on('data', (data: Buffer) => {
|
child.stderr.on("data", (data: Buffer) => {
|
||||||
stderr += data.toString();
|
stderr += data.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
child.on('close', (code: number) => {
|
child.on("close", (code: number) => {
|
||||||
const output = stderr || stdout || '(无输出)';
|
const output = stderr || stdout || "(无输出)";
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
resolve(`执行成功\n${output}`);
|
resolve(`执行成功\n${output}`);
|
||||||
} else {
|
} else {
|
||||||
@ -353,7 +420,7 @@ async function executeIverilog(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
child.on('error', (error: Error) => {
|
child.on("error", (error: Error) => {
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -364,12 +431,12 @@ async function executeIverilog(
|
|||||||
*/
|
*/
|
||||||
async function executeSimulation(
|
async function executeSimulation(
|
||||||
args: SimulationArgs,
|
args: SimulationArgs,
|
||||||
context: ToolExecutorContext
|
context: ToolExecutorContext,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
// 获取工作区路径
|
// 获取工作区路径
|
||||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||||
if (!workspaceFolders || workspaceFolders.length === 0) {
|
if (!workspaceFolders || workspaceFolders.length === 0) {
|
||||||
throw new Error('请先打开一个工作区');
|
throw new Error("请先打开一个工作区");
|
||||||
}
|
}
|
||||||
|
|
||||||
const projectPath = workspaceFolders[0].uri.fsPath;
|
const projectPath = workspaceFolders[0].uri.fsPath;
|
||||||
@ -377,21 +444,24 @@ async function executeSimulation(
|
|||||||
// 检查是否有 dumpModules 参数(多 VCD 模式)
|
// 检查是否有 dumpModules 参数(多 VCD 模式)
|
||||||
if (args.dumpModules) {
|
if (args.dumpModules) {
|
||||||
const modules = parseDumpModules(args.dumpModules);
|
const modules = parseDumpModules(args.dumpModules);
|
||||||
const vcdDir = args.vcdDir || 'vcd';
|
const vcdDir = args.vcdDir || "vcd";
|
||||||
|
|
||||||
const result = await generateMultiVCD(
|
const result = await generateMultiVCD(
|
||||||
projectPath,
|
projectPath,
|
||||||
context.extensionPath,
|
context.extensionPath,
|
||||||
args.tbPath,
|
args.tbPath,
|
||||||
modules,
|
modules,
|
||||||
vcdDir
|
vcdDir,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const vcdList = result.vcdFiles
|
const vcdList = result.vcdFiles
|
||||||
.map(f => `- ${f.moduleName}: ${f.success ? f.vcdPath : '失败 - ' + f.error}`)
|
.map(
|
||||||
.join('\n');
|
(f) =>
|
||||||
return `${result.message}\n\nVCD 文件列表:\n${vcdList}${result.stdout ? '\n\n仿真输出:' + result.stdout : ''}`;
|
`- ${f.moduleName}: ${f.success ? f.vcdPath : "失败 - " + f.error}`,
|
||||||
|
)
|
||||||
|
.join("\n");
|
||||||
|
return `${result.message}\n\nVCD 文件列表:\n${vcdList}${result.stdout ? "\n\n仿真输出:" + result.stdout : ""}`;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(result.message);
|
throw new Error(result.message);
|
||||||
}
|
}
|
||||||
@ -420,8 +490,8 @@ async function executeSimulation(
|
|||||||
* 格式:name:path,name:path
|
* 格式:name:path,name:path
|
||||||
*/
|
*/
|
||||||
function parseDumpModules(dumpModules: string): DumpModule[] {
|
function parseDumpModules(dumpModules: string): DumpModule[] {
|
||||||
return dumpModules.split(',').map(item => {
|
return dumpModules.split(",").map((item) => {
|
||||||
const [name, modulePath] = item.trim().split(':');
|
const [name, modulePath] = item.trim().split(":");
|
||||||
return { name: name.trim(), path: modulePath.trim() };
|
return { name: name.trim(), path: modulePath.trim() };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -430,13 +500,15 @@ function parseDumpModules(dumpModules: string): DumpModule[] {
|
|||||||
* 执行 waveform_summary 工具
|
* 执行 waveform_summary 工具
|
||||||
* 解析 VCD 文件并返回波形摘要
|
* 解析 VCD 文件并返回波形摘要
|
||||||
*/
|
*/
|
||||||
async function executeWaveformSummary(args: WaveformSummaryArgs): Promise<string> {
|
async function executeWaveformSummary(
|
||||||
|
args: WaveformSummaryArgs,
|
||||||
|
): Promise<string> {
|
||||||
const { vcdPath, signals, checkpoints } = args;
|
const { vcdPath, signals, checkpoints } = args;
|
||||||
|
|
||||||
// 获取工作区路径
|
// 获取工作区路径
|
||||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||||
if (!workspaceFolders || workspaceFolders.length === 0) {
|
if (!workspaceFolders || workspaceFolders.length === 0) {
|
||||||
throw new Error('请先打开一个工作区');
|
throw new Error("请先打开一个工作区");
|
||||||
}
|
}
|
||||||
|
|
||||||
const workspacePath = workspaceFolders[0].uri.fsPath;
|
const workspacePath = workspaceFolders[0].uri.fsPath;
|
||||||
@ -467,17 +539,20 @@ async function executeWaveformSummary(args: WaveformSummaryArgs): Promise<string
|
|||||||
async function executeKnowledgeSave(args: KnowledgeSaveArgs): Promise<string> {
|
async function executeKnowledgeSave(args: KnowledgeSaveArgs): Promise<string> {
|
||||||
const workspaceFolder = getWorkspaceFolder();
|
const workspaceFolder = getWorkspaceFolder();
|
||||||
if (!workspaceFolder) {
|
if (!workspaceFolder) {
|
||||||
throw new Error('请先打开一个工作区');
|
throw new Error("请先打开一个工作区");
|
||||||
}
|
}
|
||||||
|
|
||||||
const iccoderDirUri = vscode.Uri.joinPath(workspaceFolder.uri, '.iccoder');
|
const iccoderDirUri = vscode.Uri.joinPath(workspaceFolder.uri, ".iccoder");
|
||||||
const knowledgeUri = vscode.Uri.joinPath(iccoderDirUri, 'knowledge.json');
|
const knowledgeUri = vscode.Uri.joinPath(iccoderDirUri, "knowledge.json");
|
||||||
|
|
||||||
// 确保 .iccoder 目录存在(兼容远程/虚拟工作区)
|
// 确保 .iccoder 目录存在(兼容远程/虚拟工作区)
|
||||||
await vscode.workspace.fs.createDirectory(iccoderDirUri);
|
await vscode.workspace.fs.createDirectory(iccoderDirUri);
|
||||||
|
|
||||||
// 写入知识图谱(UTF-8)
|
// 写入知识图谱(UTF-8)
|
||||||
await vscode.workspace.fs.writeFile(knowledgeUri, Buffer.from(args.data || '', 'utf-8'));
|
await vscode.workspace.fs.writeFile(
|
||||||
|
knowledgeUri,
|
||||||
|
Buffer.from(args.data || "", "utf-8"),
|
||||||
|
);
|
||||||
|
|
||||||
return `知识图谱已保存: .iccoder/knowledge.json`;
|
return `知识图谱已保存: .iccoder/knowledge.json`;
|
||||||
}
|
}
|
||||||
@ -489,20 +564,33 @@ async function executeKnowledgeSave(args: KnowledgeSaveArgs): Promise<string> {
|
|||||||
async function executeKnowledgeLoad(): Promise<string> {
|
async function executeKnowledgeLoad(): Promise<string> {
|
||||||
const workspaceFolder = getWorkspaceFolder();
|
const workspaceFolder = getWorkspaceFolder();
|
||||||
if (!workspaceFolder) {
|
if (!workspaceFolder) {
|
||||||
throw new Error('请先打开一个工作区');
|
throw new Error("请先打开一个工作区");
|
||||||
}
|
}
|
||||||
|
|
||||||
const knowledgeUri = vscode.Uri.joinPath(workspaceFolder.uri, '.iccoder', 'knowledge.json');
|
const knowledgeUri = vscode.Uri.joinPath(
|
||||||
|
workspaceFolder.uri,
|
||||||
|
".iccoder",
|
||||||
|
"knowledge.json",
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const bytes = await vscode.workspace.fs.readFile(knowledgeUri);
|
const bytes = await vscode.workspace.fs.readFile(knowledgeUri);
|
||||||
const content = Buffer.from(bytes).toString('utf-8');
|
const content = Buffer.from(bytes).toString("utf-8");
|
||||||
return content;
|
return content;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// 文件不存在:返回空图谱
|
// 文件不存在:返回空图谱
|
||||||
if (error instanceof vscode.FileSystemError && error.code === 'FileNotFound') {
|
if (
|
||||||
|
error instanceof vscode.FileSystemError &&
|
||||||
|
error.code === "FileNotFound"
|
||||||
|
) {
|
||||||
// 与后端 KnowledgeGraph 结构保持一致(nodes/edges + nodeClass 多态字段)
|
// 与后端 KnowledgeGraph 结构保持一致(nodes/edges + nodeClass 多态字段)
|
||||||
return JSON.stringify({ taskId: '', version: 1, module: null, nodes: [], edges: [] });
|
return JSON.stringify({
|
||||||
|
taskId: "",
|
||||||
|
version: 1,
|
||||||
|
module: null,
|
||||||
|
nodes: [],
|
||||||
|
edges: [],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@ -515,7 +603,9 @@ function getWorkspaceFolder(): vscode.WorkspaceFolder | undefined {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const activeUri = vscode.window.activeTextEditor?.document?.uri;
|
const activeUri = vscode.window.activeTextEditor?.document?.uri;
|
||||||
const activeFolder = activeUri ? vscode.workspace.getWorkspaceFolder(activeUri) : undefined;
|
const activeFolder = activeUri
|
||||||
|
? vscode.workspace.getWorkspaceFolder(activeUri)
|
||||||
|
: undefined;
|
||||||
return activeFolder ?? folders[0];
|
return activeFolder ?? folders[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,22 +614,24 @@ function getWorkspaceFolder(): vscode.WorkspaceFolder | undefined {
|
|||||||
*/
|
*/
|
||||||
function getIverilogPath(extensionPath: string): string {
|
function getIverilogPath(extensionPath: string): string {
|
||||||
const platform = process.platform;
|
const platform = process.platform;
|
||||||
if (platform === 'win32') {
|
if (platform === "win32") {
|
||||||
return path.join(extensionPath, 'tools', 'iverilog', 'bin', 'iverilog.exe');
|
return path.join(extensionPath, "tools", "iverilog", "bin", "iverilog.exe");
|
||||||
} else {
|
} else {
|
||||||
return path.join(extensionPath, 'tools', 'iverilog', 'bin', 'iverilog');
|
return path.join(extensionPath, "tools", "iverilog", "bin", "iverilog");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建工具执行器上下文
|
* 创建工具执行器上下文
|
||||||
*/
|
*/
|
||||||
export function createToolExecutorContext(extensionPath: string): ToolExecutorContext {
|
export function createToolExecutorContext(
|
||||||
|
extensionPath: string,
|
||||||
|
): ToolExecutorContext {
|
||||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||||
const workspacePath = workspaceFolders?.[0]?.uri.fsPath || '';
|
const workspacePath = workspaceFolders?.[0]?.uri.fsPath || "";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
extensionPath,
|
extensionPath,
|
||||||
workspacePath
|
workspacePath,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { submitAnswer, submitToolConfirm } from './apiClient';
|
import { submitAnswer, submitToolConfirm } from './apiClient';
|
||||||
import type { AskUserEvent, AnswerRequest } from '../types/api';
|
import type { AskUserEvent, AnswerRequest, QuestionItem } from '../types/api';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 待处理的用户问题
|
* 待处理的用户问题
|
||||||
@ -12,8 +12,7 @@ import type { AskUserEvent, AnswerRequest } from '../types/api';
|
|||||||
interface PendingQuestion {
|
interface PendingQuestion {
|
||||||
askId: string;
|
askId: string;
|
||||||
taskId: string;
|
taskId: string;
|
||||||
question: string;
|
questions: QuestionItem[];
|
||||||
options: string[];
|
|
||||||
resolve: (answer: string) => void;
|
resolve: (answer: string) => void;
|
||||||
reject: (error: Error) => void;
|
reject: (error: Error) => void;
|
||||||
}
|
}
|
||||||
@ -45,9 +44,9 @@ export class UserInteractionManager {
|
|||||||
* @param taskId 当前任务ID
|
* @param taskId 当前任务ID
|
||||||
*/
|
*/
|
||||||
async handleAskUser(event: AskUserEvent, taskId: string): Promise<void> {
|
async handleAskUser(event: AskUserEvent, taskId: string): Promise<void> {
|
||||||
const { askId, question, options } = event;
|
const { askId, questions } = event;
|
||||||
|
|
||||||
console.log(`[UserInteraction] 收到问题: askId=${askId}, question=${question}`);
|
console.log(`[UserInteraction] 收到问题: askId=${askId}, count=${questions.length}`);
|
||||||
|
|
||||||
// 注意:问题显示已经通过 dialogService 的 onSegmentUpdate 统一处理
|
// 注意:问题显示已经通过 dialogService 的 onSegmentUpdate 统一处理
|
||||||
// 这里不再单独发送 showQuestion 命令,避免重复显示
|
// 这里不再单独发送 showQuestion 命令,避免重复显示
|
||||||
@ -57,8 +56,7 @@ export class UserInteractionManager {
|
|||||||
this.pendingQuestions.set(askId, {
|
this.pendingQuestions.set(askId, {
|
||||||
askId,
|
askId,
|
||||||
taskId,
|
taskId,
|
||||||
question,
|
questions,
|
||||||
options,
|
|
||||||
resolve: (answer: string) => {
|
resolve: (answer: string) => {
|
||||||
this.submitUserAnswer(askId, taskId, answer)
|
this.submitUserAnswer(askId, taskId, answer)
|
||||||
.then(() => resolve())
|
.then(() => resolve())
|
||||||
@ -80,24 +78,38 @@ export class UserInteractionManager {
|
|||||||
/**
|
/**
|
||||||
* 处理用户提交的回答(从 WebView 调用)
|
* 处理用户提交的回答(从 WebView 调用)
|
||||||
* @param askId 问题ID
|
* @param askId 问题ID
|
||||||
* @param selected 选中的选项
|
* @param selected 选中的选项(旧格式)
|
||||||
* @param customInput 自定义输入
|
* @param customInput 自定义输入(旧格式)
|
||||||
|
* @param answers 新格式:按问题索引的答案
|
||||||
* @param fallbackTaskId 当问题不存在时使用的 taskId(用于直接发送到后端)
|
* @param fallbackTaskId 当问题不存在时使用的 taskId(用于直接发送到后端)
|
||||||
*/
|
*/
|
||||||
async receiveAnswer(
|
async receiveAnswer(
|
||||||
askId: string,
|
askId: string,
|
||||||
selected?: string[],
|
selected?: string[],
|
||||||
customInput?: string,
|
customInput?: string,
|
||||||
|
answers?: { [questionIndex: string]: string[] },
|
||||||
fallbackTaskId?: string
|
fallbackTaskId?: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const pending = this.pendingQuestions.get(askId);
|
const pending = this.pendingQuestions.get(askId);
|
||||||
const answer = customInput || selected?.join(', ') || '';
|
|
||||||
|
// 构建答案字符串
|
||||||
|
let answer = '';
|
||||||
|
if (answers && Object.keys(answers).length > 0) {
|
||||||
|
// 新格式:多问题答案
|
||||||
|
answer = Object.entries(answers)
|
||||||
|
.sort(([a], [b]) => parseInt(a) - parseInt(b))
|
||||||
|
.map(([_, vals]) => vals.join('; '))
|
||||||
|
.join(' | ');
|
||||||
|
} else {
|
||||||
|
// 旧格式:单问题答案
|
||||||
|
answer = customInput || selected?.join(', ') || '';
|
||||||
|
}
|
||||||
|
|
||||||
if (!pending) {
|
if (!pending) {
|
||||||
// 问题不存在(可能是页面刷新或会话切换后),尝试直接发送到后端
|
// 问题不存在(可能是页面刷新或会话切换后),尝试直接发送到后端
|
||||||
if (fallbackTaskId) {
|
if (fallbackTaskId) {
|
||||||
console.log(`[UserInteraction] 问题不在 pendingQuestions 中,直接发送到后端: askId=${askId}, taskId=${fallbackTaskId}`);
|
console.log(`[UserInteraction] 问题不在 pendingQuestions 中,直接发送到后端: askId=${askId}, taskId=${fallbackTaskId}`);
|
||||||
await this.submitUserAnswer(askId, fallbackTaskId, answer);
|
await this.submitUserAnswer(askId, fallbackTaskId, answer, answers);
|
||||||
} else {
|
} else {
|
||||||
console.warn(`[UserInteraction] 问题不存在且无 fallbackTaskId: askId=${askId}`);
|
console.warn(`[UserInteraction] 问题不存在且无 fallbackTaskId: askId=${askId}`);
|
||||||
}
|
}
|
||||||
@ -119,7 +131,8 @@ export class UserInteractionManager {
|
|||||||
private async submitUserAnswer(
|
private async submitUserAnswer(
|
||||||
askId: string,
|
askId: string,
|
||||||
taskId: string,
|
taskId: string,
|
||||||
answer: string
|
answer: string,
|
||||||
|
answers?: { [questionIndex: string]: string[] }
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// 检查是否是工具确认类型的问题
|
// 检查是否是工具确认类型的问题
|
||||||
if (askId.startsWith('tool_confirm_')) {
|
if (askId.startsWith('tool_confirm_')) {
|
||||||
@ -148,7 +161,8 @@ export class UserInteractionManager {
|
|||||||
const request: AnswerRequest = {
|
const request: AnswerRequest = {
|
||||||
askId,
|
askId,
|
||||||
taskId,
|
taskId,
|
||||||
customInput: answer
|
answers: answers,
|
||||||
|
customInput: answers ? undefined : answer
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -162,10 +162,14 @@ export async function getUserInfo(token: string): Promise<UserInfo | null> {
|
|||||||
console.log('[UserService] 从 getInfo 接口获取到 isPluginTrial: true');
|
console.log('[UserService] 从 getInfo 接口获取到 isPluginTrial: true');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取试用到期时间
|
// 获取试用到期时间(null 表示长期有效)
|
||||||
if (response.enterpriseTrialExpires) {
|
if (response.enterpriseTrialExpires !== undefined) {
|
||||||
userInfo.pluginTrialExpiresAt = response.enterpriseTrialExpires;
|
userInfo.pluginTrialExpiresAt = response.enterpriseTrialExpires;
|
||||||
console.log('[UserService] 试用到期时间:', new Date(response.enterpriseTrialExpires).toLocaleString());
|
if (response.enterpriseTrialExpires === null) {
|
||||||
|
console.log('[UserService] 试用长期有效');
|
||||||
|
} else {
|
||||||
|
console.log('[UserService] 试用到期时间:', new Date(response.enterpriseTrialExpires).toLocaleString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return userInfo;
|
return userInfo;
|
||||||
@ -335,28 +339,38 @@ export async function onTokenReceived(token: string): Promise<UserInfo | null> {
|
|||||||
console.log('[UserService] 检查用户类型,isPluginTrial:', userInfo.isPluginTrial);
|
console.log('[UserService] 检查用户类型,isPluginTrial:', userInfo.isPluginTrial);
|
||||||
console.log('[UserService] extensionContext 是否存在:', !!extensionContext);
|
console.log('[UserService] extensionContext 是否存在:', !!extensionContext);
|
||||||
|
|
||||||
if (userInfo.isPluginTrial === true) {
|
if (userInfo.isPluginTrial === true && userInfo.pluginTrialExpiresAt !== null && userInfo.pluginTrialExpiresAt !== undefined) {
|
||||||
// 插件试用用户:标记需要显示欢迎弹窗
|
// 检查是否过期
|
||||||
const hasWelcomed = extensionContext?.globalState.get('pluginTrialWelcomed');
|
const now = Date.now();
|
||||||
console.log('[UserService] 是否已显示过欢迎弹窗:', hasWelcomed);
|
const isExpired = now >= userInfo.pluginTrialExpiresAt;
|
||||||
|
console.log('[UserService] 试用到期时间:', new Date(userInfo.pluginTrialExpiresAt).toLocaleString());
|
||||||
|
console.log('[UserService] 当前时间:', new Date(now).toLocaleString());
|
||||||
|
console.log('[UserService] 是否过期:', isExpired);
|
||||||
|
|
||||||
if (!hasWelcomed && extensionContext) {
|
if (isExpired) {
|
||||||
// 设置标记,让聊天面板显示欢迎弹窗
|
// 已过期:显示邀请码弹窗
|
||||||
await extensionContext.globalState.update('showWelcomeModal', true);
|
console.log('[UserService] 试用已过期,将显示邀请码弹窗');
|
||||||
await extensionContext.globalState.update('pluginTrialWelcomed', true);
|
|
||||||
console.log('[UserService] ✅ 已设置欢迎弹窗标记 showWelcomeModal=true');
|
|
||||||
|
|
||||||
// 验证标记是否设置成功
|
|
||||||
const checkMark = extensionContext.globalState.get('showWelcomeModal');
|
|
||||||
console.log('[UserService] 验证标记:', checkMark);
|
|
||||||
} else if (!extensionContext) {
|
|
||||||
console.error('[UserService] ❌ extensionContext 为 null,无法设置标记');
|
|
||||||
} else {
|
} else {
|
||||||
console.log('[UserService] 已经显示过欢迎弹窗,跳过');
|
// 未过期:显示欢迎弹窗
|
||||||
|
const hasWelcomed = extensionContext?.globalState.get('pluginTrialWelcomed');
|
||||||
|
console.log('[UserService] 是否已显示过欢迎弹窗:', hasWelcomed);
|
||||||
|
|
||||||
|
if (!hasWelcomed && extensionContext) {
|
||||||
|
await extensionContext.globalState.update('showWelcomeModal', true);
|
||||||
|
await extensionContext.globalState.update('pluginTrialWelcomed', true);
|
||||||
|
console.log('[UserService] ✅ 已设置欢迎弹窗标记 showWelcomeModal=true');
|
||||||
|
|
||||||
|
const checkMark = extensionContext.globalState.get('showWelcomeModal');
|
||||||
|
console.log('[UserService] 验证标记:', checkMark);
|
||||||
|
} else if (!extensionContext) {
|
||||||
|
console.error('[UserService] ❌ extensionContext 为 null,无法设置标记');
|
||||||
|
} else {
|
||||||
|
console.log('[UserService] 已经显示过欢迎弹窗,跳过');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 正式用户:显示邀请码弹窗(现有逻辑)
|
// isPluginTrial=false 或 enterpriseTrialExpires 为 null:显示邀请码弹窗
|
||||||
console.log('[UserService] 正式用户登录,将在面板中检查邀请码');
|
console.log('[UserService] 非试用用户或无过期时间,将显示邀请码弹窗');
|
||||||
}
|
}
|
||||||
|
|
||||||
return userInfo;
|
return userInfo;
|
||||||
|
|||||||
@ -194,11 +194,17 @@ export interface PlanSummaryUpdateEvent {
|
|||||||
timestamp: number;
|
timestamp: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 单个问题项 */
|
||||||
|
export interface QuestionItem {
|
||||||
|
question: string;
|
||||||
|
options: string[];
|
||||||
|
multiSelect?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/** ask_user 事件数据 */
|
/** ask_user 事件数据 */
|
||||||
export interface AskUserEvent {
|
export interface AskUserEvent {
|
||||||
askId: string;
|
askId: string;
|
||||||
question: string;
|
questions: QuestionItem[];
|
||||||
options: string[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** complete 事件数据 */
|
/** complete 事件数据 */
|
||||||
@ -351,10 +357,12 @@ export interface AnswerRequest {
|
|||||||
askId: string;
|
askId: string;
|
||||||
/** 任务ID */
|
/** 任务ID */
|
||||||
taskId: string;
|
taskId: string;
|
||||||
/** 选中的选项列表 */
|
/** 选中的选项列表(旧格式,兼容) */
|
||||||
selected?: string[];
|
selected?: string[];
|
||||||
/** 自定义输入内容 */
|
/** 自定义输入内容(旧格式,兼容) */
|
||||||
customInput?: string;
|
customInput?: string;
|
||||||
|
/** 新格式:按问题索引的答案 */
|
||||||
|
answers?: { [questionIndex: string]: string[] };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 用户回答响应 */
|
/** 用户回答响应 */
|
||||||
|
|||||||
@ -92,7 +92,9 @@ export async function handleUserMessage(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (action === '立即登录') {
|
if (action === '立即登录') {
|
||||||
vscode.commands.executeCommand("ic-coder.login");
|
vscode.commands.executeCommand("ic-coder.login", {
|
||||||
|
forceReauth: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 恢复输入状态
|
// 恢复输入状态
|
||||||
@ -126,7 +128,9 @@ export async function handleUserMessage(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (action === '立即登录') {
|
if (action === '立即登录') {
|
||||||
vscode.commands.executeCommand("ic-coder.login");
|
vscode.commands.executeCommand("ic-coder.login", {
|
||||||
|
forceReauth: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 恢复输入状态
|
// 恢复输入状态
|
||||||
@ -320,7 +324,7 @@ async function handleUserMessageWithBackend(
|
|||||||
// 工具错误,不需要单独处理,通过 onSegmentUpdate 统一更新
|
// 工具错误,不需要单独处理,通过 onSegmentUpdate 统一更新
|
||||||
},
|
},
|
||||||
|
|
||||||
onQuestion: (askId, question, options) => {
|
onQuestion: (askId: string, questions: import("../types/api").QuestionItem[]) => {
|
||||||
// 只更新状态栏,问题显示由 onSegmentUpdate 统一处理
|
// 只更新状态栏,问题显示由 onSegmentUpdate 统一处理
|
||||||
panel.webview.postMessage({
|
panel.webview.postMessage({
|
||||||
command: "updateStatus",
|
command: "updateStatus",
|
||||||
@ -365,13 +369,12 @@ async function handleUserMessageWithBackend(
|
|||||||
command: "hideStatus",
|
command: "hideStatus",
|
||||||
});
|
});
|
||||||
|
|
||||||
// 最后一次发送完整的段落
|
// 发送完成标记(不再重复发送 segments,避免内容重复显示)
|
||||||
const result = await panel.webview.postMessage({
|
panel.webview.postMessage({
|
||||||
command: "updateSegments",
|
command: "updateSegments",
|
||||||
segments: segments,
|
segments: [],
|
||||||
isComplete: true,
|
isComplete: true,
|
||||||
});
|
});
|
||||||
console.log("[MessageHandler] postMessage 返回值:", result);
|
|
||||||
|
|
||||||
// 发送系统通知 - AI 响应完成
|
// 发送系统通知 - AI 响应完成
|
||||||
const notificationService = NotificationService.getInstance();
|
const notificationService = NotificationService.getInstance();
|
||||||
@ -466,10 +469,11 @@ async function handleUserMessageWithBackend(
|
|||||||
export async function handleUserAnswer(
|
export async function handleUserAnswer(
|
||||||
askId: string,
|
askId: string,
|
||||||
selected?: string[],
|
selected?: string[],
|
||||||
customInput?: string
|
customInput?: string,
|
||||||
|
answers?: { [questionIndex: string]: string[] }
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (currentSession) {
|
if (currentSession) {
|
||||||
await currentSession.submitAnswer(askId, selected, customInput);
|
await currentSession.submitAnswer(askId, selected, customInput, answers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -92,7 +92,8 @@ export async function executeWaveformTrace(
|
|||||||
|
|
||||||
child.on('close', (code: number | null) => {
|
child.on('close', (code: number | null) => {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
resolve(stdout);
|
// 成功时返回 stdout,忽略 stderr 中的进度信息
|
||||||
|
resolve(stdout || stderr);
|
||||||
} else {
|
} else {
|
||||||
reject(new Error(
|
reject(new Error(
|
||||||
`waveform_trace 执行失败 (code=${code}):\n${stderr || stdout}`
|
`waveform_trace 执行失败 (code=${code}):\n${stderr || stdout}`
|
||||||
|
|||||||
@ -28,7 +28,7 @@ export function showICHelperPanel(context: vscode.ExtensionContext) {
|
|||||||
retainContextWhenHidden: true,
|
retainContextWhenHidden: true,
|
||||||
localResourceRoots: [
|
localResourceRoots: [
|
||||||
vscode.Uri.joinPath(context.extensionUri, "media"),
|
vscode.Uri.joinPath(context.extensionUri, "media"),
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets")
|
vscode.Uri.joinPath(context.extensionUri, "dist", "assets")
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -47,21 +47,21 @@ export function showICHelperPanel(context: vscode.ExtensionContext) {
|
|||||||
|
|
||||||
// 获取模型图标URI
|
// 获取模型图标URI
|
||||||
const autoIconUri = panel.webview.asWebviewUri(
|
const autoIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "Auto.png")
|
vscode.Uri.joinPath(context.extensionUri, "dist", "assets", "model", "Auto.png")
|
||||||
);
|
);
|
||||||
const liteIconUri = panel.webview.asWebviewUri(
|
const liteIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "lite.png")
|
vscode.Uri.joinPath(context.extensionUri, "dist", "assets", "model", "lite.png")
|
||||||
);
|
);
|
||||||
const syIconUri = panel.webview.asWebviewUri(
|
const syIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "Sy.png")
|
vscode.Uri.joinPath(context.extensionUri, "dist", "assets", "model", "Sy.png")
|
||||||
);
|
);
|
||||||
const maxIconUri = panel.webview.asWebviewUri(
|
const maxIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "Max.png")
|
vscode.Uri.joinPath(context.extensionUri, "dist", "assets", "model", "Max.png")
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取二维码图片URI
|
// 获取二维码图片URI
|
||||||
const qrCodeUri = panel.webview.asWebviewUri(
|
const qrCodeUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "QRCode", "wx.png")
|
vscode.Uri.joinPath(context.extensionUri, "dist", "assets", "QRCode", "wx.png")
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取Logo URI
|
// 获取Logo URI
|
||||||
@ -129,7 +129,8 @@ export function showICHelperPanel(context: vscode.ExtensionContext) {
|
|||||||
handleUserAnswer(
|
handleUserAnswer(
|
||||||
message.askId,
|
message.askId,
|
||||||
message.selected,
|
message.selected,
|
||||||
message.customInput
|
message.customInput,
|
||||||
|
message.answers
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
// 新增:中止对话
|
// 新增:中止对话
|
||||||
@ -256,7 +257,7 @@ export class ICViewProvider implements vscode.WebviewViewProvider {
|
|||||||
vscode.commands.executeCommand("ic-coder.login");
|
vscode.commands.executeCommand("ic-coder.login");
|
||||||
} else if (message.command === "logout") {
|
} else if (message.command === "logout") {
|
||||||
// 退出登录(前端已有确认对话框)
|
// 退出登录(前端已有确认对话框)
|
||||||
vscode.commands.executeCommand('iccoder.logout');
|
vscode.commands.executeCommand("ic-coder.logout");
|
||||||
} else if (message.command === "openICCoder") {
|
} else if (message.command === "openICCoder") {
|
||||||
// 打开 IC Coder 官网
|
// 打开 IC Coder 官网
|
||||||
vscode.env.openExternal(vscode.Uri.parse('https://www.iccoder.com'));
|
vscode.env.openExternal(vscode.Uri.parse('https://www.iccoder.com'));
|
||||||
@ -320,15 +321,15 @@ export class ICViewProvider implements vscode.WebviewViewProvider {
|
|||||||
width: 200px;
|
width: 200px;
|
||||||
padding: 8px 12px;
|
padding: 8px 12px;
|
||||||
margin: 4px 0;
|
margin: 4px 0;
|
||||||
background: var(--vscode-button-background);
|
background: #007ACC;
|
||||||
color: var(--vscode-button-foreground);
|
color: #ffffff;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.btn:hover {
|
.btn:hover {
|
||||||
background: var(--vscode-button-hoverBackground);
|
background: #005a9e;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@ -16,7 +16,7 @@ export function getContextButtonContent(): string {
|
|||||||
<span class="add-context-label">添加上下文</span>
|
<span class="add-context-label">添加上下文</span>
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
<span class="tooltiptext">添加文件、文件夹、图片或文档作为上下文</span>
|
<span class="tooltiptext">添加文件、文件夹作为上下文</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 上拉菜单 -->
|
<!-- 上拉菜单 -->
|
||||||
@ -271,6 +271,7 @@ export function getContextButtonStyles(): string {
|
|||||||
width: 14px;
|
width: 14px;
|
||||||
height: 14px;
|
height: 14px;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.context-menu-list-item label {
|
.context-menu-list-item label {
|
||||||
@ -335,6 +336,7 @@ export function getContextButtonScript(): string {
|
|||||||
return `
|
return `
|
||||||
// 上下文菜单状态
|
// 上下文菜单状态
|
||||||
let currentListData = [];
|
let currentListData = [];
|
||||||
|
let filteredListData = [];
|
||||||
let currentListType = '';
|
let currentListType = '';
|
||||||
let selectedItems = new Set();
|
let selectedItems = new Set();
|
||||||
|
|
||||||
@ -392,6 +394,15 @@ export function getContextButtonScript(): string {
|
|||||||
|
|
||||||
selectedItems.clear();
|
selectedItems.clear();
|
||||||
currentListData = [];
|
currentListData = [];
|
||||||
|
filteredListData = [];
|
||||||
|
clearContextSearchInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearContextSearchInput() {
|
||||||
|
const searchInput = document.getElementById('contextMenuSearch');
|
||||||
|
if (searchInput) {
|
||||||
|
searchInput.value = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切换到列表视图
|
// 切换到列表视图
|
||||||
@ -406,10 +417,12 @@ export function getContextButtonScript(): string {
|
|||||||
titleEl.textContent = title;
|
titleEl.textContent = title;
|
||||||
|
|
||||||
currentListType = type;
|
currentListType = type;
|
||||||
currentListData = data;
|
currentListData = data || [];
|
||||||
|
filteredListData = currentListData;
|
||||||
selectedItems.clear();
|
selectedItems.clear();
|
||||||
|
|
||||||
renderList(data);
|
clearContextSearchInput();
|
||||||
|
renderList(filteredListData);
|
||||||
updateSelectedCount();
|
updateSelectedCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -419,32 +432,36 @@ export function getContextButtonScript(): string {
|
|||||||
const body = document.getElementById('contextMenuListBody');
|
const body = document.getElementById('contextMenuListBody');
|
||||||
if (!body) return;
|
if (!body) return;
|
||||||
|
|
||||||
body.innerHTML = data.map((item, index) => \`
|
filteredListData = data || [];
|
||||||
<div class="context-menu-list-item" onclick="toggleItemSelection(\${index})">
|
|
||||||
<input type="checkbox" id="item-\${index}" />
|
body.innerHTML = filteredListData.map((item, index) => \`
|
||||||
<label for="item-\${index}">\${item.relativePath}</label>
|
<div class="context-menu-list-item \${selectedItems.has(item.path) ? 'selected' : ''}" onclick="toggleItemSelection(\${index})">
|
||||||
|
<input type="checkbox" id="item-\${index}" \${selectedItems.has(item.path) ? 'checked' : ''} />
|
||||||
|
<label>\${item.relativePath || item.path}</label>
|
||||||
</div>
|
</div>
|
||||||
\`).join('');
|
\`).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切换项选择
|
// 切换项选择
|
||||||
function toggleItemSelection(index) {
|
function toggleItemSelection(index) {
|
||||||
|
const selectedItem = filteredListData[index];
|
||||||
|
if (!selectedItem) return;
|
||||||
|
|
||||||
|
const selectedPath = selectedItem.path;
|
||||||
const checkbox = document.getElementById('item-' + index);
|
const checkbox = document.getElementById('item-' + index);
|
||||||
const item = document.querySelectorAll('.context-menu-list-item')[index];
|
const item = document.querySelectorAll('.context-menu-list-item')[index];
|
||||||
|
|
||||||
if (checkbox && item) {
|
if (selectedItems.has(selectedPath)) {
|
||||||
checkbox.checked = !checkbox.checked;
|
selectedItems.delete(selectedPath);
|
||||||
|
if (checkbox) checkbox.checked = false;
|
||||||
if (checkbox.checked) {
|
if (item) item.classList.remove('selected');
|
||||||
selectedItems.add(index);
|
} else {
|
||||||
item.classList.add('selected');
|
selectedItems.add(selectedPath);
|
||||||
} else {
|
if (checkbox) checkbox.checked = true;
|
||||||
selectedItems.delete(index);
|
if (item) item.classList.add('selected');
|
||||||
item.classList.remove('selected');
|
|
||||||
}
|
|
||||||
|
|
||||||
updateSelectedCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSelectedCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新选中数量
|
// 更新选中数量
|
||||||
@ -457,15 +474,25 @@ export function getContextButtonScript(): string {
|
|||||||
|
|
||||||
// 确认选择
|
// 确认选择
|
||||||
function confirmSelection() {
|
function confirmSelection() {
|
||||||
const selected = Array.from(selectedItems).map(index => currentListData[index]);
|
try {
|
||||||
|
const selected = currentListData.filter(item => selectedItems.has(item.path));
|
||||||
|
|
||||||
if (selected.length > 0) {
|
if (selected.length > 0) {
|
||||||
selected.forEach(item => {
|
selected.forEach(item => {
|
||||||
addContextItem(currentListType, item.path);
|
addContextItem(currentListType, item.path, item.relativePath || item.path);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
const menu = document.getElementById('contextMenu');
|
||||||
|
const button = document.querySelector('.add-context-button');
|
||||||
|
if (menu) {
|
||||||
|
menu.classList.remove('show');
|
||||||
|
}
|
||||||
|
if (button) {
|
||||||
|
button.classList.remove('active');
|
||||||
|
}
|
||||||
|
backToMainMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleContextMenu();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加图片
|
// 添加图片
|
||||||
@ -484,9 +511,9 @@ export function getContextButtonScript(): string {
|
|||||||
const searchInput = document.getElementById('contextMenuSearch');
|
const searchInput = document.getElementById('contextMenuSearch');
|
||||||
if (searchInput) {
|
if (searchInput) {
|
||||||
searchInput.addEventListener('input', function(e) {
|
searchInput.addEventListener('input', function(e) {
|
||||||
const keyword = e.target.value.toLowerCase();
|
const keyword = (e.target.value || '').toLowerCase().trim();
|
||||||
const filtered = currentListData.filter(item =>
|
const filtered = currentListData.filter(item =>
|
||||||
item.relativePath.toLowerCase().includes(keyword)
|
(item.relativePath || item.path || '').toLowerCase().includes(keyword)
|
||||||
);
|
);
|
||||||
renderList(filtered);
|
renderList(filtered);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -137,9 +137,12 @@ export function getContextDisplayScript(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 添加上下文项
|
// 添加上下文项
|
||||||
function addContextItem(type, path) {
|
function addContextItem(type, path, displayPath) {
|
||||||
|
const exists = contextItems.some(item => item.type === type && item.path === path);
|
||||||
|
if (exists) return;
|
||||||
|
|
||||||
const id = Date.now() + Math.random();
|
const id = Date.now() + Math.random();
|
||||||
contextItems.push({ id, type, path });
|
contextItems.push({ id, type, path, displayPath: displayPath || '' });
|
||||||
renderContextItems();
|
renderContextItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +177,7 @@ export function getContextDisplayScript(): string {
|
|||||||
return \`
|
return \`
|
||||||
<div class="context-item" title="\${item.path}">
|
<div class="context-item" title="\${item.path}">
|
||||||
\${icon}
|
\${icon}
|
||||||
<span class="context-item-name">\${getFileName(item.path)}</span>
|
<span class="context-item-name">\${item.displayPath || getFileName(item.path)}</span>
|
||||||
<span class="context-item-remove" onclick="removeContextItem(\${item.id})">
|
<span class="context-item-remove" onclick="removeContextItem(\${item.id})">
|
||||||
\${getRemoveIcon()}
|
\${getRemoveIcon()}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@ -330,7 +330,7 @@ export function getConversationHistoryBarStyles(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.new-conversation-button:hover {
|
.new-conversation-button:hover {
|
||||||
background: var(--vscode-toolbar-hoverBackground);
|
background: #007ACC;
|
||||||
transform: scale(1.1);
|
transform: scale(1.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
62
src/views/filePathTag.ts
Normal file
62
src/views/filePathTag.ts
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/**
|
||||||
|
* 文件路径标签组件
|
||||||
|
* 功能:显示可点击的文件路径标签
|
||||||
|
* 使用场景:在用户消息中显示上下文文件
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件路径标签的样式
|
||||||
|
*/
|
||||||
|
export function getFilePathTagStyles(): string {
|
||||||
|
return `
|
||||||
|
/* 文件路径标签 */
|
||||||
|
.file-path-tag {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
padding: 2px 8px;
|
||||||
|
margin-right: 6px;
|
||||||
|
background: rgba(0, 122, 204, 0.15);
|
||||||
|
border: 1px solid rgba(0, 122, 204, 0.3);
|
||||||
|
border-radius: 4px;
|
||||||
|
color: #4fc3f7;
|
||||||
|
font-size: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
font-family: 'Consolas', 'Monaco', monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-path-tag:hover {
|
||||||
|
background: rgba(0, 122, 204, 0.25);
|
||||||
|
border-color: rgba(0, 122, 204, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-path-tag svg {
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件路径标签的脚本
|
||||||
|
*/
|
||||||
|
export function getFilePathTagScript(): string {
|
||||||
|
return `
|
||||||
|
// 处理文件路径标签点击
|
||||||
|
function handleFilePathClick(filePath) {
|
||||||
|
vscode.postMessage({
|
||||||
|
command: 'openFile',
|
||||||
|
filePath: filePath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建文件路径标签
|
||||||
|
window.createFilePathTag = function(filePath) {
|
||||||
|
const fileIcon = '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg"><path d="M854.6 288.6L639.4 73.4c-6-6-14.1-9.4-22.6-9.4H192c-17.7 0-32 14.3-32 32v832c0 17.7 14.3 32 32 32h640c17.7 0 32-14.3 32-32V311.3c0-8.5-3.4-16.7-9.4-22.7z" fill="currentColor"/></svg>';
|
||||||
|
const escapedPath = filePath.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, "\\\\'");
|
||||||
|
return '<span class="file-path-tag" onclick="handleFilePathClick(\\'' + escapedPath + '\\')">' + fileIcon + filePath + '</span>';
|
||||||
|
};
|
||||||
|
`;
|
||||||
|
}
|
||||||
@ -24,6 +24,10 @@ import {
|
|||||||
getContextCompressStyles,
|
getContextCompressStyles,
|
||||||
getContextCompressScript,
|
getContextCompressScript,
|
||||||
} from "./contextCompress";
|
} from "./contextCompress";
|
||||||
|
import {
|
||||||
|
getFilePathTagStyles,
|
||||||
|
getFilePathTagScript,
|
||||||
|
} from "./filePathTag";
|
||||||
import {
|
import {
|
||||||
getOptimizeButtonContent,
|
getOptimizeButtonContent,
|
||||||
getOptimizeButtonStyles,
|
getOptimizeButtonStyles,
|
||||||
@ -98,6 +102,7 @@ export function getInputAreaStyles(): string {
|
|||||||
${getModelSelectorStyles()}
|
${getModelSelectorStyles()}
|
||||||
${getContextButtonStyles()}
|
${getContextButtonStyles()}
|
||||||
${getContextDisplayStyles()}
|
${getContextDisplayStyles()}
|
||||||
|
${getFilePathTagStyles()}
|
||||||
${getContextCompressStyles()}
|
${getContextCompressStyles()}
|
||||||
${getOptimizeButtonStyles()}
|
${getOptimizeButtonStyles()}
|
||||||
${getExampleShowcaseStyles()}
|
${getExampleShowcaseStyles()}
|
||||||
@ -309,6 +314,7 @@ export function getInputAreaScript(): string {
|
|||||||
${getContextCompressScript()}
|
${getContextCompressScript()}
|
||||||
${getOptimizeButtonScript()}
|
${getOptimizeButtonScript()}
|
||||||
${getChangePanelScript()}
|
${getChangePanelScript()}
|
||||||
|
${getFilePathTagScript()}
|
||||||
|
|
||||||
// 对话状态管理
|
// 对话状态管理
|
||||||
let isConversationActive = false;
|
let isConversationActive = false;
|
||||||
@ -426,7 +432,22 @@ export function getInputAreaScript(): string {
|
|||||||
// 获取上下文项
|
// 获取上下文项
|
||||||
const contextItems = window.getContextItems ? window.getContextItems() : [];
|
const contextItems = window.getContextItems ? window.getContextItems() : [];
|
||||||
|
|
||||||
addMessage(text, 'user');
|
// 构建显示消息:如果有上下文文件,添加文件路径前缀
|
||||||
|
let displayText = text;
|
||||||
|
if (contextItems.length > 0) {
|
||||||
|
const filePaths = contextItems
|
||||||
|
.filter(item => item.type === 'file')
|
||||||
|
.map(item => item.displayPath || item.path)
|
||||||
|
.join(' ');
|
||||||
|
if (filePaths) {
|
||||||
|
displayText = filePaths + ' ' + text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addMessage(displayText, 'user');
|
||||||
|
|
||||||
|
// 重置分段消息容器,强制下次创建新容器
|
||||||
|
currentSegmentedMessage = null;
|
||||||
|
|
||||||
// 标记已有消息,切换布局到底部
|
// 标记已有消息,切换布局到底部
|
||||||
hasMessages = true;
|
hasMessages = true;
|
||||||
|
|||||||
@ -248,19 +248,21 @@ export function getMessageAreaStyles(): string {
|
|||||||
}
|
}
|
||||||
.question-option {
|
.question-option {
|
||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
background: var(--vscode-button-secondaryBackground);
|
background: #007ACC;
|
||||||
color: var(--vscode-button-secondaryForeground);
|
color: #ffffff;
|
||||||
border: 1px solid var(--vscode-button-border);
|
border: 1px solid #007ACC;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
}
|
}
|
||||||
.question-option:hover {
|
.question-option:hover {
|
||||||
background: var(--vscode-button-secondaryHoverBackground);
|
background: #005a9e;
|
||||||
|
border-color: #005a9e;
|
||||||
}
|
}
|
||||||
.question-option.selected {
|
.question-option.selected {
|
||||||
background: var(--vscode-button-background);
|
background: #007ACC;
|
||||||
color: var(--vscode-button-foreground);
|
color: #ffffff;
|
||||||
|
border-color: #007ACC;
|
||||||
}
|
}
|
||||||
.question-message.answered .question-option:not(.selected) {
|
.question-message.answered .question-option:not(.selected) {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
@ -420,6 +422,9 @@ export function getMessageAreaStyles(): string {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
.icon-expanded svg path {
|
||||||
|
fill: #007ACC !important;
|
||||||
|
}
|
||||||
.tool-segment-header.collapsed .tool-collapse-icon {
|
.tool-segment-header.collapsed .tool-collapse-icon {
|
||||||
transform: rotate(-90deg);
|
transform: rotate(-90deg);
|
||||||
}
|
}
|
||||||
@ -546,7 +551,7 @@ export function getMessageAreaStyles(): string {
|
|||||||
.tool-segment-description {
|
.tool-segment-description {
|
||||||
margin: 6px 0 0 0px;
|
margin: 6px 0 0 0px;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
color: #ccc;
|
color: var(--vscode-descriptionForeground);
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
}
|
}
|
||||||
/* 低调显示的工具调用样式 */
|
/* 低调显示的工具调用样式 */
|
||||||
@ -585,20 +590,22 @@ export function getMessageAreaStyles(): string {
|
|||||||
}
|
}
|
||||||
.segment-question .question-option {
|
.segment-question .question-option {
|
||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
background: var(--vscode-button-secondaryBackground);
|
background: #007ACC;
|
||||||
color: var(--vscode-button-secondaryForeground);
|
color: #ffffff;
|
||||||
border: 1px solid var(--vscode-button-border);
|
border: 1px solid #007ACC;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
.segment-question .question-option:hover {
|
.segment-question .question-option:hover {
|
||||||
background: var(--vscode-button-secondaryHoverBackground);
|
background: #005a9e;
|
||||||
|
border-color: #005a9e;
|
||||||
}
|
}
|
||||||
.segment-question .question-option.selected {
|
.segment-question .question-option.selected {
|
||||||
background: var(--vscode-button-background);
|
background: #007ACC;
|
||||||
color: var(--vscode-button-foreground);
|
color: #ffffff;
|
||||||
|
border-color: #007ACC;
|
||||||
}
|
}
|
||||||
.segment-question.answered .question-option:not(.selected) {
|
.segment-question.answered .question-option:not(.selected) {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
@ -850,7 +857,26 @@ export function getMessageAreaScript(): string {
|
|||||||
|
|
||||||
div.appendChild(actionsDiv);
|
div.appendChild(actionsDiv);
|
||||||
} else {
|
} else {
|
||||||
div.textContent = text;
|
// 用户消息:解析文件路径并转换为标签
|
||||||
|
const parts = text.split(' ');
|
||||||
|
const filePaths = [];
|
||||||
|
const textParts = [];
|
||||||
|
|
||||||
|
parts.forEach(part => {
|
||||||
|
// 判断是否为文件路径:包含路径分隔符或文件扩展名
|
||||||
|
if (part.includes('/') || part.includes('\\\\') || /\\.[a-zA-Z0-9]+$/.test(part)) {
|
||||||
|
filePaths.push(part);
|
||||||
|
} else {
|
||||||
|
textParts.push(part);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filePaths.length > 0) {
|
||||||
|
div.innerHTML = filePaths.map(fp => window.createFilePathTag ? window.createFilePathTag(fp) : fp).join('') + ' ' + textParts.join(' ');
|
||||||
|
} else {
|
||||||
|
div.textContent = text;
|
||||||
|
}
|
||||||
|
|
||||||
// 当添加用户消息时,隐藏 header
|
// 当添加用户消息时,隐藏 header
|
||||||
hideHeaderIfNeeded();
|
hideHeaderIfNeeded();
|
||||||
}
|
}
|
||||||
@ -988,34 +1014,42 @@ export function getMessageAreaScript(): string {
|
|||||||
|
|
||||||
// 实时更新分段消息(按后端返回顺序)
|
// 实时更新分段消息(按后端返回顺序)
|
||||||
function updateSegmentsRealtime(segments, isComplete) {
|
function updateSegmentsRealtime(segments, isComplete) {
|
||||||
console.log('[WebView] updateSegmentsRealtime 被调用, segments:', segments, 'isComplete:', isComplete);
|
// 如果对话完成且没有新段落,只重置容器
|
||||||
|
if (isComplete && (!segments || segments.length === 0)) {
|
||||||
|
currentSegmentedMessage = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!segments || segments.length === 0) {
|
if (!segments || segments.length === 0) {
|
||||||
console.log('[WebView] segments 为空,跳过渲染');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果没有当前分段消息容器,创建一个
|
// 如果没有当前分段消息容器,创建一个
|
||||||
if (!currentSegmentedMessage) {
|
if (!currentSegmentedMessage) {
|
||||||
console.log('[WebView] 创建新的分段消息容器');
|
|
||||||
// 移除流式消息(如果有)
|
// 移除流式消息(如果有)
|
||||||
if (currentStreamingMessage) {
|
if (currentStreamingMessage) {
|
||||||
console.log('[WebView] 移除流式消息');
|
|
||||||
currentStreamingMessage.remove();
|
currentStreamingMessage.remove();
|
||||||
currentStreamingMessage = null;
|
currentStreamingMessage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移除所有工具状态消息(因为会在分段中显示)
|
// 移除所有工具状态消息(因为会在分段中显示)
|
||||||
const toolStatuses = messagesEl.querySelectorAll('.tool-status');
|
const toolStatuses = messagesEl.querySelectorAll('.tool-status');
|
||||||
console.log('[WebView] 找到工具状态消息数量:', toolStatuses.length);
|
|
||||||
toolStatuses.forEach(el => {
|
toolStatuses.forEach(el => {
|
||||||
console.log('[WebView] 移除工具状态消息:', el.className);
|
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
currentSegmentedMessage = document.createElement('div');
|
// 检查最后一个容器是否是未完成的对话(没有操作按钮)
|
||||||
currentSegmentedMessage.className = 'message bot-message segmented-message';
|
const lastSegmented = messagesEl.querySelector('.segmented-message:last-child');
|
||||||
messagesEl.appendChild(currentSegmentedMessage);
|
if (lastSegmented && !lastSegmented.querySelector('.message-actions')) {
|
||||||
|
// 复用未完成的容器
|
||||||
|
currentSegmentedMessage = lastSegmented;
|
||||||
|
} else {
|
||||||
|
// 创建新容器
|
||||||
|
currentSegmentedMessage = document.createElement('div');
|
||||||
|
currentSegmentedMessage.className = 'message bot-message segmented-message';
|
||||||
|
messagesEl.appendChild(currentSegmentedMessage);
|
||||||
|
}
|
||||||
|
renderedSegmentCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存当前所有工具的展开/折叠状态
|
// 保存当前所有工具的展开/折叠状态
|
||||||
@ -1154,64 +1188,60 @@ export function getMessageAreaScript(): string {
|
|||||||
} else if (segment.type === 'question') {
|
} else if (segment.type === 'question') {
|
||||||
segmentDiv.className += ' segment-question';
|
segmentDiv.className += ' segment-question';
|
||||||
|
|
||||||
|
// 兼容旧格式:如果有 segment.question,转换为 questions 数组
|
||||||
|
const questions = segment.questions || (segment.question ? [{
|
||||||
|
question: segment.question,
|
||||||
|
options: segment.options || [],
|
||||||
|
multiSelect: false
|
||||||
|
}] : []);
|
||||||
|
|
||||||
// 检查是否已回答
|
// 检查是否已回答
|
||||||
const isAnswered = answeredQuestions.has(segment.askId);
|
const isAnswered = answeredQuestions.has(segment.askId);
|
||||||
const selectedAnswer = answeredQuestions.get(segment.askId);
|
const savedAnswers = answeredQuestions.get(segment.askId) || {};
|
||||||
|
|
||||||
if (isAnswered) {
|
if (isAnswered) {
|
||||||
segmentDiv.classList.add('answered');
|
segmentDiv.classList.add('answered');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否有选项
|
// 渲染多个问题
|
||||||
const hasOptions = segment.options && segment.options.length > 0;
|
const questionsHtml = questions.map((q, qIndex) => {
|
||||||
|
const inputType = q.multiSelect ? 'checkbox' : 'radio';
|
||||||
|
const inputName = \`q\${qIndex}\`;
|
||||||
|
const selectedAnswers = savedAnswers[qIndex] || [];
|
||||||
|
|
||||||
const optionsHtml = hasOptions
|
const optionsHtml = q.options.map(opt => {
|
||||||
? (segment.options || []).map(opt => {
|
const isSelected = selectedAnswers.includes(opt);
|
||||||
const isSelected = isAnswered && opt === selectedAnswer;
|
return \`<label style="display:flex;align-items:center;gap:6px;cursor:pointer;padding:4px 0;">
|
||||||
return \`<button class="question-option\${isSelected ? ' selected' : ''}" data-option="\${opt}">\${opt}</button>\`;
|
<input type="\${inputType}" name="\${inputName}" value="\${opt}" \${isSelected ? 'checked' : ''} \${isAnswered ? 'disabled' : ''}>
|
||||||
}).join('')
|
<span>\${opt}</span>
|
||||||
: '';
|
</label>\`;
|
||||||
|
}).join('');
|
||||||
|
|
||||||
|
return \`
|
||||||
|
<div class="question-item" data-question-index="\${qIndex}" style="margin-bottom:12px;">
|
||||||
|
<div class="question-text" style="margin-bottom:8px;">\${formatText(q.question)}</div>
|
||||||
|
<div class="question-options">\${optionsHtml}</div>
|
||||||
|
</div>
|
||||||
|
\`;
|
||||||
|
}).join('');
|
||||||
|
|
||||||
segmentDiv.innerHTML = \`
|
segmentDiv.innerHTML = \`
|
||||||
<div class="question-text">\${formatText(segment.question || '')}</div>
|
\${questionsHtml}
|
||||||
\${hasOptions ? \`<div class="question-options" data-ask-id="\${segment.askId}">\${optionsHtml}</div>\` : ''}
|
<button class="custom-submit" style="display:\${isAnswered ? 'none' : 'block'};margin-top:8px;padding:8px 16px;background:var(--vscode-button-background);color:var(--vscode-button-foreground);border:none;border-radius:6px;cursor:pointer;">提交答案</button>
|
||||||
<div class="custom-input-container" style="display: \${isAnswered ? 'none' : 'flex'};">
|
|
||||||
<input type="text" class="custom-input" placeholder="\${hasOptions ? '输入其他答案...' : '请输入您的答案...'}" />
|
|
||||||
<button class="custom-submit">提交</button>
|
|
||||||
</div>
|
|
||||||
\`;
|
\`;
|
||||||
|
|
||||||
// 只在未回答时添加事件监听
|
// 只在未回答时添加事件监听
|
||||||
if (!isAnswered) {
|
if (!isAnswered) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (hasOptions) {
|
|
||||||
const optionButtons = segmentDiv.querySelectorAll('.question-option');
|
|
||||||
optionButtons.forEach(btn => {
|
|
||||||
btn.addEventListener('click', function() {
|
|
||||||
const option = this.getAttribute('data-option');
|
|
||||||
handleQuestionAnswerInSegment(segment.askId, option, segmentDiv);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const submitBtn = segmentDiv.querySelector('.custom-submit');
|
const submitBtn = segmentDiv.querySelector('.custom-submit');
|
||||||
const customInput = segmentDiv.querySelector('.custom-input');
|
if (submitBtn) {
|
||||||
if (submitBtn && customInput) {
|
|
||||||
submitBtn.addEventListener('click', function() {
|
submitBtn.addEventListener('click', function() {
|
||||||
const customValue = customInput.value.trim();
|
const answers = {};
|
||||||
if (customValue) {
|
questions.forEach((q, qIndex) => {
|
||||||
handleQuestionAnswerInSegment(segment.askId, customValue, segmentDiv);
|
const inputs = segmentDiv.querySelectorAll(\`input[name="q\${qIndex}"]:checked\`);
|
||||||
}
|
answers[qIndex] = Array.from(inputs).map(input => input.value);
|
||||||
});
|
});
|
||||||
|
handleMultiQuestionAnswer(segment.askId, answers, segmentDiv);
|
||||||
// 支持回车提交
|
|
||||||
customInput.addEventListener('keypress', function(e) {
|
|
||||||
if (e.key === 'Enter') {
|
|
||||||
const customValue = customInput.value.trim();
|
|
||||||
if (customValue) {
|
|
||||||
handleQuestionAnswerInSegment(segment.askId, customValue, segmentDiv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
@ -1227,7 +1257,7 @@ export function getMessageAreaScript(): string {
|
|||||||
currentSegmentedMessage.appendChild(segmentDiv);
|
currentSegmentedMessage.appendChild(segmentDiv);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 如果对话完成,添加操作按钮
|
// 如果对话完成,添加操作按钮并重置容器
|
||||||
if (isComplete) {
|
if (isComplete) {
|
||||||
console.log('[WebView] 对话完成,添加操作按钮');
|
console.log('[WebView] 对话完成,添加操作按钮');
|
||||||
const actionsDiv = document.createElement('div');
|
const actionsDiv = document.createElement('div');
|
||||||
@ -1262,7 +1292,7 @@ export function getMessageAreaScript(): string {
|
|||||||
actionsDiv.appendChild(dislikeBtn);
|
actionsDiv.appendChild(dislikeBtn);
|
||||||
currentSegmentedMessage.appendChild(actionsDiv);
|
currentSegmentedMessage.appendChild(actionsDiv);
|
||||||
|
|
||||||
// 重置当前分段消息容器
|
// 重置当前分段消息容器(继续对话时创建新容器)
|
||||||
currentSegmentedMessage = null;
|
currentSegmentedMessage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1689,6 +1719,34 @@ export function getMessageAreaScript(): string {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理多问题答案提交
|
||||||
|
function handleMultiQuestionAnswer(askId, answers, segmentDiv) {
|
||||||
|
console.log('[WebView] 多问题答案提交:', askId, answers);
|
||||||
|
|
||||||
|
// 保存答案到 Map 中
|
||||||
|
answeredQuestions.set(askId, answers);
|
||||||
|
|
||||||
|
// 标记问题已回答
|
||||||
|
segmentDiv.classList.add('answered');
|
||||||
|
|
||||||
|
// 禁用所有输入
|
||||||
|
const inputs = segmentDiv.querySelectorAll('input');
|
||||||
|
inputs.forEach(input => input.disabled = true);
|
||||||
|
|
||||||
|
// 隐藏提交按钮
|
||||||
|
const submitBtn = segmentDiv.querySelector('.custom-submit');
|
||||||
|
if (submitBtn) {
|
||||||
|
submitBtn.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送答案到后端
|
||||||
|
vscode.postMessage({
|
||||||
|
command: 'submitAnswer',
|
||||||
|
askId: askId,
|
||||||
|
answers: answers
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
${getWaveformPreviewScript()}
|
${getWaveformPreviewScript()}
|
||||||
|
|
||||||
${getCodeHighlightScript()}
|
${getCodeHighlightScript()}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ export function getNdtWelcomeModalContent(logoUri?: string): string {
|
|||||||
|
|
||||||
<div class="ndt-welcome-modal-header">
|
<div class="ndt-welcome-modal-header">
|
||||||
<div class="ndt-welcome-icon">🎉</div>
|
<div class="ndt-welcome-icon">🎉</div>
|
||||||
<h2>欢迎宁德时代新能源科技股份有限公司<span style="white-space: nowrap;">的各位专家</span>使用 IC Coder!</h2>
|
<h2>欢迎企业<span style="white-space: nowrap;">的各位专家</span>使用 IC Coder!</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ndt-welcome-modal-body">
|
<div class="ndt-welcome-modal-body">
|
||||||
|
|||||||
@ -195,11 +195,11 @@ export function getPlanCardStyles(): string {
|
|||||||
background: var(--vscode-list-hoverBackground);
|
background: var(--vscode-list-hoverBackground);
|
||||||
}
|
}
|
||||||
.plan-btn-confirm {
|
.plan-btn-confirm {
|
||||||
background: var(--vscode-button-background);
|
background: #007ACC;
|
||||||
color: var(--vscode-button-foreground);
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
.plan-btn-confirm:hover {
|
.plan-btn-confirm:hover {
|
||||||
background: var(--vscode-button-hoverBackground);
|
background: #005a9e;
|
||||||
}
|
}
|
||||||
.plan-btn-cancel {
|
.plan-btn-cancel {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
|
|||||||
@ -186,8 +186,8 @@ export function getProgressBarStyles(): string {
|
|||||||
|
|
||||||
/* 已完成状态 */
|
/* 已完成状态 */
|
||||||
.progress-step.completed .step-circle {
|
.progress-step.completed .step-circle {
|
||||||
background: var(--vscode-button-background);
|
background: #007ACC;
|
||||||
border-color: var(--vscode-button-background);
|
border-color: #007ACC;
|
||||||
}
|
}
|
||||||
|
|
||||||
.progress-step.completed .step-number {
|
.progress-step.completed .step-number {
|
||||||
@ -204,14 +204,14 @@ export function getProgressBarStyles(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.progress-step.completed + .progress-line {
|
.progress-step.completed + .progress-line {
|
||||||
background: var(--vscode-button-background);
|
background: #007ACC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 进行中状态 */
|
/* 进行中状态 */
|
||||||
.progress-step.active .step-circle {
|
.progress-step.active .step-circle {
|
||||||
background: var(--vscode-button-background);
|
background: #007ACC;
|
||||||
border-color: var(--vscode-button-background);
|
border-color: #007ACC;
|
||||||
box-shadow: 0 0 0 2px var(--vscode-button-background)33;
|
box-shadow: 0 0 0 2px #007ACC33;
|
||||||
animation: pulse 2s infinite;
|
animation: pulse 2s infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,10 +226,10 @@ export function getProgressBarStyles(): string {
|
|||||||
|
|
||||||
@keyframes pulse {
|
@keyframes pulse {
|
||||||
0%, 100% {
|
0%, 100% {
|
||||||
box-shadow: 0 0 0 2px var(--vscode-button-background)33;
|
box-shadow: 0 0 0 2px #007ACC33;
|
||||||
}
|
}
|
||||||
50% {
|
50% {
|
||||||
box-shadow: 0 0 0 4px var(--vscode-button-background)1a;
|
box-shadow: 0 0 0 4px #007ACC1a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ export function getProgressBarScript(): string {
|
|||||||
// 更新连接线
|
// 更新连接线
|
||||||
document.querySelectorAll('.progress-line').forEach((line, index) => {
|
document.querySelectorAll('.progress-line').forEach((line, index) => {
|
||||||
if (index < currentIndex) {
|
if (index < currentIndex) {
|
||||||
line.style.background = 'var(--vscode-button-background)';
|
line.style.background = '#007ACC';
|
||||||
} else {
|
} else {
|
||||||
line.style.background = 'var(--vscode-input-border)';
|
line.style.background = 'var(--vscode-input-border)';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,40 +19,41 @@ export function getWelcomeModalContent(logoUri?: string): string {
|
|||||||
<div class="welcome-modal-header">
|
<div class="welcome-modal-header">
|
||||||
<div class="welcome-icon">🎉</div>
|
<div class="welcome-icon">🎉</div>
|
||||||
<h2>欢迎使用 IC Coder!</h2>
|
<h2>欢迎使用 IC Coder!</h2>
|
||||||
<p class="welcome-modal-subtitle">您已成功激活 15 天试用期,让我们开始探索 IC Coder 的强大功能吧!</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="welcome-modal-body">
|
<div class="welcome-modal-body">
|
||||||
<div class="welcome-step">
|
<!-- 试用期提示 -->
|
||||||
<div class="welcome-step-icon">📝</div>
|
<div class="trial-banner">
|
||||||
<div class="welcome-step-content">
|
<span>您已获得 <strong>5 天企业版试用期</strong>,企业版试用期内Credits用量无限,并可无限制使用所有功能</span>
|
||||||
<h3>步骤 1:打开聊天面板</h3>
|
</div>
|
||||||
<p>点击侧边栏的 IC Coder 图标,或使用命令面板搜索 "IC Coder: Open Chat"</p>
|
|
||||||
|
<!-- IC Coder 简介 -->
|
||||||
|
<div class="intro-section">
|
||||||
|
<h3 class="section-title">关于 IC Coder</h3>
|
||||||
|
<p class="intro-text">IC Coder是一款The Agentic AI Verilog Coding Platform(自主式人工智能 Verilog 编码平台)。我们采用全球顶尖的IC Coder自研芯片设计微调模型,为代码生成提供强大的AI能力支撑。</p>
|
||||||
|
|
||||||
|
<div class="features">
|
||||||
|
<div class="feature-item">
|
||||||
|
<span class="feature-text">多智能体架构(Multi-Agent System):多个专业化AI智能体协同工作,分别负责架构设计、代码生成、验证测试等不同环节</span>
|
||||||
|
</div>
|
||||||
|
<div class="feature-item">
|
||||||
|
<span class="feature-text">增强上下文引擎:智能理解和管理大规模设计上下文,确保生成代码的一致性和准确性</span>
|
||||||
|
</div>
|
||||||
|
<div class="feature-item">
|
||||||
|
<span class="feature-text">AI自主仿真:IC Coder提供完全自动化的仿真验证流程,无需手动编写测试代码</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="welcome-step">
|
<!-- 按钮组 -->
|
||||||
<div class="welcome-step-icon">💬</div>
|
<div class="button-group">
|
||||||
<div class="welcome-step-content">
|
<button id="welcomeStartBtn" class="welcome-btn welcome-btn-primary">
|
||||||
<h3>步骤 2:输入您的需求</h3>
|
<span>开始使用</span>
|
||||||
<p>描述您想要生成的 Verilog 代码或需要帮助的问题,AI 将为您提供专业的解决方案</p>
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
|
||||||
</div>
|
<path d="M6 3L11 8L6 13" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="welcome-step">
|
|
||||||
<div class="welcome-step-icon">🔬</div>
|
|
||||||
<div class="welcome-step-content">
|
|
||||||
<h3>步骤 3:运行仿真</h3>
|
|
||||||
<p>使用 "生成 VCD" 命令运行 iverilog 仿真,并通过波形查看器查看仿真结果</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button id="welcomeStartBtn" class="welcome-btn welcome-btn-primary">
|
|
||||||
<span>开始使用</span>
|
|
||||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
|
|
||||||
<path d="M6 3L11 8L6 13" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -96,7 +97,7 @@ export function getWelcomeModalStyles(): string {
|
|||||||
border: 1px solid var(--vscode-widget-border);
|
border: 1px solid var(--vscode-widget-border);
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 500px;
|
max-width: 480px;
|
||||||
box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
|
box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
|
||||||
animation: modalSlideIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
|
animation: modalSlideIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@ -124,9 +125,10 @@ export function getWelcomeModalStyles(): string {
|
|||||||
|
|
||||||
.welcome-modal-header h2 {
|
.welcome-modal-header h2 {
|
||||||
margin: 0 0 12px;
|
margin: 0 0 12px;
|
||||||
font-size: 24px;
|
font-size: 20px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: var(--vscode-foreground);
|
color: var(--vscode-foreground);
|
||||||
|
line-height: 1.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome-modal-subtitle {
|
.welcome-modal-subtitle {
|
||||||
@ -140,37 +142,70 @@ export function getWelcomeModalStyles(): string {
|
|||||||
padding: 0 32px 32px;
|
padding: 0 32px 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome-step {
|
/* 试用期横幅 */
|
||||||
|
.trial-banner {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 16px;
|
align-items: center;
|
||||||
margin: 20px 0;
|
justify-content: center;
|
||||||
padding: 16px;
|
padding: 12px 16px;
|
||||||
background: var(--vscode-editor-inactiveSelectionBackground);
|
background: var(--vscode-editor-inactiveSelectionBackground);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
border-left: 4px solid var(--vscode-textLink-foreground);
|
margin-bottom: 20px;
|
||||||
}
|
|
||||||
|
|
||||||
.welcome-step-icon {
|
|
||||||
font-size: 24px;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.welcome-step-content h3 {
|
|
||||||
margin: 0 0 8px;
|
|
||||||
font-size: 15px;
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--vscode-textLink-foreground);
|
|
||||||
}
|
|
||||||
|
|
||||||
.welcome-step-content p {
|
|
||||||
margin: 0;
|
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: var(--vscode-descriptionForeground);
|
color: var(--vscode-descriptionForeground);
|
||||||
line-height: 1.5;
|
border-left: 3px solid var(--vscode-textLink-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
.trial-banner strong {
|
||||||
|
color: var(--vscode-textLink-foreground);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* IC Coder 简介区域 */
|
||||||
|
.intro-section {
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
margin: 0 0 12px;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--vscode-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
.intro-text {
|
||||||
|
margin: 0 0 16px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--vscode-descriptionForeground);
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.features {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.feature-item {
|
||||||
|
padding: 10px 12px;
|
||||||
|
background: var(--vscode-editor-inactiveSelectionBackground);
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--vscode-foreground);
|
||||||
|
border-left: 2px solid var(--vscode-textLink-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
.feature-text {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 按钮组 */
|
||||||
|
.button-group {
|
||||||
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome-btn {
|
.welcome-btn {
|
||||||
width: 100%;
|
flex: 1;
|
||||||
padding: 12px 16px;
|
padding: 12px 16px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
@ -181,18 +216,32 @@ export function getWelcomeModalStyles(): string {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
background: var(--vscode-button-background);
|
|
||||||
color: var(--vscode-button-foreground);
|
|
||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
margin-top: 24px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome-btn:hover {
|
.welcome-btn-primary {
|
||||||
|
background: var(--vscode-button-background);
|
||||||
|
color: var(--vscode-button-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
.welcome-btn-primary:hover {
|
||||||
background: var(--vscode-button-hoverBackground);
|
background: var(--vscode-button-hoverBackground);
|
||||||
transform: translateY(-1px);
|
transform: translateY(-1px);
|
||||||
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
|
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.welcome-btn-secondary {
|
||||||
|
background: var(--vscode-button-secondaryBackground);
|
||||||
|
color: var(--vscode-button-secondaryForeground);
|
||||||
|
border: 1px solid var(--vscode-button-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.welcome-btn-secondary:hover {
|
||||||
|
background: var(--vscode-button-secondaryHoverBackground);
|
||||||
|
transform: translateY(-1px);
|
||||||
|
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
|
||||||
|
}
|
||||||
|
|
||||||
.welcome-btn:active {
|
.welcome-btn:active {
|
||||||
transform: translateY(0);
|
transform: translateY(0);
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
tools/waveform_trace/bin/waveform_trace.exe
Normal file
BIN
tools/waveform_trace/bin/waveform_trace.exe
Normal file
Binary file not shown.
@ -3,6 +3,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||||
|
|
||||||
//@ts-check
|
//@ts-check
|
||||||
/** @typedef {import('webpack').Configuration} WebpackConfig **/
|
/** @typedef {import('webpack').Configuration} WebpackConfig **/
|
||||||
@ -45,5 +46,12 @@ const extensionConfig = {
|
|||||||
infrastructureLogging: {
|
infrastructureLogging: {
|
||||||
level: "log", // enables logging required for problem matchers
|
level: "log", // enables logging required for problem matchers
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
new CopyWebpackPlugin({
|
||||||
|
patterns: [
|
||||||
|
{ from: 'src/assets', to: 'assets' }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
]
|
||||||
};
|
};
|
||||||
module.exports = [ extensionConfig ];
|
module.exports = [ extensionConfig ];
|
||||||
Reference in New Issue
Block a user