From c58995f6b632d2df66c6a2b741e6a46d7fdaa3c2 Mon Sep 17 00:00:00 2001 From: RedNesto Date: Mon, 15 Jul 2024 16:49:37 +0200 Subject: [PATCH] Reformat created files without keeping line breaks Fixes #2330 --- .../kotlin/creator/custom/CustomPlatformStep.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/creator/custom/CustomPlatformStep.kt b/src/main/kotlin/creator/custom/CustomPlatformStep.kt index 6d54cab04..edf57b332 100644 --- a/src/main/kotlin/creator/custom/CustomPlatformStep.kt +++ b/src/main/kotlin/creator/custom/CustomPlatformStep.kt @@ -32,6 +32,7 @@ import com.demonwav.mcdev.creator.custom.types.ExternalCreatorProperty import com.demonwav.mcdev.creator.modalityState import com.demonwav.mcdev.util.toTypedArray import com.demonwav.mcdev.util.virtualFileOrError +import com.intellij.codeInsight.CodeInsightSettings import com.intellij.codeInsight.actions.ReformatCodeProcessor import com.intellij.ide.projectView.ProjectView import com.intellij.ide.wizard.AbstractNewProjectWizardStep @@ -553,7 +554,18 @@ class CustomPlatformStep( val psiFiles = files.asSequence() .filter { (desc, _) -> desc.reformat != false } .mapNotNull { (_, file) -> psiManager.findFile(file) } - ReformatCodeProcessor(project, psiFiles.toTypedArray(), null, false).run() + + val processor = ReformatCodeProcessor(project, psiFiles.toTypedArray(), null, false) + psiFiles.forEach(processor::setDoNotKeepLineBreaks) + + val insightSettings = CodeInsightSettings.getInstance() + val oldSecondReformat = insightSettings.ENABLE_SECOND_REFORMAT + insightSettings.ENABLE_SECOND_REFORMAT = true + try { + processor.run() + } finally { + insightSettings.ENABLE_SECOND_REFORMAT = oldSecondReformat + } } private fun openFilesInEditor(