Skip to content

Commit 5209156

Browse files
authored
Merge pull request #181 from ccagml/main
请尝试配置区域调试参数
2 parents ddf158a + b2be842 commit 5209156

File tree

15 files changed

+5548
-5353
lines changed

15 files changed

+5548
-5353
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## version 2.15.3
2+
3+
- 原插件不能调试的题目,增加区域调试参数
4+
15
## version 2.15.2
26

37
- 有些题目不能 debug 的提示

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
- [新增题目自定义分类](#新增在工作目录存放数据)
2929
- [答案不同上色,配置默认不开启](#插件配置项)
3030
- 增加获取中文站的题解
31-
- 增加 cpp、js、py3 一些题目的 debug(参考其他项目,有问题提 issues)
31+
- 增加 cpp、js、py3 一些题目的 debug(参考 wangtao0101 项目,有问题提 issues)
32+
- [有些题目原插件无法调试,请尝试配置区域调试参数](#区域调试参数的一些说明)
3233

3334
# 关于本项目
3435

@@ -74,6 +75,55 @@
7475

7576
- 查看一个题目时会开始计时,提交一个题目通过后会停止计时
7677

78+
## 区域调试参数的一些说明
79+
80+
### 如果有些题目无法 debug,请尝试配置 diy 参数区
81+
82+
1. 例子 cpp 2544 题为例
83+
```
84+
// @lcpr-div-debug-arg-start
85+
// funName= alternateDigitSum
86+
// paramTypes= ["number"]
87+
// returnType= number
88+
// @lcpr-div-debug-arg-end
89+
```
90+
2. diy 参数说明
91+
92+
- funName:函数名,既本次解决方法的函数名
93+
- paramTypes:函数的输入参数,是一个字符串数组类型
94+
- 可填入内容为以下字符串
95+
- "number"
96+
- 类型说明:数字
97+
- "number[]"
98+
- 类型说明:数字数组
99+
- "number[][]"
100+
- 类型说明:数字二维数组
101+
- "string"
102+
- 类型说明:字符串
103+
- "string[]"
104+
- 类型说明:字符串数组
105+
- "string[][]"
106+
- 类型说明:字符串二维数组
107+
- "ListNode"
108+
- 类型说明:链表
109+
- "ListNode[]"
110+
- 类型说明:链表数组
111+
- "character"
112+
- 类型说明:字节
113+
- "character[]"
114+
- 类型说明:字节数组
115+
- "character[][]"
116+
- 类型说明:字节二维数组
117+
- "NestedInteger[]"
118+
- 类型说明:数组
119+
- "MountainArray"
120+
- 类型说明:数组
121+
- "TreeNode"
122+
- 类型说明:树节点
123+
- returnType:函数的返回值
124+
125+
- 可填入内容同 paramTypes
126+
77127
<!-- ## TODO 看到一些可能会用得上的功能
78128
79129
- (完成) 在文件里面插入一些测试用例?

package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "%main.description%",
5-
"version": "2.15.2",
5+
"version": "2.15.3",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",
@@ -1118,6 +1118,19 @@
11181118
"default": 3600,
11191119
"scope": "application",
11201120
"description": "Open the app to clear the cache interval by default 3600 seconds"
1121+
},
1122+
"leetcode-problem-rating.cppCompiler": {
1123+
"type": "string",
1124+
"default": "gdb",
1125+
"enum": [
1126+
"gdb",
1127+
"clang"
1128+
],
1129+
"enumDescriptions": [
1130+
"gdb compiler",
1131+
"clang compiler"
1132+
],
1133+
"scope": "resource"
11211134
}
11221135
}
11231136
}

resources/templates/codeonly.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<%=code%>
1010
<%=comment.singleLine%> @lc code=end
1111

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
1217

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

resources/templates/detailed.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
<%=code%>
2222
<%=comment.singleLine%> @lc code=end
2323

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
29+
2430
<% if(allCaseList && allCaseList.length > 0){ %>
2531
<%=comment.start%><% allCaseList.forEach(function(acase) { %>
2632
<%=comment.singleLine%> @lcpr case=start

src/controller/DebugController.ts

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

10-
import { Uri, window } from "vscode";
10+
import { TextDocument, window } from "vscode";
1111
import { getTextEditorFilePathByUri } from "../utils/SystemUtils";
1212
import * as fs from "fs";
13-
import { fileMeta, ProblemMeta, canDebug } from "../utils/problemUtils";
14-
// import problemTypes from "../utils/problemTypes";
13+
import { fileMeta, ProblemMeta, supportDebugLanguages } from "../utils/problemUtils";
14+
1515
import { debugService } from "../service/DebugService";
16+
import { debugArgDao } from "../dao/debugArgDao";
1617

1718
// 做杂活
1819
class DebugContorller {
1920
constructor() {}
21+
public canDebug(meta: ProblemMeta | null, document: TextDocument) {
22+
if (
23+
meta == null ||
24+
supportDebugLanguages.indexOf(meta.lang) === -1 ||
25+
debugArgDao.getDebugArgData(meta.id, document) == undefined
26+
) {
27+
return false;
28+
}
29+
return true;
30+
}
2031

21-
public async startDebug(uri: Uri, testcase?: string): Promise<void> {
32+
public async startDebug(document: TextDocument, testcase?: string): Promise<void> {
2233
try {
23-
const filePath: string | undefined = await getTextEditorFilePathByUri(uri);
34+
const filePath: string | undefined = await getTextEditorFilePathByUri(document.uri);
2435
if (!filePath) {
2536
return;
2637
}
2738
const fileContent: Buffer = fs.readFileSync(filePath);
2839
const meta: ProblemMeta | null = fileMeta(fileContent.toString());
29-
if (!canDebug(meta)) {
30-
window.showErrorMessage("这题还不能debug 麻烦提issuse");
40+
41+
if (!this.canDebug(meta, document)) {
42+
window.showErrorMessage("这题还不能debug,请尝试配置区域调试参数,麻烦提issuse");
3143
return;
3244
}
3345
let result: any;
3446

3547
if (testcase != undefined) {
36-
result = await debugService.execute(filePath, testcase.replace(/"/g, '\\"'), meta!.lang);
48+
result = await debugService.execute(document, filePath, testcase.replace(/"/g, '\\"'), meta!.lang);
3749
} else {
3850
const ts: string | undefined = await window.showInputBox({
3951
prompt: "Enter the test cases.",
@@ -43,7 +55,7 @@ class DebugContorller {
4355
ignoreFocusOut: true,
4456
});
4557
if (ts) {
46-
result = await debugService.execute(filePath, ts.replace(/"/g, '\\"'), meta!.lang);
58+
result = await debugService.execute(document, filePath, ts.replace(/"/g, '\\"'), meta!.lang);
4759
}
4860
}
4961

0 commit comments

Comments
 (0)