Skip to content

Commit 1b243fc

Browse files
committed
调试代码
1 parent 1981fb2 commit 1b243fc

File tree

6 files changed

+254
-5
lines changed

6 files changed

+254
-5
lines changed
File renamed without changes.
File renamed without changes.

prompt/test.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
�½�һ������ҳ���ò������ť����
2+
��������Ļ�����ѧ
3+
�����ת����������
4+
����ŵ������ļ���

prompt/testdata.txt

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
## BEGIN_TCVB
2+
## FILE:k:\lab\CodeReDesign\src\guidePage.ts
3+
## OPERATION:CREATE
4+
```typescript
5+
import * as vscode from 'vscode';
6+
7+
export class GuidePage {
8+
private static readonly viewType = 'codeReDesign.guidePage';
9+
private static panel: vscode.WebviewPanel | undefined;
10+
11+
public static show(context: vscode.ExtensionContext) {
12+
if (this.panel) {
13+
this.panel.reveal(vscode.ViewColumn.One);
14+
return;
15+
}
16+
17+
this.panel = vscode.window.createWebviewPanel(
18+
this.viewType,
19+
'CodeReDesign Guide',
20+
vscode.ViewColumn.One,
21+
{
22+
enableScripts: true,
23+
retainContextWhenHidden: true
24+
}
25+
);
26+
27+
this.panel.webview.html = this.getWebviewContent();
28+
29+
this.panel.onDidDispose(() => {
30+
this.panel = undefined;
31+
}, null, context.subscriptions);
32+
}
33+
34+
private static getWebviewContent(): string {
35+
return
36+
<!DOCTYPE html>
37+
<html lang="en">
38+
<head>
39+
<meta charset="UTF-8">
40+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
41+
<title>CodeReDesign Guide</title>
42+
<style>
43+
body {
44+
font-family: Arial, sans-serif;
45+
padding: 20px;
46+
}
47+
h1 {
48+
color: #0078d7;
49+
}
50+
.command {
51+
margin: 10px 0;
52+
padding: 10px;
53+
border: 1px solid #ddd;
54+
border-radius: 4px;
55+
cursor: pointer;
56+
}
57+
.command:hover {
58+
background-color: #f5f5f5;
59+
}
60+
</style>
61+
</head>
62+
<body>
63+
<h1>Welcome to CodeReDesign</h1>
64+
<p>This guide will help you get started with the CodeReDesign extension.</p>
65+
66+
<h2>Quick Commands</h2>
67+
<div class="command" onclick="executeCommand('codeReDesign.generateCvb')">
68+
<strong>Generate CVB File</strong>
69+
<p>Package the code you want to refactor into CVB format.</p>
70+
</div>
71+
<div class="command" onclick="executeCommand('codeReDesign.uploadCvb')">
72+
<strong>Upload CVB File</strong>
73+
<p>Upload a CVB file and call the DeepSeek API for refactoring suggestions.</p>
74+
</div>
75+
<div class="command" onclick="executeCommand('codeReDesign.applyCvb')">
76+
<strong>Apply CVB File</strong>
77+
<p>Apply the changes from a CVB file to your workspace.</p>
78+
</div>
79+
<div class="command" onclick="executeCommand('codeReDesign.analyzeCode')">
80+
<strong>Analyze Code</strong>
81+
<p>Analyze your code with DeepSeek API.</p>
82+
</div>
83+
84+
<script>
85+
const vscode = acquireVsCodeApi();
86+
function executeCommand(command) {
87+
vscode.postMessage({
88+
command: 'execute',
89+
text: command
90+
});
91+
}
92+
</script>
93+
</body>
94+
</html>
95+
;
96+
}
97+
98+
public static register(context: vscode.ExtensionContext) {
99+
const showGuideCommand = vscode.commands.registerCommand('codeReDesign.showGuide', () => {
100+
GuidePage.show(context);
101+
});
102+
103+
context.subscriptions.push(showGuideCommand);
104+
105+
if (vscode.window.registerWebviewPanelSerializer) {
106+
vscode.window.registerWebviewPanelSerializer(GuidePage.viewType, {
107+
async deserializeWebviewPanel(webviewPanel: vscode.WebviewPanel, state: any) {
108+
GuidePage.panel = webviewPanel;
109+
webviewPanel.webview.html = GuidePage.getWebviewContent();
110+
}
111+
});
112+
}
113+
}
114+
}
115+
```
116+
## FILE:k:\lab\CodeReDesign\src\extension.ts
117+
## OPERATION:INSERT
118+
## BEFORE_ANCHOR
119+
```typescript
120+
import { registerCvbContextMenu } from './siderBar';
121+
```
122+
## AFTER_ANCHOR
123+
```typescript
124+
import { GuidePage } from './guidePage';
125+
```
126+
## INSERT_CONTENT
127+
```typescript
128+
import { GuidePage } from './guidePage';
129+
```
130+
## OPERATION:INSERT
131+
## BEFORE_ANCHOR
132+
```
133+
typescript
134+
// 注册右键菜单
135+
registerCvbContextMenu(context);
136+
```
137+
## AFTER_ANCHOR
138+
```typescript
139+
}
140+
```
141+
## INSERT_CONTENT
142+
```typescript
143+
// 注册引导页
144+
GuidePage.register(context);
145+
```
146+
## FILE:k:\lab\CodeReDesign\package.json
147+
## OPERATION:INSERT
148+
## BEFORE_ANCHOR
149+
```json
150+
{
151+
"command": "codeReDesign.analyzeThisCvb",
152+
"title": "CodeReDesign: Analyze this CVB"
153+
}
154+
```
155+
## AFTER_ANCHOR
156+
```json
157+
]
158+
},
159+
"views": {
160+
```
161+
## INSERT_CONTENT
162+
```json
163+
{
164+
"command": "codeReDesign.showGuide",
165+
"title": "CodeReDesign: Show Guide"
166+
}
167+
```
168+
## OPERATION:INSERT
169+
## BEFORE_ANCHOR
170+
```json
171+
{
172+
"command": "codeReDesign.analyzeThisCvb",
173+
"when": "resourceExtname == .cvb",
174+
"group": "cvb@1"
175+
}
176+
```
177+
## AFTER_ANCHOR
178+
```json
179+
],
180+
"commandPalette": [
181+
```
182+
## INSERT_CONTENT
183+
```json
184+
{
185+
"command": "codeReDesign.showGuide",
186+
"when": "view == codeReDesign.cvbView"
187+
}
188+
```
189+
## FILE:k:\lab\CodeReDesign\src\siderBar.ts
190+
## OPERATION:INSERT
191+
## BEFORE_ANCHOR
192+
```typescript
193+
// 设置图标(可选)
194+
this.iconPath = vscode.ThemeIcon.File;
195+
```
196+
## AFTER_ANCHOR
197+
```typescript
198+
this.resourceUri = uri;
199+
```
200+
## INSERT_CONTENT
201+
```typescript
202+
// 添加引导按钮
203+
if (label === 'Guide') {
204+
this.iconPath = new vscode.ThemeIcon('book');
205+
this.command = {
206+
command: 'codeReDesign.showGuide',
207+
title: 'Show Guide',
208+
arguments: []
209+
};
210+
}
211+
```
212+
## OPERATION:INSERT
213+
## BEFORE_ANCHOR
214+
```typescript
215+
// 新增排序逻辑
216+
cvbFiles.sort((a, b) =>
217+
a.label.localeCompare(b.label, undefined, { sensitivity: 'base' })
218+
);
219+
```
220+
## AFTER_ANCHOR
221+
```typescript
222+
return cvbFiles;
223+
```
224+
## INSERT_CONTENT
225+
```typescript
226+
// 添加引导按钮
227+
cvbFiles.unshift(new CvbFile('Guide', vscode.Uri.parse('codeReDesign:guide')));
228+
```
229+
## END_TCVB

