|
7 | 7 | * Copyright (c) 2023 ccagml . All rights reserved
|
8 | 8 | */
|
9 | 9 |
|
10 |
| -import { TextDocument, window } from "vscode"; |
| 10 | +import { TextDocument, window, Range } from "vscode"; |
11 | 11 | import { getTextEditorFilePathByUri } from "../utils/SystemUtils";
|
12 | 12 | import * as fs from "fs";
|
13 | 13 | import { fileMeta, ProblemMeta, supportDebugLanguages } from "../utils/problemUtils";
|
14 | 14 |
|
15 | 15 | import { debugService } from "../service/DebugService";
|
16 | 16 | import { debugArgDao } from "../dao/debugArgDao";
|
17 | 17 |
|
| 18 | +import { IQuickItemEx } from "../model/Model"; |
| 19 | + |
18 | 20 | // 做杂活
|
19 | 21 | class DebugContorller {
|
20 | 22 | constructor() {}
|
@@ -66,6 +68,122 @@ class DebugContorller {
|
66 | 68 | //
|
67 | 69 | }
|
68 | 70 | }
|
| 71 | + |
| 72 | + public async addDebugType(document: TextDocument, addType) { |
| 73 | + const picks: Array<IQuickItemEx<string>> = [ |
| 74 | + { label: "number", detail: "类型说明:数字", value: "number" }, |
| 75 | + { label: "number[]", detail: "类型说明:数字数组", value: "number[]" }, |
| 76 | + { label: "number[][]", detail: "类型说明:数字二维数组", value: "number[][]" }, |
| 77 | + { label: "string", detail: "类型说明:字符串", value: "string" }, |
| 78 | + { label: "string[]", detail: "类型说明:字符串数组", value: "string[]" }, |
| 79 | + { label: "string[][]", detail: "类型说明:字符串二维数组", value: "string[][]" }, |
| 80 | + { label: "ListNode", detail: "类型说明:链表", value: "ListNode" }, |
| 81 | + { label: "ListNode[]", detail: "类型说明:链表数组", value: "ListNode[]" }, |
| 82 | + { label: "character", detail: "类型说明:字节", value: "character" }, |
| 83 | + { label: "character[]", detail: "类型说明:字节数组", value: "character[]" }, |
| 84 | + { label: "character[][]", detail: "类型说明:字节二维数组", value: "character[][]" }, |
| 85 | + { label: "NestedInteger[]", detail: "类型说明:数组", value: "NestedInteger[]" }, |
| 86 | + { label: "MountainArray", detail: "类型说明:数组", value: "MountainArray" }, |
| 87 | + { label: "TreeNode", detail: "类型说明:树节点", value: "TreeNode" }, |
| 88 | + ]; |
| 89 | + |
| 90 | + const choice: IQuickItemEx<string> | undefined = await window.showQuickPick(picks, { |
| 91 | + title: "添加调试需要的参数", |
| 92 | + matchOnDescription: false, |
| 93 | + matchOnDetail: false, |
| 94 | + placeHolder: "选择要添加的分类", |
| 95 | + canPickMany: false, |
| 96 | + }); |
| 97 | + if (!choice) { |
| 98 | + return; |
| 99 | + } |
| 100 | + |
| 101 | + const content: string = document.getText(); |
| 102 | + const matchResult: RegExpMatchArray | null = content.match(/@lc app=.* id=(.*) lang=(.*)/); |
| 103 | + if (!matchResult || !matchResult[2]) { |
| 104 | + return undefined; |
| 105 | + } |
| 106 | + // 搜集所有debug |
| 107 | + let debugFlag: boolean = false; |
| 108 | + for (let i: number = 0; i < document.lineCount; i++) { |
| 109 | + const lineContent: string = document.lineAt(i).text; |
| 110 | + |
| 111 | + // 收集所有用例 |
| 112 | + if (lineContent.indexOf("@lcpr-div-debug-arg-end") >= 0) { |
| 113 | + debugFlag = false; |
| 114 | + } |
| 115 | + |
| 116 | + if (debugFlag) { |
| 117 | + let equal_index = lineContent.indexOf("="); |
| 118 | + const last_index = document.lineAt(i).range.end.character; |
| 119 | + if (addType == "paramTypes" && lineContent.indexOf("paramTypes=") >= 0) { |
| 120 | + window.activeTextEditor?.edit((edit) => { |
| 121 | + // 参数是个数组; |
| 122 | + // edit.replace(new Position(i, equal_index + 1), choice.value); |
| 123 | + let cur_param_str = lineContent.substring(equal_index + 1); |
| 124 | + let cur_param_array: any = []; |
| 125 | + try { |
| 126 | + cur_param_array = JSON.parse(cur_param_str); |
| 127 | + } catch (error) { |
| 128 | + cur_param_array = []; |
| 129 | + } |
| 130 | + |
| 131 | + cur_param_array.push(choice.value); |
| 132 | + |
| 133 | + edit.replace(new Range(i, equal_index + 1, i, last_index), JSON.stringify(cur_param_array)); |
| 134 | + }); |
| 135 | + } else if (addType == "returnType" && lineContent.indexOf("returnType=") >= 0) { |
| 136 | + window.activeTextEditor?.edit((edit) => { |
| 137 | + edit.replace(new Range(i, equal_index + 1, i, last_index), choice.value); |
| 138 | + }); |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + // 收集所有用例 |
| 143 | + if (lineContent.indexOf("@lcpr-div-debug-arg-start") >= 0) { |
| 144 | + debugFlag = true; |
| 145 | + } |
| 146 | + } |
| 147 | + return; |
| 148 | + } |
| 149 | + public async resetDebugType(document: TextDocument, addType) { |
| 150 | + const content: string = document.getText(); |
| 151 | + const matchResult: RegExpMatchArray | null = content.match(/@lc app=.* id=(.*) lang=(.*)/); |
| 152 | + if (!matchResult || !matchResult[2]) { |
| 153 | + return undefined; |
| 154 | + } |
| 155 | + // 搜集所有debug |
| 156 | + let debugFlag: boolean = false; |
| 157 | + for (let i: number = 0; i < document.lineCount; i++) { |
| 158 | + const lineContent: string = document.lineAt(i).text; |
| 159 | + |
| 160 | + // 收集所有用例 |
| 161 | + if (lineContent.indexOf("@lcpr-div-debug-arg-end") >= 0) { |
| 162 | + debugFlag = false; |
| 163 | + } |
| 164 | + |
| 165 | + if (debugFlag) { |
| 166 | + let equal_index = lineContent.indexOf("="); |
| 167 | + const last_index = document.lineAt(i).range.end.character; |
| 168 | + if (addType == "paramTypes" && lineContent.indexOf("paramTypes=") >= 0) { |
| 169 | + window.activeTextEditor?.edit((edit) => { |
| 170 | + let cur_param_array: any = []; |
| 171 | + edit.replace(new Range(i, equal_index + 1, i, last_index), JSON.stringify(cur_param_array)); |
| 172 | + }); |
| 173 | + } else if (addType == "returnType" && lineContent.indexOf("returnType=") >= 0) { |
| 174 | + window.activeTextEditor?.edit((edit) => { |
| 175 | + edit.replace(new Range(i, equal_index + 1, i, last_index), ""); |
| 176 | + }); |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + // 收集所有用例 |
| 181 | + if (lineContent.indexOf("@lcpr-div-debug-arg-start") >= 0) { |
| 182 | + debugFlag = true; |
| 183 | + } |
| 184 | + } |
| 185 | + return; |
| 186 | + } |
69 | 187 | }
|
70 | 188 |
|
71 | 189 | export const debugContorller: DebugContorller = new DebugContorller();
|
0 commit comments