8000 enrich the code template. · RinChanNOWWW/vscode-leetcode@141eef7 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 141eef7

Browse files
committed
enrich the code template.
Now I can add some custom codes at the top of the file.
1 parent d713ad5 commit 141eef7

File t 8000 ree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

package.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "vscode-leetcode",
3-
"displayName": "LeetCode",
2+
"name": "vscode-leetcode-kai",
3+
"displayName": "LeetCode-kai",
44
"description": "Solve LeetCode problems in VS Code",
5-
"version": "0.18.1",
6-
"author": "Sheng Chen",
5+
"version": "0.18.0-kai-by-rcn",
6+
"author": "Sheng Chen (Modified by RinChanNOWWW)",
77
"publisher": "LeetCode",
88
"license": "MIT",
99
"icon": "resources/LeetCode.png",
@@ -700,6 +700,14 @@
700700
"Acceptance Rate (Descending)"
701701
],
702702
"description": "Sorting strategy for problems list."
703+
},
704+
"leetcode.header": {
705+
"type": "array",
706+
"items": {
707+
"type": "string"
708+
},
709+
"scope": "application",
710+
"description": "Add your custom codes at the top of source files."
703711
}
704712
}
705713
}

src/commands/show.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ async function showProblemInternal(node: IProblem): Promise<void> {
170170
const descriptionConfig: IDescriptionConfiguration = settingUtils.getDescriptionConfiguration();
171171
const needTranslation: boolean = settingUtils.shouldUseEndpointTranslation();
172172

173-
await leetCodeExecutor.showProblem(node, language, finalPath, descriptionConfig.showInComment, needTranslation);
173+
const header: string[] = leetCodeConfig.get<string[]>("header", []);
174+
let header_str: string = header.join("\n").trim();
175+
if (header_str.length > 0) {
176+
header_str += "\n";
177+
}
178+
await leetCodeExecutor.showProblem(node, language, finalPath, descriptionConfig.showInComment, needTranslation, header_str);
174179
const promises: any[] = [
175180
vscode.window.showTextDocument(vscode.Uri.file(finalPath), { preview: false, viewColumn: vscode.ViewColumn.One }),
176181
promptHintMessage(

src/leetCodeExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class LeetCodeExecutor implements Disposable {
100100
return await this.executeCommandEx(this.nodeExecutable, cmd);
101101
}
102102

103-
public async showProblem(problemNode: IProblem, language: string, filePath: string, showDescriptionInComment: boolean = false, needTranslation: boolean): Promise<void> {
103+
public async showProblem(problemNode: IProblem, language: string, filePath: string, showDescriptionInComment: boolean = false, needTranslation: boolean, header: string = ""): Promise<void> {
104104
const templateType: string = showDescriptionInComment ? "-cx" : "-c";
105105
const cmd: string[] = [await this.getLeetCodeBinaryPath(), "show", problemNode.id, templateType, "-l", language];
106106

@@ -111,7 +111,7 @@ class LeetCodeExecutor implements Disposable {
111111
if (!await fse.pathExists(filePath)) {
112112
await fse.createFile(filePath);
113113
const codeTemplate: string = await this.executeCommandWithProgressEx("Fetching problem data...", this.nodeExecutable, cmd);
114-
await fse.writeFile(filePath, codeTemplate);
114+
await fse.writeFile(filePath, header + codeTemplate);
115115
}
116116
}
117117

0 commit comments

Comments
 (0)
0