Skip to content

Commit 5884eb5

Browse files
committed
feat: allow turning off automatic creation of class body when creating a new java file
Signed-off-by: Fred Bricon <fbricon@gmail.com>
1 parent 05e0324 commit 5884eb5

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ The following settings are supported:
263263
* `java.hover.javadoc.enabled` : Enable/disable displaying Javadoc on hover. Defaults to `true`.
264264

265265
New in 1.53.0
266+
* `java.templates.newFile.enabled` : Enable/disable automatic generation of class body and package declaration when creating a new Java file. Set to `false` to create empty Java files. Defaults to `true`.
266267
* `java.updateImportsOnPaste.enabled` : Enable/disable auto organize imports when pasting code. Defaults to `true`.
267268

268269
Semantic Highlighting

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,13 @@
11911191
"title": "Code Generation",
11921192
"order": 100,
11931193
"properties": {
1194+
"java.templates.newFile.enabled": {
1195+
"type": "boolean",
1196+
"default": true,
1197+
"markdownDescription": "Enable/disable automatic generation of class body and package declaration when creating a new Java file. Set to `false` to create empty Java files. Defaults to `true`.",
1198+
"scope": "window",
1199+
"order": 5
1200+
},
11941201
"java.templates.fileHeader": {
11951202
"type": "array",
11961203
"markdownDescription": "Specifies the file header comment for new Java file. Supports configuring multi-line comments with an array of strings, and using ${variable} to reference the [predefined variables](command:_java.templateVariables).",

src/fileEventHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export function registerFileEventHandlers(client: LanguageClient, context: Exten
4747
}
4848

4949
async function handleNewJavaFiles(e: FileCreateEvent) {
50+
if (!getJavaConfiguration().get<boolean>('templates.newFile.enabled', true)) {
51+
return;
52+
}
5053
const emptyFiles: Uri[] = [];
5154
const textDocuments: TextDocument[] = [];
5255
for (const uri of e.files) {

0 commit comments

Comments
 (0)