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

Merged
merged 5 commits into from
Jan 21, 2025
Merged
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
Binary file added docs/img/javaTemplate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/templateSettings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 like 'class 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