Skip to content

Commit c7135ed

Browse files
committed
尝试调试参数
1 parent 7e5cca1 commit c7135ed

File tree

14 files changed

+232
-1863
lines changed

14 files changed

+232
-1863
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
// @lcpr-div-debug-arg-start
8585
// funName= alternateDigitSum
8686
// paramTypes= ["number"]
87-
// returnType= number
8887
// @lcpr-div-debug-arg-end
8988
```
9089
2. diy 参数说明
@@ -120,9 +119,6 @@
120119
- 类型说明:数组
121120
- "TreeNode"
122121
- 类型说明:树节点
123-
- returnType:函数的返回值
124-
125-
- 可填入内容同 paramTypes
126122

127123
<!-- ## TODO 看到一些可能会用得上的功能
128124

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,8 @@
10181018
"case",
10191019
"allcase",
10201020
"test",
1021-
"solution"
1021+
"solution",
1022+
"debug"
10221023
],
10231024
"scope": "application",
10241025
"items": {
@@ -1030,7 +1031,8 @@
10301031
"solution",
10311032
"description",
10321033
"case",
1033-
"allcase"
1034+
"allcase",
1035+
"debug"
10341036
],
10351037
"enumDescriptions": [
10361038
"%main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions.0%",
@@ -1039,7 +1041,8 @@
10391041
"%main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions.3%",
10401042
"%main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions.4%",
10411043
"%main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions.5%",
1042-
"%main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions.6%"
1044+
"%main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions.6%",
1045+
"%main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions.7%"
10431046
]
10441047
},
10451048
"description": "%main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.description%"

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
"Show the top voted solution for the current problem.",
8080
"Show the problem description page.",
8181
"Test default case",
82-
"Test all default case"
82+
"Test all default case",
83+
"Debug case"
8384
],
8485
"main.contributes.configuration.properties.leetcode-problem-rating.enableSideMode.description": "Determine whether to group all webview pages into the second editor column when solving problems.",
8586
"main.contributes.configuration.properties.leetcode-problem-rating.nodePath.description": "The Node.js executable path. for example, C:\\Program Files\\nodejs\\node.exe",

package.nls.zh-cn.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@
7373
"main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description": "是否显示状态栏。",
7474
"main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.description": "自定义编辑器中的快捷方式。",
7575
"main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions": [
76-
"Submit your answer to LeetCode.",
77-
"Test your answer with customized test cases.",
78-
"Star or unstar the current problem.",
79-
"Show the top voted solution for the current problem.",
80-
"Show the problem description page.",
81-
"Test default case",
82-
"Test all default case"
76+
"提交题解",
77+
"提交测试",
78+
"题目标心",
79+
"获取题解",
80+
"显示题目简介",
81+
"提交默认测试",
82+
"提交所有测试",
83+
"本地调试"
8384
],
8485
"main.contributes.configuration.properties.leetcode-problem-rating.enableSideMode.description": "解决问题时确定是否将所有webview页面分组到第二个编辑器列中。",
8586
"main.contributes.configuration.properties.leetcode-problem-rating.nodePath.description": "Node.js 可执行文件路径。 例如:C:\\Program Files\\nodejs\\node.exe",

resources/templates/codeonly.tpl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<%=comment.start%>
22
<%=comment.line%> @lc app=<%=app%> id=<%=fid%> lang=<%=lang%>
33
<%=comment.line%> @lcpr version=<%=LCPTCTX.version%>
4+
<%=comment.line%> @lcpr app=<%=app%>
5+
<%=comment.line%> @lcpr id=<%=fid%>
6+
<%=comment.line%> @lcpr lang=<%=lang%>
47
<%=comment.line%>
58
<%=comment.line%> [<%=fid%>] <%=name%>
69
<%=comment.end%>
@@ -9,11 +12,6 @@
912
<%=code%>
1013
<%=comment.singleLine%> @lc code=end
1114

12-
<%=comment.singleLine%> @lcpr-div-debug-arg-start
13-
<%=comment.singleLine%> funName=
14-
<%=comment.singleLine%> paramTypes= []
15-
<%=comment.singleLine%> returnType=
16-
<%=comment.singleLine%> @lcpr-div-debug-arg-end
1715

1816
<% if(allCaseList && allCaseList.length > 0){ %>
1917
<%=comment.start%><% allCaseList.forEach(function(acase) { %>

resources/templates/detailed.tpl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<%=comment.start%>
22
<%=comment.line%> @lc app=<%=app%> id=<%=fid%> lang=<%=lang%>
33
<%=comment.line%> @lcpr version=<%=LCPTCTX.version%>
4+
<%=comment.line%> @lcpr app=<%=app%>
5+
<%=comment.line%> @lcpr id=<%=fid%>
6+
<%=comment.line%> @lcpr lang=<%=lang%>
47
<%=comment.line%>
58
<%=comment.line%> [<%=fid%>] <%=name%>
69
<%=comment.line%>
@@ -21,11 +24,6 @@
2124
<%=code%>
2225
<%=comment.singleLine%> @lc code=end
2326

24-
<%=comment.singleLine%> @lcpr-div-debug-arg-start
25-
<%=comment.singleLine%> funName=
26-
<%=comment.singleLine%> paramTypes= []
27-
<%=comment.singleLine%> returnType=
28-
<%=comment.singleLine%> @lcpr-div-debug-arg-end
2927

3028
<% if(allCaseList && allCaseList.length > 0){ %>
3129
<%=comment.start%><% allCaseList.forEach(function(acase) { %>

src/controller/DebugController.ts

Lines changed: 165 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2023 ccagml . All rights reserved
88
*/
99

10-
import { TextDocument, window, Range } from "vscode";
10+
import { TextDocument, window, Range, Position } from "vscode";
1111
import { getTextEditorFilePathByUri } from "../utils/SystemUtils";
1212
import * as fs from "fs";
1313
import { fileMeta, ProblemMeta, supportDebugLanguages } from "../utils/problemUtils";
@@ -17,6 +17,26 @@ import { debugArgDao } from "../dao/debugArgDao";
1717

1818
import { IQuickItemEx } from "../model/Model";
1919

20+
const singleLineFlag = {
21+
bash: "#",
22+
c: "//",
23+
cpp: "//",
24+
csharp: "//",
25+
golang: "//",
26+
java: "//",
27+
javascript: "//",
28+
kotlin: "//",
29+
mysql: "--",
30+
php: "//",
31+
python: "#",
32+
python3: "#",
33+
ruby: "#",
34+
rust: "//",
35+
scala: "//",
36+
swift: "//",
37+
typescript: "//",
38+
};
39+
2040
// 做杂活
2141
class DebugContorller {
2242
constructor() {}
@@ -31,6 +51,137 @@ class DebugContorller {
3151
return true;
3252
}
3353

54+
public async check_create_debug_area(meta: ProblemMeta | null, document: TextDocument) {
55+
if (supportDebugLanguages.indexOf(meta?.lang || "") != -1) {
56+
// 分析uri代码块
57+
if (document != null) {
58+
const fileContent: string = document.getText();
59+
const debug_div_arg: RegExp = /@lcpr-div-debug-arg-start/;
60+
if (!debug_div_arg.test(fileContent.toString())) {
61+
// 弹一个生成配置区的选项
62+
await this.create_diy_debug_arg(meta, document);
63+
}
64+
}
65+
}
66+
}
67+
68+
public try_get_array_type(obj) {
69+
if (Array.isArray(obj)) {
70+
if (Array.isArray(obj[0])) {
71+
if (typeof obj[0][0] == "number") {
72+
return "number[][]";
73+
} else if (typeof obj[0][0] == "string") {
74+
return "string[][]";
75+
}
76+
} else if (typeof obj[0] == "number") {
77+
return "number[]";
78+
} else if (typeof obj[0] == "string") {
79+
return "string[]";
80+
}
81+
}
82+
return "try_arg_error";
83+
}
84+
85+
// 尝试获取diy的参数
86+
public async try_get_diy_param() {
87+
let debug_param: Array<any> = [];
88+
89+
let ts: string | undefined = await window.showInputBox({
90+
prompt: "测试",
91+
placeHolder: "Example: [1,2,3]\\n4",
92+
ignoreFocusOut: true,
93+
});
94+
95+
ts = (ts || "").replace(/\r?\n/g, "\\n");
96+
ts += "\\n";
97+
98+
let case_array: Array<string> = ts.split("\\n");
99+
100+
case_array.forEach((element) => {
101+
try {
102+
let cur_param = JSON.parse(element);
103+
if (typeof cur_param == "number") {
104+
debug_param.push("number");
105+
} else if (Array.isArray(cur_param)) {
106+
debug_param.push(this.try_get_array_type(cur_param));
107+
} else {
108+
debug_param = [];
109+
return;
110+
}
111+
} catch (error) {
112+
// 这里是字符串
113+
debug_param.push(element.length == 1 ? "character" : "string");
114+
}
115+
});
116+
117+
console.log("结果", debug_param);
118+
119+
// const picks: Array<IQuickItemEx<string>> = [
120+
// { label: "number", detail: "类型说明:数字", value: "number" },
121+
// { label: "number[]", detail: "类型说明:数字数组", value: "number[]" },
122+
// { label: "number[][]", detail: "类型说明:数字二维数组", value: "number[][]" },
123+
// { label: "string", detail: "类型说明:字符串", value: "string" },
124+
// { label: "string[]", detail: "类型说明:字符串数组", value: "string[]" },
125+
// { label: "string[][]", detail: "类型说明:字符串二维数组", value: "string[][]" },
126+
// { label: "character", detail: "类型说明:字节", value: "character" },
127+
// { label: "character[]", detail: "类型说明:字节数组", value: "character[]" },
128+
// { label: "character[][]", detail: "类型说明:字节二维数组", value: "character[][]" },
129+
// ];
130+
131+
// let equal_index = lineContent.indexOf("=");
132+
// const last_index = document.lineAt(i).range.end.character;
133+
// if (addType == "paramTypes" && lineContent.indexOf("paramTypes=") >= 0) {
134+
// window.activeTextEditor?.edit((edit) => {
135+
// // 参数是个数组;
136+
// // edit.replace(new Position(i, equal_index + 1), choice.value);
137+
// let cur_param_str = lineContent.substring(equal_index + 1);
138+
// let cur_param_array: any = [];
139+
// try {
140+
// cur_param_array = JSON.parse(cur_param_str);
141+
// } catch (error) {
142+
// cur_param_array = [];
143+
// }
144+
145+
// cur_param_array.push(choice.value);
146+
147+
// edit.replace(new Range(i, equal_index + 1, i, last_index), JSON.stringify(cur_param_array));
148+
// });
149+
// }
150+
}
151+
152+
public async create_diy_debug_arg(meta: ProblemMeta | null, document: TextDocument) {
153+
const name: string | undefined = await window.showInputBox({
154+
prompt: "输入函数名",
155+
title: "尝试生成区域调试参数",
156+
ignoreFocusOut: true,
157+
});
158+
159+
if (!(name && name.trim())) {
160+
return;
161+
}
162+
163+
let singleLine = singleLineFlag[meta?.lang || ""];
164+
let div_debug_arg: any = [
165+
`\n`,
166+
`${singleLine} @lcpr-div-debug-arg-start`,
167+
`${singleLine} funName=${name}`,
168+
`${singleLine} paramTypes= []`,
169+
`${singleLine} @lcpr-div-debug-arg-end`,
170+
`\n`,
171+
];
172+
173+
for (let i: number = 0; i < document.lineCount; i++) {
174+
const lineContent: string = document.lineAt(i).text;
175+
176+
if (lineContent.indexOf("@lc code=end") >= 0) {
177+
const editor = window.activeTextEditor;
178+
editor?.edit((edit) => {
179+
edit.insert(new Position(i + 1, i + 1), div_debug_arg.join("\n"));
180+
});
181+
}
182+
}
183+
}
184+
34185
public async startDebug(document: TextDocument, testcase?: string): Promise<void> {
35186
try {
36187
const filePath: string | undefined = await getTextEditorFilePathByUri(document.uri);
@@ -41,7 +192,9 @@ class DebugContorller {
41192
const meta: ProblemMeta | null = fileMeta(fileContent.toString());
42193

43194
if (!this.canDebug(meta, document)) {
44-
window.showErrorMessage("这题还不能debug,请尝试配置区域调试参数,麻烦提issuse");
195+
// window.showErrorMessage("这题还不能debug,请尝试配置区域调试参数,麻烦提issuse");
196+
// 判断生成测试区块
197+
await this.check_create_debug_area(meta, document);
45198
return;
46199
}
47200
let result: any;
@@ -132,11 +285,12 @@ class DebugContorller {
132285

133286
edit.replace(new Range(i, equal_index + 1, i, last_index), JSON.stringify(cur_param_array));
134287
});
135-
} else if (addType == "returnType" && lineContent.indexOf("returnType=") >= 0) {
136-
window.activeTextEditor?.edit((edit) => {
137-
edit.replace(new Range(i, equal_index + 1, i, last_index), choice.value);
138-
});
139288
}
289+
// else if (addType == "returnType" && lineContent.indexOf("returnType=") >= 0) {
290+
// window.activeTextEditor?.edit((edit) => {
291+
// edit.replace(new Range(i, equal_index + 1, i, last_index), choice.value);
292+
// });
293+
// }
140294
}
141295

142296
// 收集所有用例
@@ -170,11 +324,12 @@ class DebugContorller {
170324
let cur_param_array: any = [];
171325
edit.replace(new Range(i, equal_index + 1, i, last_index), JSON.stringify(cur_param_array));
172326
});
173-
} else if (addType == "returnType" && lineContent.indexOf("returnType=") >= 0) {
174-
window.activeTextEditor?.edit((edit) => {
175-
edit.replace(new Range(i, equal_index + 1, i, last_index), "");
176-
});
177327
}
328+
// else if (addType == "returnType" && lineContent.indexOf("returnType=") >= 0) {
329+
// window.activeTextEditor?.edit((edit) => {
330+
// edit.replace(new Range(i, equal_index + 1, i, last_index), "");
331+
// });
332+
// }
178333
}
179334

180335
// 收集所有用例

src/controller/TreeViewController.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import { fileButtonService } from "../service/FileButtonService";
7474
import * as fse from "fs-extra";
7575
import { submissionService } from "../service/SubmissionService";
7676
import { bricksDataService } from "../service/BricksDataService";
77+
import { debugContorller } from "./DebugController";
7778

7879
// 视图控制器
7980
class TreeViewController implements Disposable {
@@ -527,12 +528,12 @@ class TreeViewController implements Disposable {
527528
label: `周赛期数查询`,
528529
detail: `周赛期数查询`,
529530
value: `contest`,
531+
},
532+
{
533+
label: `测试api`,
534+
detail: `测试api`,
535+
value: `testapi`,
530536
}
531-
// {
532-
// label: `测试api`,
533-
// detail: `测试api`,
534-
// value: `testapi`,
535-
// }
536537
);
537538
const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(picks, {
538539
title: "选择查询选项",
@@ -628,10 +629,10 @@ class TreeViewController implements Disposable {
628629

629630
public async testapi(): Promise<void> {
630631
try {
631-
let so = {};
632-
633-
const solution: string = JSON.stringify(so);
634-
solutionService.show(solution);
632+
// let so = {};
633+
// const solution: string = JSON.stringify(so);
634+
// solutionService.show(solution);
635+
debugContorller.try_get_diy_param();
635636
} catch (error) {
636637
logOutput.appendLine(error.toString());
637638
await promptForOpenOutputChannel("Failed to fetch today question. 请查看控制台信息~", OutPutType.error);

0 commit comments

Comments
 (0)