[local] Added commit message spell checking(IJPL-245329)

(cherry picked from commit f8851506317da03b6610c1f5f061b860107b30b2)

GitOrigin-RevId: a58923c450d1810a3af02c2d6b92cbc9633c4f2f
This commit is contained in:
natalia.ponomareva
2026-07-21 14:25:56 +00:00
committed by intellij-monorepo-bot
parent fb3797d0d9
commit 4caf0c335c
2 changed files with 35 additions and 2 deletions
@@ -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<SpellCheckingScope> 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();
}
@@ -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, "<TYPO descr=\"Typo: In word 'typopo'\">typopo</TYPO> [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<GrazieCheckers>().awaitConfiguration()
// No <TYPO> 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()
}
}