From 9ae7249ee2f98288a19490f4b695c7d42e5764c5 Mon Sep 17 00:00:00 2001 From: Ilia Permiashkin Date: Fri, 14 Aug 2026 15:30:33 +0000 Subject: [PATCH] [grazie] IJPL-252933 Better handling of words that don't have suggestions in cloud Merge-request: IJ-MR-218532 Merged-by: Ilia Permiashkin Merge-request: IJ-MR-218560 Merged-by: Ilia Permiashkin GitOrigin-RevId: 80e1a10b05d7650a85d611fb700e29afab9b543c --- .../grazie/spellcheck/SpellingTextChecker.kt | 22 +++++++++---------- ...ckingTest.kt => CloudSpellcheckingTest.kt} | 11 +++++++++- 2 files changed, 20 insertions(+), 13 deletions(-) rename plugins/grazie/src/tests.pro/testSrc/com/intellij/grazie/pro/{CloudTextLevelSpellcheckingTest.kt => CloudSpellcheckingTest.kt} (84%) diff --git a/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/SpellingTextChecker.kt b/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/SpellingTextChecker.kt index d7cf6d3c61d1..b7e1ea9f9767 100644 --- a/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/SpellingTextChecker.kt +++ b/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/SpellingTextChecker.kt @@ -27,7 +27,6 @@ import com.intellij.grazie.utils.EXTRACTOR_SOURCE import com.intellij.grazie.utils.NaturalTextDetector import com.intellij.grazie.utils.getGrazieTracker import com.intellij.grazie.utils.getProblems -import com.intellij.grazie.utils.toLinkedSet import com.intellij.grazie.utils.toSpellingProblems import com.intellij.openapi.Disposable import com.intellij.openapi.components.Service @@ -199,20 +198,19 @@ internal class SpellingTextChecker : ExternalTextChecker() { } private fun toCloudProblems(context: ProofreadingContext, problems: List, manager: SpellCheckerManager): List = - problems - .mapNotNull { - val parts = it.fixes.flatMap { fix -> fix.parts.toList() } + problems.mapNotNull { problem -> + val range = problem.highlighting.always.single() + val word = range.substring(context.text.toString()) + if (!manager.hasProblem(word)) return@mapNotNull null + + TypoProblem(context.text, range, word, true) { + problem.fixes.asSequence() + .flatMap { fix -> fix.parts.toList() } .filterIsInstance() .filter { part -> part.type == ProblemFix.Part.Change.ChangeType.REPLACE } - if (parts.isEmpty()) return@mapNotNull null - - val word = parts.first().range.substring(context.text.toString()) - if (!manager.hasProblem(word)) return@mapNotNull null - - TypoProblem(context.text, parts.first().range, word, true) { - parts.map { part -> part.text }.toLinkedSet() - } + .mapTo(LinkedHashSet()) { part -> part.text } } + } private fun checkText(context: ProofreadingContext, project: Project): List { val textSpeller = getTextSpeller(project) ?: return emptyList() diff --git a/plugins/grazie/src/tests.pro/testSrc/com/intellij/grazie/pro/CloudTextLevelSpellcheckingTest.kt b/plugins/grazie/src/tests.pro/testSrc/com/intellij/grazie/pro/CloudSpellcheckingTest.kt similarity index 84% rename from plugins/grazie/src/tests.pro/testSrc/com/intellij/grazie/pro/CloudTextLevelSpellcheckingTest.kt rename to plugins/grazie/src/tests.pro/testSrc/com/intellij/grazie/pro/CloudSpellcheckingTest.kt index 71a716616f8d..c3bd44d9eaaf 100644 --- a/plugins/grazie/src/tests.pro/testSrc/com/intellij/grazie/pro/CloudTextLevelSpellcheckingTest.kt +++ b/plugins/grazie/src/tests.pro/testSrc/com/intellij/grazie/pro/CloudSpellcheckingTest.kt @@ -6,7 +6,7 @@ import com.intellij.grazie.spellcheck.GrazieSpellCheckingInspection import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -class CloudTextLevelSpellcheckingTest: BaseTestCase() { +class CloudSpellcheckingTest: BaseTestCase() { @BeforeEach fun setUp() { myFixture.enableInspections(GrazieSpellCheckingInspection()) @@ -49,4 +49,13 @@ class CloudTextLevelSpellcheckingTest: BaseTestCase() { """.trimIndent()) myFixture.checkHighlighting() } + + @NeedsCloud + @Test + fun `test typos without suggestions are highlighted`() { + myFixture.configureByText("a.md", """ + English text about asdkjasjdhasjdasjdhajdzxc + """.trimIndent()) + myFixture.checkHighlighting() + } } \ No newline at end of file