Skip to content

Commit 7d87414

Browse files
committed
Check the usage flag and language ID in the SqlPostProcessor.kt
1 parent a99ae2c commit 7d87414

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/kotlin/org/domaframework/doma/intellij/formatter/SqlPostProcessor.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import com.intellij.psi.PsiElement
2424
import com.intellij.psi.PsiFile
2525
import com.intellij.psi.codeStyle.CodeStyleSettings
2626
import com.intellij.psi.impl.source.codeStyle.PostFormatProcessor
27+
import org.domaframework.doma.intellij.setting.SqlLanguage
28+
import org.domaframework.doma.intellij.state.DomaToolsFunctionEnableSettings
2729

2830
class SqlPostProcessor : PostFormatProcessor {
2931
override fun processElement(
@@ -36,6 +38,9 @@ class SqlPostProcessor : PostFormatProcessor {
3638
rangeToReformat: TextRange,
3739
settings: CodeStyleSettings,
3840
): TextRange {
41+
if (!isEnableFormat()) return rangeToReformat
42+
if (source.language != SqlLanguage.INSTANCE) return rangeToReformat
43+
3944
val project: Project = source.project
4045
val document = PsiDocumentManager.getInstance(project).getDocument(source) ?: return rangeToReformat
4146

@@ -55,4 +60,10 @@ class SqlPostProcessor : PostFormatProcessor {
5560
}
5661
return TextRange(0, finalText.length)
5762
}
63+
64+
private fun isEnableFormat(): Boolean {
65+
val setting = DomaToolsFunctionEnableSettings.getInstance()
66+
val isEnableFormat = setting.state.isEnableSqlFormat
67+
return isEnableFormat
68+
}
5869
}

0 commit comments

Comments
 (0)