Skip to content

Commit

Permalink
Support formatting for Idea 2023
Browse files Browse the repository at this point in the history
  • Loading branch information
QwerTech authored and popematt committed May 24, 2023
1 parent 08b37c3 commit 5357052
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.amazon.ion.plugin.intellij.formatting

import com.amazon.ion.plugin.intellij.formatting.blocks.IonBlockOptions
import com.amazon.ion.plugin.intellij.formatting.blocks.RootIonBlock
import com.intellij.formatting.FormattingContext
import com.intellij.formatting.FormattingModel
import com.intellij.formatting.FormattingModelBuilder
import com.intellij.formatting.FormattingModelProvider

/**
* Creates the block model for an Ion file.
*
* The block model will determine how elements are spaced, indented and aligned.
*/
class IonFormattingModelBuilder : FormattingModelBuilder {
override fun createModel(formattingContext: FormattingContext): FormattingModel {
val element = formattingContext.psiElement
val settings = formattingContext.codeStyleSettings

val rootBlock = RootIonBlock(
node = element.node,
options = IonBlockOptions(
spaceBuilder = IonCodeBlockSpacingProvider(settings),
codeStyle = settings
)
)


return FormattingModelProvider.createFormattingModelForPsiFile(
element.containingFile,
rootBlock, settings
)
}
}

0 comments on commit 5357052

Please sign in to comment.