@@ -9,6 +9,7 @@ import com.github.lppedd.cc.language.psi.ConventionalCommitPsiElementVisitor
99import com.github.lppedd.cc.language.psi.ConventionalCommitScopePsiElement
1010import com.github.lppedd.cc.language.psi.ConventionalCommitSubjectPsiElement
1111import com.github.lppedd.cc.language.psi.ConventionalCommitTypePsiElement
12+ import com.intellij.codeInspection.InspectionManager
1213import com.intellij.codeInspection.ProblemDescriptor
1314import com.intellij.codeInspection.ProblemHighlightType.GENERIC_ERROR_OR_WARNING
1415import com.intellij.codeInspection.ProblemHighlightType.WARNING
@@ -52,25 +53,29 @@ internal class CommitFormatInspection : CommitBaseInspection() {
5253 collectProblems(project, document).isNotEmpty()
5354
5455 override fun reformat (project : Project , document : Document ) {
56+ val documentManager = project.service<PsiDocumentManager >()
57+
5558 for (problem in collectProblems(project, document)) {
5659 val quickFixes = problem.fixes ? : return
5760
5861 for (fix in quickFixes) {
5962 if (fix is CommitBaseQuickFix ) {
6063 fix.applyFix(project, document, problem)
64+ documentManager.commitDocument(document)
6165 }
6266 }
6367 }
6468 }
6569
66- private fun collectProblems (project : Project , document : Document ): Collection <ProblemDescriptor > {
70+ private fun collectProblems (project : Project , document : Document ): List <ProblemDescriptor > {
6771 if (isInspectionEnabled(document)) {
68- val psiDocumentManager = project.service<PsiDocumentManager >()
69- val psiFile = psiDocumentManager.getPsiFile(document) ? : return emptyList()
70- val holder = ProblemsHolder (project.service(), psiFile, true )
71- val visitor = MyRecursiveVisitor (holder)
72+ val documentManager = project.service<PsiDocumentManager >()
73+ val inspectionManager = project.service<InspectionManager >()
74+ val psiFile = documentManager.getPsiFile(document) ? : return emptyList()
75+ val problemsHolder = ProblemsHolder (inspectionManager, psiFile, true )
76+ val visitor = MyRecursiveVisitor (problemsHolder)
7277 visitor.visitFile(psiFile)
73- return holder .results
78+ return problemsHolder .results
7479 }
7580
7681 return emptyList()
0 commit comments