Skip to content

Commit 7bb1cf3

Browse files
committed
feat: 新增右键菜单
1 parent f8512a4 commit 7bb1cf3

File tree

2 files changed

+85
-6
lines changed

2 files changed

+85
-6
lines changed

package.json

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"onCommand:codeReDesign.uploadCvb",
1818
"onCommand:codeReDesign.applyCvb",
1919
"onCommand:codeReDesign.applyThisCvb",
20-
"onCommand:codeReDesign.analyzeCode"
20+
"onCommand:codeReDesign.analyzeCode",
21+
"onCommand:codeReDesign.uploadThisCvb",
22+
"onCommand:codeReDesign.analyzeThisCvb"
2123
],
2224
"repository": {
2325
"type": "git",
@@ -48,6 +50,14 @@
4850
{
4951
"command": "codeReDesign.analyzeCode",
5052
"title": "CodeReDesign: Analyze Code"
53+
},
54+
{
55+
"command": "codeReDesign.uploadThisCvb",
56+
"title": "CodeReDesign: Upload this CVB and Call API"
57+
},
58+
{
59+
"command": "codeReDesign.analyzeThisCvb",
60+
"title": "CodeReDesign: Analyze this CVB"
5161
}
5262
],
5363
"views": {
@@ -64,6 +74,16 @@
6474
"command": "codeReDesign.applyThisCvb",
6575
"when": "resourceExtname == .cvb",
6676
"group": "cvb@1"
77+
},
78+
{
79+
"command": "codeReDesign.uploadThisCvb",
80+
"when": "resourceExtname == .cvb",
81+
"group": "cvb@1"
82+
},
83+
{
84+
"command": "codeReDesign.analyzeThisCvb",
85+
"when": "resourceExtname == .cvb",
86+
"group": "cvb@1"
6787
}
6888
]
6989
},
@@ -136,4 +156,4 @@
136156
"jschardet": "^3.1.4",
137157
"openai": "^4.81.0"
138158
}
139-
}
159+
}

src/siderBar.ts

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as vscode from 'vscode';
22
import * as path from 'path';
33
import * as fs from 'fs';
4-
import {applyCvbToWorkspace} from './cvbManager';
4+
import { applyCvbToWorkspace } from './cvbManager';
5+
import { queryCodeReDesign, analyzeCode } from './deepseekApi';
56

67
export function registerCvbContextMenu(context: vscode.ExtensionContext) {
78

@@ -11,11 +12,23 @@ export function registerCvbContextMenu(context: vscode.ExtensionContext) {
1112
const filePath = uri.fsPath;
1213

1314
// 调用处理函数
14-
applyCvb(filePath);
15+
applyThisCvb(filePath);
16+
});
17+
18+
// 注册上传 CVB 命令
19+
const uploadCvbCommand = vscode.commands.registerCommand('codeReDesign.uploadThisCvb', async (uri: vscode.Uri) => {
20+
const filePath = uri.fsPath;
21+
await uploadThisCvb(filePath);
22+
});
23+
24+
// 注册分析 CVB 命令
25+
const analyzeCvbCommand = vscode.commands.registerCommand('codeReDesign.analyzeThisCvb', async (uri: vscode.Uri) => {
26+
const filePath = uri.fsPath;
27+
await analyzeThisCvb(filePath);
1528
});
1629

1730
// 将命令添加到订阅中
18-
context.subscriptions.push(applyCvbCommand);
31+
context.subscriptions.push(applyCvbCommand, uploadCvbCommand, analyzeCvbCommand);
1932

2033
// 注册 TreeDataProvider
2134
const cvbViewProvider = new CvbViewProvider();
@@ -122,7 +135,7 @@ class CvbFile extends vscode.TreeItem {
122135
* 处理 .cvb 文件的函数
123136
* @param filePath .cvb 文件的路径
124137
*/
125-
function applyCvb(filePath: string) {
138+
function applyThisCvb(filePath: string) {
126139
// 在这里实现你的逻辑
127140
vscode.window.showInformationMessage(`Applying CVB from: ${filePath}`);
128141
// 例如:读取文件内容并处理
@@ -135,4 +148,50 @@ function applyCvb(filePath: string) {
135148
}
136149
}
137150

151+
/**
152+
* 上传 CVB 文件并调用 API
153+
* @param filePath .cvb 文件的路径
154+
*/
155+
async function uploadThisCvb(filePath: string) {
156+
const userPrompt = await vscode.window.showInputBox({
157+
prompt: 'Enter your prompt for the refactoring',
158+
placeHolder: 'e.g., Refactor the code to improve readability',
159+
});
160+
161+
if (!userPrompt) {
162+
return;
163+
}
164+
165+
const cvbContent = fs.readFileSync(filePath, 'utf-8');
166+
const outputChannel = vscode.window.createOutputChannel('CodeReDesign API Stream');
167+
168+
const apiResponse = await queryCodeReDesign(cvbContent, userPrompt, outputChannel);
169+
if (apiResponse) {
170+
vscode.window.showInformationMessage('API response received. Check the output channel for details.');
171+
}
172+
}
173+
174+
/**
175+
* 分析 CVB 文件
176+
* @param filePath .cvb 文件的路径
177+
*/
178+
async function analyzeThisCvb(filePath: string) {
179+
const userRequest = await vscode.window.showInputBox({
180+
prompt: 'Enter your analysis request',
181+
placeHolder: 'e.g., Analyze the code for potential bugs',
182+
});
183+
184+
if (!userRequest) {
185+
return;
186+
}
187+
188+
const cvbContent = fs.readFileSync(filePath, 'utf-8');
189+
const outputChannel = vscode.window.createOutputChannel('CodeReDesign API Stream');
190+
191+
const analysisResult = await analyzeCode(cvbContent, userRequest, outputChannel);
192+
if (analysisResult) {
193+
vscode.window.showInformationMessage('Analysis completed. Check the output channel for details.');
194+
}
195+
}
196+
138197
export function deactivate() {}

0 commit comments

Comments
 (0)