From 4caf0c335c9c5529cf718aa4df3e36a98f3317bc Mon Sep 17 00:00:00 2001 From: "natalia.ponomareva" Date: Mon, 22 Jun 2026 18:00:46 +0200 Subject: [PATCH] [local] Added commit message spell checking(IJPL-245329) (cherry picked from commit f8851506317da03b6610c1f5f061b860107b30b2) GitOrigin-RevId: a58923c450d1810a3af02c2d6b92cbc9633c4f2f --- .../GrazieSpellCheckingInspection.java | 10 +++++-- .../grazie/ide/language/CommitSupportTest.kt | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/GrazieSpellCheckingInspection.java b/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/GrazieSpellCheckingInspection.java index bf50df56d57a..ca7bc30c09bb 100644 --- a/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/GrazieSpellCheckingInspection.java +++ b/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/GrazieSpellCheckingInspection.java @@ -51,6 +51,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.EnumSet; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -72,8 +73,13 @@ public final class GrazieSpellCheckingInspection extends SpellCheckingInspection private static final AtomicBoolean IS_LOGGED = new AtomicBoolean(false); public static Set buildAllowedScopes(PsiElement element) { - var tool = getTool(element.getContainingFile(), SPELL_CHECKING_INSPECTION_TOOL_NAME, GrazieSpellCheckingInspection.class); - if (tool == null) return Set.of(); + PsiFile file = element.getContainingFile(); + var tool = getTool(file, SPELL_CHECKING_INSPECTION_TOOL_NAME, GrazieSpellCheckingInspection.class); + if (tool == null) { + // The commit editor uses a restricted profile that omits the spellcheck inspection. + // CommitAnnotator (already gated by the "Commit messages" toggle) drives the check, so allow all scopes. + return CommitMessage.isCommitMessage(file) ? EnumSet.allOf(SpellCheckingScope.class) : Set.of(); + } return tool.buildAllowedScopes(); } diff --git a/plugins/grazie/src/test/kotlin/com/intellij/grazie/ide/language/CommitSupportTest.kt b/plugins/grazie/src/test/kotlin/com/intellij/grazie/ide/language/CommitSupportTest.kt index 0a0c974eada4..b9c5ab45052c 100644 --- a/plugins/grazie/src/test/kotlin/com/intellij/grazie/ide/language/CommitSupportTest.kt +++ b/plugins/grazie/src/test/kotlin/com/intellij/grazie/ide/language/CommitSupportTest.kt @@ -2,11 +2,16 @@ package com.intellij.grazie.ide.language +import com.intellij.codeInspection.ex.InspectionProfileWrapper +import com.intellij.grazie.GrazieConfig import com.intellij.grazie.GrazieTestBase import com.intellij.grazie.jlanguage.Lang +import com.intellij.grazie.spellcheck.GrazieCheckers +import com.intellij.openapi.components.service import com.intellij.openapi.util.Disposer import com.intellij.openapi.vcs.ui.CommitMessage import com.intellij.testFramework.fixtures.CodeInsightTestFixture +import com.intellij.vcs.commit.message.CommitMessageInspectionProfile class CommitSupportTest : GrazieTestBase() { fun `test commit message has highlighting with all quick fixes`() { @@ -46,6 +51,20 @@ class CommitSupportTest : GrazieTestBase() { assertNull(myFixture.getAvailableIntention("Accept all writing suggestions…")) } + fun `test typos are highlighted under the real commit editor inspection profile`() { + checkRealCommitHighlighting(myFixture, "typopo [grazie]: june is here") + } + + fun `test spell checking is skipped when commit message checking is disabled`() { + GrazieConfig.update { state -> + state.copy(checkingContext = state.checkingContext.copy(isCheckInCommitMessagesEnabled = false)) + } + service().awaitConfiguration() + + // No markup: with the "Commit messages" toggle off, CommitAnnotator must not report typos. + checkRealCommitHighlighting(myFixture, "typopo [grazie]: june is here") + } + private fun checkCommitMessage(text: String) { configureCommit(myFixture, text) myFixture.checkHighlighting() @@ -58,3 +77,11 @@ internal fun configureCommit(fixture: CodeInsightTestFixture, text: String) { Disposer.register(fixture.testRootDisposable, commitMessage) fixture.editor.document.putUserData(CommitMessage.DATA_KEY, commitMessage) } + +internal fun checkRealCommitHighlighting(fixture: CodeInsightTestFixture, text: String) { + configureCommit(fixture, text) + InspectionProfileWrapper.runWithCustomInspectionWrapper(fixture.file, + { InspectionProfileWrapper(CommitMessageInspectionProfile.getInstance(fixture.project)) }) { + fixture.checkHighlighting() + } +}