Skip to content

Commit

Permalink
Enhanced Template Java class name substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
KshKnsl committed Jan 11, 2025
1 parent db6d83a commit b5fb4ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/companion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,15 @@ const handleNewProblem = async (problem: Problem) => {
`Template file does not exist: ${templateLocation}`,
);
} else {
const templateContents =
let templateContents =
readFileSync(templateLocation).toString();

if(extn == 'java')

Check failure on line 247 in src/companion.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Replace `(extn·==·'java')⏎···············` with `·(extn·==·'java')`
{
const className = path.basename(problemFileName, '.java');
templateContents = templateContents.replace('CLASS_NAME', className);

Check failure on line 250 in src/companion.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Replace `'CLASS_NAME',·className);` with `⏎························'CLASS_NAME',⏎························className,`
}

Check failure on line 251 in src/companion.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Replace `················}` with `····················);`

Check failure on line 252 in src/companion.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Insert `}⏎`
writeFileSync(srcPath, templateContents);
}
}
Expand Down

0 comments on commit b5fb4ce

Please sign in to comment.