diff --git a/docs/img/javaTemplate.png b/docs/img/javaTemplate.png new file mode 100644 index 0000000..4de0796 Binary files /dev/null and b/docs/img/javaTemplate.png differ diff --git a/docs/img/templateSettings.png b/docs/img/templateSettings.png new file mode 100644 index 0000000..df69e9b Binary files /dev/null and b/docs/img/templateSettings.png differ diff --git a/docs/user-guide.md b/docs/user-guide.md index caf9350..8ec6264 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -105,6 +105,14 @@ Several options are available to customize the extension. Open VS Code settings down during codeforces submission. - [Python] Command used to run python files. For eg. py, python3, pypy3, etc. +## Default Language Templates +- The path of the template that will be loaded when a new file of the default language is created by Competitive Companion +- For Java Users, the template shall be in the format where class name is `CLASS_NAME` as the file name so that CLASS_NAME in the code gets auto replaced. +\ +![Templates](img/templateSettings.png) +![Templates](img/javaTemplate.png) + + ## Getting help If you have trouble using the extension, find any bugs, or want to request a new diff --git a/package.json b/package.json index f1b6687..8ec1dd4 100644 --- a/package.json +++ b/package.json @@ -349,7 +349,7 @@ "cph.general.defaultLanguageTemplateFileLocation": { "type": "string", "default": "", - "description": "The path of the template that will be loaded when a new file of the default language is created by Competitive Companion" + "description": "The path to the template file that will be used when creating a new file for the default language via Competitive Companion. For Java templates, use 'CLASS_NAME' as a placeholder for the class name like 'class CLASS_NAME{...}'" }, "cph.general.autoShowJudge": { "type": "boolean", diff --git a/src/companion.ts b/src/companion.ts index 276f38b..08d79a9 100644 --- a/src/companion.ts +++ b/src/companion.ts @@ -241,8 +241,16 @@ const handleNewProblem = async (problem: Problem) => { `Template file does not exist: ${templateLocation}`, ); } else { - const templateContents = + let templateContents = readFileSync(templateLocation).toString(); + + if (extn == 'java') { + const className = path.basename(problemFileName, '.java'); + templateContents = templateContents.replace( + 'CLASS_NAME', + className, + ); + } writeFileSync(srcPath, templateContents); } }