Skip to content

Commit ab8d221

Browse files
committed
update
1 parent 24443e3 commit ab8d221

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+118
-267
lines changed

CHANGELOG.md

+4

README.md

+24-21

package.json

+1-1
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.14.2",
5+
"version": "2.15.1",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",
File renamed without changes.

src/debug/entry/javascript/entry.js renamed to resources/debug/entry/javascript/entry.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ function parseParameter(index, type, param) {
349349
function parseParamsToJson(paramString) {
350350
let params;
351351
try {
352-
const paramsByLine = paramString.split(/\\n/);
352+
let paramsByLine = paramString.split(/\\n/);
353+
paramsByLine = paramsByLine.slice(0, paramTypes.length);
353354

354355
params = paramsByLine.map(str => {
355356
return JSON.parse(str);

src/debug/entry/python3/entry.py renamed to resources/debug/entry/python3/entry.py

+1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ def loadModule():
291291

292292
def start():
293293
lines = testString.split("\\n")
294+
lines = lines[:len(paramTypes)]
294295
params = []
295296
for i, val in enumerate(lines):
296297
params.append(json.loads(codecs.getdecoder("unicode_escape")(val)[0]))
File renamed without changes.
File renamed without changes.

src/controller/DebugController.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import { Uri, window } from "vscode";
1111
import { getTextEditorFilePathByUri } from "../utils/SystemUtils";
1212
import * as fs from "fs";
1313
import { fileMeta, ProblemMeta, canDebug } from "../utils/problemUtils";
14-
import problemTypes from "../utils/problemTypes";
15-
import { debugExecutor } from "../debug/debugExecutor";
14+
// import problemTypes from "../utils/problemTypes";
15+
import { debugService } from "../service/DebugService";
1616

1717
// 做杂活
1818
class DebugContorller {
1919
constructor() {}
2020

21-
public async debugSolution(uri: Uri, testcase?: string): Promise<void> {
21+
public async startDebug(uri: Uri, testcase?: string): Promise<void> {
2222
try {
2323
const filePath: string | undefined = await getTextEditorFilePathByUri(uri);
2424
if (!filePath) {
@@ -31,12 +31,8 @@ class DebugContorller {
3131
}
3232
let result: any;
3333

34-
if (!testcase) {
35-
result = await debugExecutor.execute(
36-
filePath,
37-
problemTypes[meta!.id]!.testCase.replace(/"/g, '\\"'),
38-
meta!.lang
39-
);
34+
if (testcase != undefined) {
35+
result = await debugService.execute(filePath, testcase.replace(/"/g, '\\"'), meta!.lang);
4036
} else {
4137
const ts: string | undefined = await window.showInputBox({
4238
prompt: "Enter the test cases.",
@@ -46,7 +42,7 @@ class DebugContorller {
4642
ignoreFocusOut: true,
4743
});
4844
if (ts) {
49-
result = await debugExecutor.execute(filePath, ts.replace(/"/g, '\\"'), meta!.lang);
45+
result = await debugService.execute(filePath, ts.replace(/"/g, '\\"'), meta!.lang);
5046
}
5147
}
5248

src/debug/debugExecutor.ts

-187
This file was deleted.

src/debugex/debugBase.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export interface IDebug {
2+
execute(filePath: string, testString: string, language: string, port: number): Promise<string | undefined>;
3+
}
4+
5+
export class DebugBase implements IDebug {
6+
constructor() {}
7+
public async execute(
8+
filePath: string,
9+
testString: string,
10+
language: string,
11+
port: number
12+
): Promise<string | undefined> {
13+
throw new Error(`Method not implemented. ${filePath}, ${testString}, ${language}, ${port}`);
14+
}
15+
}

src/debug/executor/cppExecutor.ts renamed to src/debugex/debugCpp.ts

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as fse from "fs-extra";
22
import * as path from "path";
33
import * as vscode from "vscode";
4-
import { logOutput } from "../../utils/OutputUtils";
4+
import { logOutput } from "../utils/OutputUtils";
55

6-
import { executeCommand } from "../../utils/CliUtils";
6+
import { executeCommand } from "../utils/CliUtils";
77
import {
88
fileMeta,
99
getEntryFile,
@@ -12,10 +12,12 @@ import {
1212
extensionState,
1313
IDebugConfig,
1414
IProblemType,
15-
} from "../../utils/problemUtils";
15+
} from "../utils/problemUtils";
1616

17-
import problemTypes from "../../utils/problemTypes";
18-
import { isWindows } from "../../utils/SystemUtils";
17+
import problemTypes from "../utils/problemTypes";
18+
import { isWindows } from "../utils/SystemUtils";
19+
20+
import { DebugBase } from "../debugex/debugBase";
1921

2022
function getGdbDefaultConfig(): IDebugConfig {
2123
return {
@@ -53,7 +55,7 @@ function getTemplateId(id: string): string {
5355
return findKey ? findKey : id;
5456
}
5557

56-
class CppExecutor {
58+
class DebugCpp extends DebugBase {
5759
public async execute(
5860
filePath: string,
5961
testString: string,
@@ -83,16 +85,10 @@ class CppExecutor {
8385
const commonImplementName: string = `common${language}problem${meta.id}.cpp`;
8486

8587
// check whether module.exports is exist or not
86-
const moduleExportsReg: RegExp = /\/\/ @before-stub-for-debug-begin/;
88+
const moduleExportsReg: RegExp = /\/\/ @lcpr-before-debug-begin/;
8789
if (!moduleExportsReg.test(sourceFileContent)) {
8890
const newContent: string =
89-
`// @before-stub-for-debug-begin
90-
91-
92-
93-
94-
95-
// @before-stub-for-debug-end\n\n` + sourceFileContent;
91+
`// @lcpr-before-debug-begin\n\n\n\n\n// @lcpr-before-debug-end\n\n` + sourceFileContent;
9692
await fse.writeFile(filePath, newContent);
9793

9894
// create source file for build because g++ does not support inlucde file with chinese name
@@ -101,12 +97,19 @@ class CppExecutor {
10197
await fse.writeFile(newSourceFilePath, sourceFileContent);
10298
}
10399

104-
const params: string[] = testString.split("\\n");
100+
let params: string[] = testString.split("\\n");
105101
const paramsType: string[] = problemType.paramTypes;
106-
if (params.length !== paramsType.length) {
102+
103+
// 参数不够就不行
104+
105+
if (params.length < paramsType.length) {
107106
vscode.window.showErrorMessage("Input parameters is not match the problem!");
108107
return;
109108
}
109+
// 参数太多舍弃
110+
if (params.length < paramsType.length) {
111+
params = params.slice(0, paramsType.length);
112+
}
110113

111114
const templateId: string = getTemplateId(meta.id);
112115

@@ -203,7 +206,7 @@ class CppExecutor {
203206
const extDir: string = vscode.extensions.getExtension("ccagml.vscode-leetcode-problem-rating")!.extensionPath;
204207

205208
// copy common.h
206-
const commonHeaderPath: string = path.join(extDir, "src/debug/entry/cpp/problems/common.h");
209+
const commonHeaderPath: string = path.join(extDir, "resources/debug/entry/cpp/problems/common.h");
207210
const commonHeaderContent: string = (await fse.readFile(commonHeaderPath)).toString();
208211
const commonHeaderDestPath: string = path.join(extensionState.cachePath, commonHeaderName);
209212

@@ -214,7 +217,7 @@ class CppExecutor {
214217
);
215218

216219
// copy common.cpp
217-
const commonPath: string = path.join(extDir, "src/debug/entry/cpp/problems/common.cpp");
220+
const commonPath: string = path.join(extDir, "resources/debug/entry/cpp/problems/common.cpp");
218221
const commonContent: string = (await fse.readFile(commonPath))
219222
.toString()
220223
.replace(includeFileRegExp, `#include "${commonHeaderName}"`);
@@ -227,8 +230,8 @@ class CppExecutor {
227230
);
228231

229232
const exePath: string = path.join(extensionState.cachePath, `${language}problem${meta.id}.exe`);
230-
const thirdPartyPath: string = path.join(extDir, "src/debug/thirdparty/c");
231-
const jsonPath: string = path.join(extDir, "src/debug/thirdparty/c/cJSON.c");
233+
const thirdPartyPath: string = path.join(extDir, "resources/debug/thirdparty/c");
234+
const jsonPath: string = path.join(extDir, "resources/debug/thirdparty/c/cJSON.c");
232235

233236
const compiler = vscode.workspace.getConfiguration("debug-leetcode").get<string>("cppCompiler") ?? "gdb";
234237
let debugConfig: any;
@@ -442,4 +445,4 @@ class CppExecutor {
442445
}
443446
}
444447

445-
export const cppExecutor: CppExecutor = new CppExecutor();
448+
export const debugCpp: DebugCpp = new DebugCpp();

src/debugex/debugJs.ts

Whitespace-only changes.

src/debugex/debugPy3.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)