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