src/cvbManager.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,13 @@ export class TCVB
276276
const strFilePath: string = filePathNormalize(arrFileMatch[1]);
277277
const strOperationsBlock: string = arrFileMatch[2];
278278
// 支持操作类型中含有 "-" 符号(如 single-replace 等)
279-
const regOperation: RegExp = /^## OPERATION:([\w-]+)(?:\s+FILE:(.*?))?\n([\s\S]*?)(?=^## OPERATION:|^## FILE:|^## END_TCVB)/gm;
279+
const regOperation: RegExp = /^## OPERATION:([\w-]+)\n([\s\S]*?)(?=^## OPERATION:)/gm;
280280
let arrOpMatch: RegExpExecArray | null;
281281
while ((arrOpMatch = regOperation.exec(strOperationsBlock)) !== null)
282282
{
283283
const strType: string = arrOpMatch[1].toLowerCase();
284-
const strExplicitFilePath: string | null = arrOpMatch[2] ? filePathNormalize(arrOpMatch[2]) : null;
285-
const strOpContent: string = arrOpMatch[3].trim();
286-
const strFinalFilePath: string = strExplicitFilePath || strFilePath;
287-
this.parseOperation(strFinalFilePath, strType, strOpContent);
284+
const strOpContent: string = arrOpMatch[2].trim();
285+
this.parseOperation(strFilePath, strType, strOpContent);
288286
}
289287
}
290288
}

src/siderBar.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ function applyThisCvb(filePath: string) {
160160
* @param filePath .cvb 文件的路径
161161
*/
162162
async function uploadThisCvb(filePath: string) {
163+
164+
// 测试 begin
165+
{
166+
const workspaceFolders = vscode.workspace.workspaceFolders;
167+
if (!workspaceFolders) {
168+
vscode.window.showErrorMessage('No workspace folder found.');
169+
return;
170+
}
171+
const workspacePath = workspaceFolders[0].uri.fsPath;
172+
const filepath = path.join(workspacePath, "/prompt/testdata.txt");
173+
const tcvbContent = fs.readFileSync(filepath, 'utf-8');
174+
const tcvb = new TCVB(tcvbContent);
175+
const cvbContent = fs.readFileSync(filePath, 'utf-8');
176+
const oldCvb = new Cvb(cvbContent);
177+
const cvb = mergeCvb(oldCvb, tcvb);
178+
}
179+
// 测试 end
180+
163181
const userPrompt = await vscode.window.showInputBox({
164182
prompt: 'Enter your prompt for the refactoring',
165183
placeHolder: 'e.g., Refactor the code to improve readability',

0 commit comments

Comments
 (0)