Skip to content

Commit a998bfe

Browse files
committed
区域调试参数,等到使用的时候才生成
1 parent c7135ed commit a998bfe

File tree

9 files changed

+149
-115
lines changed

9 files changed

+149
-115
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.19.1
2+
3+
- 区域调试参数,等到使用的时候才生成
4+
15
## version 2.18.1
26

37
- 增加周赛场次信息展示

package.json

Lines changed: 1 addition & 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.18.1",
5+
"version": "2.19.1",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",

resources/templates/codeonly.tpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
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%>
74
<%=comment.line%>
85
<%=comment.line%> [<%=fid%>] <%=name%>
96
<%=comment.end%>

resources/templates/detailed.tpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
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%>
74
<%=comment.line%>
85
<%=comment.line%> [<%=fid%>] <%=name%>
96
<%=comment.line%>

src/controller/DebugController.ts

Lines changed: 72 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -83,70 +83,82 @@ class DebugContorller {
8383
}
8484

8585
// 尝试获取diy的参数
86-
public async try_get_diy_param() {
86+
public try_get_diy_param(ts: string) {
8787
let debug_param: Array<any> = [];
8888

89-
let ts: string | undefined = await window.showInputBox({
90-
prompt: "测试",
91-
placeHolder: "Example: [1,2,3]\\n4",
92-
ignoreFocusOut: true,
93-
});
94-
9589
ts = (ts || "").replace(/\r?\n/g, "\\n");
9690
ts += "\\n";
9791

9892
let case_array: Array<string> = ts.split("\\n");
9993

10094
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;
95+
if (element.length > 0) {
96+
try {
97+
let cur_param = JSON.parse(element);
98+
if (typeof cur_param == "number") {
99+
debug_param.push("number");
100+
} else if (Array.isArray(cur_param)) {
101+
debug_param.push(this.try_get_array_type(cur_param));
102+
} else if (typeof cur_param == "string") {
103+
debug_param.push(element.length == 1 ? "character" : "string");
104+
} else {
105+
debug_param = [];
106+
return;
107+
}
108+
} catch (error) {
109+
// 这里是字符串
110+
debug_param.push(element.length == 1 ? "character" : "string");
110111
}
111-
} catch (error) {
112-
// 这里是字符串
113-
debug_param.push(element.length == 1 ? "character" : "string");
114112
}
115113
});
116114

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-
// }
115+
// console.log("结果", debug_param);
116+
return debug_param;
117+
}
118+
119+
// 去除测试用例前的注释符号, 测试用例 可能有某些语言的注释符号, 例如 844题的#
120+
public fix_lineContent(lineContent) {
121+
let cut_pos = 0;
122+
for (let left = 0; left < lineContent.length; left++) {
123+
if (lineContent[left] == "#") {
124+
continue;
125+
}
126+
if (lineContent[left] == "/" && lineContent[left + 1] == "/") {
127+
left++;
128+
continue;
129+
}
130+
if (lineContent[left] == "-" && lineContent[left + 1] == "-") {
131+
left++;
132+
continue;
133+
}
134+
if (lineContent[left] == " ") {
135+
continue;
136+
}
137+
cut_pos = left;
138+
break;
139+
}
140+
return lineContent.substring(cut_pos);
141+
}
142+
143+
public get_one_case(document: TextDocument) {
144+
let caseFlag = false;
145+
let curCase = "";
146+
for (let i: number = 0; i < document.lineCount; i++) {
147+
const lineContent: string = document.lineAt(i).text;
148+
149+
if (caseFlag && lineContent.indexOf("@lcpr case=end") < 0) {
150+
curCase += this.fix_lineContent(lineContent).replace(/\s+/g, "");
151+
}
152+
// 收集所有用例
153+
if (lineContent.indexOf("@lcpr case=start") >= 0) {
154+
caseFlag = true;
155+
}
156+
157+
if (caseFlag && lineContent.indexOf("@lcpr case=end") >= 0) {
158+
return curCase;
159+
}
160+
}
161+
return curCase;
150162
}
151163

