Skip to content

Commit bd79dd8

Browse files
committed
modify the code template
1 parent d713ad5 commit bd79dd8

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

package.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "vscode-leetcode",
3-
"displayName": "LeetCode",
2+
"name": "vscode-leetcode-wzh",
3+
"displayName": "LeetCode-wzh",
44
"description": "Solve LeetCode problems in VS Code",
5-
"version": "0.18.1",
6-
"author": "Sheng Chen",
5+
"version": "0.18.1-wzh",
6+
"author": "Sheng Chen (Modified by wzh)",
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

+6-1
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

+2-2
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)