diff --git a/package.json b/package.json index 385dad5..8098487 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." }, "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); } }