152164
public async create_diy_debug_arg(meta: ProblemMeta | null, document: TextDocument) {
@@ -165,7 +177,7 @@ class DebugContorller {
165177
`\n`,
166178
`${singleLine} @lcpr-div-debug-arg-start`,
167179
`${singleLine} funName=${name}`,
168-
`${singleLine} paramTypes= []`,
180+
`${singleLine} paramTypes= ${JSON.stringify(this.try_get_diy_param(this.get_one_case(document)))}`,
169181
`${singleLine} @lcpr-div-debug-arg-end`,
170182
`\n`,
171183
];
@@ -252,8 +264,10 @@ class DebugContorller {
252264
}
253265

254266
const content: string = document.getText();
255-
const matchResult: RegExpMatchArray | null = content.match(/@lc app=.* id=(.*) lang=(.*)/);
256-
if (!matchResult || !matchResult[2]) {
267+
const matchResult: RegExpMatchArray | null = content.match(
268+
/@lc app=(.*) id=(.*|\w*|\W*|[\\u4e00-\\u9fa5]*) lang=(.*)/
269+
);
270+
if (!matchResult || !matchResult[3]) {
257271
return undefined;
258272
}
259273
// 搜集所有debug
@@ -302,7 +316,9 @@ class DebugContorller {
302316
}
303317
public async resetDebugType(document: TextDocument, addType) {
304318
const content: string = document.getText();
305-
const matchResult: RegExpMatchArray | null = content.match(/@lc app=.* id=(.*) lang=(.*)/);
319+
const matchResult: RegExpMatchArray | null = content.match(
320+
/@lc app=(.*) id=(.*|\w*|\W*|[\\u4e00-\\u9fa5]*) lang=(.*)/
321+
);
306322
if (!matchResult || !matchResult[2]) {
307323
return undefined;
308324
}

src/controller/TreeViewController.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ 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";
7877

7978
// 视图控制器
8079
class TreeViewController implements Disposable {
@@ -528,12 +527,12 @@ class TreeViewController implements Disposable {
528527
label: `周赛期数查询`,
529528
detail: `周赛期数查询`,
530529
value: `contest`,
531-
},
532-
{
533-
label: `测试api`,
534-
detail: `测试api`,
535-
value: `testapi`,
536530
}
531+
// {
532+
// label: `测试api`,
533+
// detail: `测试api`,
534+
// value: `testapi`,
535+
// }
537536
);
538537
const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(picks, {
539538
title: "选择查询选项",
@@ -632,7 +631,7 @@ class TreeViewController implements Disposable {
632631
// let so = {};
633632
// const solution: string = JSON.stringify(so);
634633
// solutionService.show(solution);
635-
debugContorller.try_get_diy_param();
634+
// debugContorller.try_get_diy_param();
636635
} catch (error) {
637636
logOutput.appendLine(error.toString());
638637
await promptForOpenOutputChannel("Failed to fetch today question. 请查看控制台信息~", OutPutType.error);

src/service/FileButtonService.ts

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ export class FileButtonService implements vscode.CodeLensProvider {
104104
}
105105

106106
if (supportDebugLanguages.indexOf(nodeLang) != -1) {
107-
temp_result.push(
108-
new vscode.CodeLens(range, {
109-
title: "debug",
110-
command: "lcpr.simpleDebug",
111-
arguments: [document],
112-
})
113-
);
107+
if (shortcuts.indexOf("debug") >= 0) {
108+
temp_result.push(
109+
new vscode.CodeLens(range, {
110+
title: "debug",
111+
command: "lcpr.simpleDebug",
112+
arguments: [document],
113+
})
114+
);
115+
}
114116
}
115117

116118
return temp_result;
@@ -124,24 +126,33 @@ export class FileButtonService implements vscode.CodeLensProvider {
124126

125127
const temp_result: vscode.CodeLens[] = [];
126128

127-
temp_result.push(
128-
new vscode.CodeLens(range, {
129-
title: "case",
130-
command: "lcpr.tesCaseArea",
131-
arguments: [document.uri, testCase],
132-
})
133-
);
129+
const shortcuts: string[] = getEditorShortcuts();
130+
if (!shortcuts) {
131+
return temp_result;
132+
}
134133

135-
if (supportDebugLanguages.indexOf(nodeLang) != -1) {
134+
if (shortcuts.indexOf("case") >= 0) {
136135
temp_result.push(
137136
new vscode.CodeLens(range, {
138-
title: "debug",
139-
command: "lcpr.simpleDebug",
140-
arguments: [document, testCase],
137+
title: "case",
138+
command: "lcpr.tesCaseArea",
139+
arguments: [document.uri, testCase],
141140
})
142141
);
143142
}
144143

144+
if (supportDebugLanguages.indexOf(nodeLang) != -1) {
145+
if (shortcuts.indexOf("debug") >= 0) {
146+
temp_result.push(
147+
new vscode.CodeLens(range, {
148+
title: "debug",
149+
command: "lcpr.simpleDebug",
150+
arguments: [document, testCase],
151+
})
152+
);
153+
}
154+
}
155+
145156
return temp_result;
146157
}
147158

@@ -218,20 +229,26 @@ export class FileButtonService implements vscode.CodeLensProvider {
218229
// paramTypes= []
219230

220231
if (lineContent.indexOf("paramTypes=") >= 0) {
221-
temp_result.push(
222-
new vscode.CodeLens(range, {
223-
title: "addParam",
224-
command: "lcpr.addDebugType",
225-
arguments: [document, "paramTypes"],
226-
})
227-
);
228-
temp_result.push(
229-
new vscode.CodeLens(range, {
230-
title: "resetParam",
231-
command: "lcpr.resetDebugType",
232-
arguments: [document, "paramTypes"],
233-
})
234-
);
232+
const shortcuts: string[] = getEditorShortcuts();
233+
if (!shortcuts) {
234+
return temp_result;
235+
}
236+
if (shortcuts.indexOf("debug") >= 0) {
237+
temp_result.push(
238+
new vscode.CodeLens(range, {
239+
title: "addParam",
240+
command: "lcpr.addDebugType",
241+
arguments: [document, "paramTypes"],
242+
})
243+
);
244+
temp_result.push(
245+
new vscode.CodeLens(range, {
246+
title: "resetParam",
247+
command: "lcpr.resetDebugType",
248+
arguments: [document, "paramTypes"],
249+
})
250+
);
251+
}
235252
}
236253

237254
// if (lineContent.indexOf("returnType=") >= 0) {
@@ -255,16 +272,18 @@ export class FileButtonService implements vscode.CodeLensProvider {
255272

256273
public provideCodeLenses(document: vscode.TextDocument): vscode.ProviderResult<vscode.CodeLens[]> {
257274
const content: string = document.getText();
258-
const matchResult: RegExpMatchArray | null = content.match(/@lc app=.* id=(.*) lang=(.*)/);
275+
const matchResult: RegExpMatchArray | null = content.match(
276+
/@lc app=(.*) id=(.*|\w*|\W*|[\\u4e00-\\u9fa5]*) lang=(.*)/
277+
);
259278
if (!matchResult) {
260279
return undefined;
261280
}
262-
const nodeId: string | undefined = matchResult[1];
281+
const nodeId: string | undefined = matchResult[2];
263282
let node: NodeModel | undefined;
264283
if (nodeId) {
265284
node = treeViewController.getNodeById(nodeId);
266285
}
267-
let nodeLang: string | undefined = matchResult[2];
286+
let nodeLang: string | undefined = matchResult[3];
268287

269288
const codeLens: vscode.CodeLens[] = [];
270289
let caseFlag: boolean = false;

0 commit comments

Comments
 (0)