Skip to content

Commit 21cceb5

Browse files
committed
调试时, TreeNode 参数类型的数据,测试用例数据是整数时的调试参数解析问题
1 parent 5d5434b commit 21cceb5

File tree

8 files changed

+70
-27
lines changed

8 files changed

+70
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# version 3.1.6
22

33
- 每日一题完成后延迟 5 秒请求数据(因为马上请求,获得的状态还是未完成)
4+
- 调试时, TreeNode 参数类型的数据,测试用例数据是整数时的调试参数解析问题
45

56
# version 3.1.5
67

resources/debug/entry/cpp/problems/common.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include <vector>
21
#include <queue>
2+
#include <vector>
33
using namespace std;
44

55
#include "cJSON.h"
@@ -240,6 +240,13 @@ TreeNode *parseTreeNode(const cJSON *node)
240240
queue<TreeNode *> q;
241241
int i = 0;
242242

243+
// LCP 194题的参数 是整数
244+
if (node->type == cJSON_Number)
245+
{
246+
TreeNode *child = new TreeNode(node->valueint);
247+
return child;
248+
}
249+
243250
if (node->type != cJSON_Array)
244251
{
245252
throw "Parse parameter error, expect NumberArray";

resources/debug/entry/javascript/entry.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const sock = net.connect(
1111
port: debugServerPort,
1212
host: "127.0.0.1",
1313
},
14-
function() {
14+
function () {
1515
start();
1616
},
1717
);
@@ -47,7 +47,7 @@ function onSuccess() {
4747
onClose();
4848
}
4949

50-
process.on("uncaughtException", function(err) {
50+
process.on("uncaughtException", function (err) {
5151
onError(err.message + "\n" + err.stack);
5252
throw err;
5353
});
@@ -209,7 +209,7 @@ function NestedInteger(ni) {
209209
* Return true if this NestedInteger holds a single integer, rather than a nested list.
210210
* @return { boolean }
211211
*/
212-
this.isInteger = function() {
212+
this.isInteger = function () {
213213
if (Array.isArray(ni)) {
214214
return false;
215215
}
@@ -221,7 +221,7 @@ function NestedInteger(ni) {
221221
* Return null if this NestedInteger holds a nested list
222222
* @return { integer }
223223
*/
224-
this.getInteger = function() {
224+
this.getInteger = function () {
225225
if (Array.isArray(ni)) {
226226
return null;
227227
}
@@ -233,7 +233,7 @@ function NestedInteger(ni) {
233233
* Return null if this NestedInteger holds a single integer
234234
* @return { NestedInteger[] }
235235
*/
236-
this.getList = function() {
236+
this.getList = function () {
237237
if (Array.isArray(ni)) {
238238
return nested;
239239
}
@@ -256,14 +256,14 @@ function parseMountainArray(param) {
256256
* @param {integer} index
257257
* @return {integer}
258258
*/
259-
this.get = function(index) {
259+
this.get = function (index) {
260260
return param[index];
261261
};
262262

263263
/**
264264
* @return {integer}
265265
*/
266-
this.length = function() {
266+
this.length = function () {
267267
return param.length;
268268
};
269269
}
@@ -276,6 +276,12 @@ function TreeNode(val) {
276276
}
277277

278278
function parseTreeNode(param) {
279+
// LCP 194题的参数 是整数
280+
if (isNumber(param)) {
281+
return new TreeNode(param);
282+
}
283+
284+
279285
if (!Array.isArray(param)) {
280286
onParameterError();
281287
}

resources/debug/entry/python3/entry.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ def parseMountainArray(param):
218218

219219

220220
def parseTreeNode(param):
221+
# LCP 194题的参数 是整数
222+
if (isNumber(param)):
223+
return TreeNode(param)
221224
if (not isList(param)):
222225
onParameterError()
223226

src/BABA.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { BaseCC } from "./utils/BaseCC";
1313
export * as BaseCC from "./utils/BaseCC";
1414
export enum BabaStr {
1515
every_second = "every_second",
16+
every_minute = "every_minute",
1617
StatusBarTimeMediator = "StatusBarTimeMediator",
1718
StatusBarTimeProxy = "StatusBarTimeProxy",
1819
RemarkMediator = "RemarkMediator",

src/debug/DoPy3.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ export class DebugPy3 {
4242
return;
4343
}
4444

45-
debugConfig.program = await getEntryFile(meta.lang, meta.id);
45+
const numericStr = meta.id.replace(/\D/g, ""); // 去除非数字字符
46+
const temp_meta_id = parseInt(numericStr, 10);
47+
48+
debugConfig.program = await getEntryFile(meta.lang, temp_meta_id.toString());
4649

4750
// check whether module.exports is exist or not
4851
const moduleExportsReg: RegExp = /# @lcpr-before-debug-begin/;
4952
if (!moduleExportsReg.test(fileContent.toString())) {
5053
await fse.writeFile(
5154
filePath,
52-
`# @lcpr-before-debug-begin\nfrom python3problem${meta.id} import *\nfrom typing import *\n# @lcpr-before-debug-end\n\n` +
55+
`# @lcpr-before-debug-begin\nfrom python3problem${temp_meta_id.toString()} import *\nfrom typing import *\n# @lcpr-before-debug-end\n\n` +
5356
fileContent.toString()
5457
);
5558
}
@@ -60,7 +63,7 @@ export class DebugPy3 {
6063
problemType.funName,
6164
problemType.paramTypes.join(","),
6265
problemType.returnType || "returnType",
63-
meta.id,
66+
temp_meta_id.toString(),
6467
port.toString(),
6568
];
6669
vscode.debug.startDebugging(

src/extension.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ import { TodayDataMediator, TodayDataProxy } from "./todayData/TodayDataModule";
3838
* @param {ExtensionContext} context - ExtensionContext
3939
*/
4040

41-
let lcpr_timer;
41+
let lcpr_timer_sec;
42+
let lcpr_timer_min;
4243
export async function activate(context: ExtensionContext): Promise<void> {
4344
try {
4445
BABA.init([
@@ -225,22 +226,29 @@ export async function activate(context: ExtensionContext): Promise<void> {
225226
BABA.getProxy(BabaStr.LogOutputProxy).get_log().appendLine(error.toString());
226227
ShowMessage("Extension initialization failed. Please open output channel for details.", OutPutType.error);
227228
} finally {
228-
lcpr_timer = setInterval(lcpr_timer_callback, 1000);
229+
lcpr_timer_sec = setInterval(() => {
230+
new Promise(async (resolve, _) => {
231+
await BABA.sendNotificationAsync(BabaStr.every_second);
232+
resolve(1);
233+
});
234+
}, 1000);
235+
lcpr_timer_min = setInterval(() => {
236+
new Promise(async (resolve, _) => {
237+
await BABA.sendNotificationAsync(BabaStr.every_minute);
238+
resolve(1);
239+
});
240+
}, 60000);
229241
}
230242
}
231243

232-
function lcpr_timer_callback() {
233-
BABA.sendNotification(BabaStr.every_second);
234-
}
235-
236244
export function deactivate(): void {
237245
// Do nothing.
238-
if (0) {
239-
let a = 0;
240-
console.log(a);
246+
if (lcpr_timer_sec != undefined) {
247+
clearInterval(lcpr_timer_sec);
248+
lcpr_timer_sec = undefined;
241249
}
242-
if (lcpr_timer != undefined) {
243-
clearInterval(lcpr_timer);
244-
lcpr_timer = undefined;
250+
if (lcpr_timer_min != undefined) {
251+
clearInterval(lcpr_timer_min);
252+
lcpr_timer_min = undefined;
245253
}
246254
}

src/todayData/TodayDataModule.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ISubmitEvent, OutPutType } from "../model/ConstDefind";
1212
import { ITodayDataResponse } from "../model/TreeNodeModel";
1313
import { isUseEndpointTranslation } from "../utils/ConfigUtils";
1414
import { promptForSignIn, ShowMessage } from "../utils/OutputUtils";
15-
import { getDayEnd, getDayStart } from "../utils/SystemUtils";
15+
import { getDayEnd, getDayNow, getDayStart } from "../utils/SystemUtils";
1616

1717
class TodayData {
1818
fidInfo: Map<string, ITodayDataResponse> = new Map<string, ITodayDataResponse>();
@@ -25,18 +25,23 @@ class TodayData {
2525
return this.fidInfo.get(fid);
2626
}
2727

28-
checkNeedReadNew() {
28+
async checkNeedReadNew() {
2929
const day_start = getDayStart(); //获取当天零点的时间
3030
const day_end = getDayEnd(); //获取当天23:59:59的时间
3131
let need_get_today: boolean = true;
3232

33+
let cur_time = getDayNow();
34+
if (cur_time > day_start + 600 || cur_time < day_start + 300) {
35+
return;
36+
}
37+
3338
this.fidInfo.forEach((value) => {
3439
if (day_start <= value.time && value.time <= day_end) {
3540
need_get_today = false;
3641
}
3742
});
3843
if (need_get_today) {
39-
BABA.getProxy(BabaStr.TodayDataProxy).searchToday();
44+
await BABA.getProxy(BabaStr.TodayDataProxy).searchToday();
4045
}
4146
}
4247
public async checkSubmit(e: ISubmitEvent) {
@@ -111,7 +116,13 @@ export class TodayDataMediator extends BABAMediator {
111116
}
112117

113118
listNotificationInterests(): string[] {
114-
return [BabaStr.VSCODE_DISPOST, BabaStr.StartReadData, BabaStr.CommitResult_showFinish, BabaStr.BABACMD_refresh];
119+
return [
120+
BabaStr.VSCODE_DISPOST,
121+
BabaStr.StartReadData,
122+
BabaStr.CommitResult_showFinish,
123+
BabaStr.BABACMD_refresh,
124+
BabaStr.every_minute,
125+
];
115126
}
116127
async handleNotification(_notification: BaseCC.BaseCC.INotification) {
117128
switch (_notification.getName()) {
@@ -126,6 +137,9 @@ export class TodayDataMediator extends BABAMediator {
126137
case BabaStr.BABACMD_refresh:
127138
BABA.getProxy(BabaStr.TodayDataProxy).searchToday();
128139
break;
140+
case BabaStr.every_minute:
141+
await todayData.checkNeedReadNew();
142+
break;
129143
default:
130144
break;
131145
}

0 commit comments

Comments
 (0)