Skip to content

Commit 47257cb

Browse files
committed
fix: commit the document after each applied quick fix
1 parent f96293b commit 47257cb

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/main/kotlin/com/github/lppedd/cc/inspection/CommitFormatInspection.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.github.lppedd.cc.language.psi.ConventionalCommitPsiElementVisitor
99
import com.github.lppedd.cc.language.psi.ConventionalCommitScopePsiElement
1010
import com.github.lppedd.cc.language.psi.ConventionalCommitSubjectPsiElement
1111
import com.github.lppedd.cc.language.psi.ConventionalCommitTypePsiElement
12+
import com.intellij.codeInspection.InspectionManager
1213
import com.intellij.codeInspection.ProblemDescriptor
1314
import com.intellij.codeInspection.ProblemHighlightType.GENERIC_ERROR_OR_WARNING
1415
import 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

Comments
 (0)