Skip to content

请尝试配置区域调试参数 #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## version 2.15.3

- 原插件不能调试的题目,增加区域调试参数

## version 2.15.2

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

# 关于本项目

Expand Down Expand Up @@ -74,6 +75,55 @@

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

## 区域调试参数的一些说明

### 如果有些题目无法 debug,请尝试配置 diy 参数区

1. 例子 cpp 2544 题为例
```
// @lcpr-div-debug-arg-start
// funName= alternateDigitSum
// paramTypes= ["number"]
// returnType= number
// @lcpr-div-debug-arg-end
```
2. diy 参数说明

- funName:函数名,既本次解决方法的函数名
- paramTypes:函数的输入参数,是一个字符串数组类型
- 可填入内容为以下字符串
- "number"
- 类型说明:数字
- "number[]"
- 类型说明:数字数组
- "number[][]"
- 类型说明:数字二维数组
- "string"
- 类型说明:字符串
- "string[]"
- 类型说明:字符串数组
- "string[][]"
- 类型说明:字符串二维数组
- "ListNode"
- 类型说明:链表
- "ListNode[]"
- 类型说明:链表数组
- "character"
- 类型说明:字节
- "character[]"
- 类型说明:字节数组
- "character[][]"
- 类型说明:字节二维数组
- "NestedInteger[]"
- 类型说明:数组
- "MountainArray"
- 类型说明:数组
- "TreeNode"
- 类型说明:树节点
- returnType:函数的返回值

- 可填入内容同 paramTypes

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

- (完成) 在文件里面插入一些测试用例?
Expand Down
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-leetcode-problem-rating",
"displayName": "LeetCode",
"description": "%main.description%",
"version": "2.15.2",
"version": "2.15.3",
"author": "ccagml",
"publisher": "ccagml",
"license": "MIT",
Expand Down Expand Up @@ -1118,6 +1118,19 @@
"default": 3600,
"scope": "application",
"description": "Open the app to clear the cache interval by default 3600 seconds"
},
"leetcode-problem-rating.cppCompiler": {
"type": "string",
"default": "gdb",
"enum": [
"gdb",
"clang"
],
"enumDescriptions": [
"gdb compiler",
"clang compiler"
],
"scope": "resource"
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions resources/templates/codeonly.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<%=code%>
<%=comment.singleLine%> @lc code=end

<%=comment.singleLine%> @lcpr-div-debug-arg-start
<%=comment.singleLine%> funName= ""
<%=comment.singleLine%> paramTypes= []
<%=comment.singleLine%> returnType= ""
<%=comment.singleLine%> @lcpr-div-debug-arg-end

<% if(allCaseList && allCaseList.length > 0){ %>
<%=comment.start%><% allCaseList.forEach(function(acase) { %>
Expand Down
6 changes: 6 additions & 0 deletions resources/templates/detailed.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<%=code%>
<%=comment.singleLine%> @lc code=end

<%=comment.singleLine%> @lcpr-div-debug-arg-start
<%=comment.singleLine%> funName= ""
<%=comment.singleLine%> paramTypes= []
<%=comment.singleLine%> returnType= ""
<%=comment.singleLine%> @lcpr-div-debug-arg-end

<% if(allCaseList && allCaseList.length > 0){ %>
<%=comment.start%><% allCaseList.forEach(function(acase) { %>
<%=comment.singleLine%> @lcpr case=start
Expand Down
30 changes: 21 additions & 9 deletions src/controller/DebugController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,45 @@
* Copyright (c) 2023 ccagml . All rights reserved
*/

import { Uri, window } from "vscode";
import { TextDocument, window } from "vscode";
import { getTextEditorFilePathByUri } from "../utils/SystemUtils";
import * as fs from "fs";
import { fileMeta, ProblemMeta, canDebug } from "../utils/problemUtils";
// import problemTypes from "../utils/problemTypes";
import { fileMeta, ProblemMeta, supportDebugLanguages } from "../utils/problemUtils";

import { debugService } from "../service/DebugService";
import { debugArgDao } from "../dao/debugArgDao";

// 做杂活
class DebugContorller {
constructor() {}
public canDebug(meta: ProblemMeta | null, document: TextDocument) {
if (
meta == null ||
supportDebugLanguages.indexOf(meta.lang) === -1 ||
debugArgDao.getDebugArgData(meta.id, document) == undefined
) {
return false;
}
return true;
}

public async startDebug(uri: Uri, testcase?: string): Promise<void> {
public async startDebug(document: TextDocument, testcase?: string): Promise<void> {
try {
const filePath: string | undefined = await getTextEditorFilePathByUri(uri);
const filePath: string | undefined = await getTextEditorFilePathByUri(document.uri);
if (!filePath) {
return;
}
const fileContent: Buffer = fs.readFileSync(filePath);
const meta: ProblemMeta | null = fileMeta(fileContent.toString());
if (!canDebug(meta)) {
window.showErrorMessage("这题还不能debug 麻烦提issuse");

if (!this.canDebug(meta, document)) {
window.showErrorMessage("这题还不能debug,请尝试配置区域调试参数,麻烦提issuse");
return;
}
let result: any;

if (testcase != undefined) {
result = await debugService.execute(filePath, testcase.replace(/"/g, '\\"'), meta!.lang);
result = await debugService.execute(document, filePath, testcase.replace(/"/g, '\\"'), meta!.lang);
} else {
const ts: string | undefined = await window.showInputBox({
prompt: "Enter the test cases.",
Expand All @@ -43,7 +55,7 @@ class DebugContorller {
ignoreFocusOut: true,
});
if (ts) {
result = await debugService.execute(filePath, ts.replace(/"/g, '\\"'), meta!.lang);
result = await debugService.execute(document, filePath, ts.replace(/"/g, '\\"'), meta!.lang);
}
}

Expand Down
Loading