Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced Template Java class name substitution #522

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 9 additions & 1 deletion src/companion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Loading