Skip to content

Commit

Permalink
Reformat created files without keeping line breaks
Browse files Browse the repository at this point in the history
Fixes #2330
  • Loading branch information
RedNesto committed Jul 15, 2024
1 parent 96a55b2 commit c58995f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/kotlin/creator/custom/CustomPlatformStep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c58995f

Please sign in to comment.