[grazie] IJPL-252933 Better handling of words that don't have suggestions in cloud

Merge-request: IJ-MR-218532
Merged-by: Ilia Permiashkin <ilia.permiashkin@jetbrains.com>

Merge-request: IJ-MR-218560
Merged-by: Ilia Permiashkin <ilia.permiashkin@jetbrains.com>

GitOrigin-RevId: 80e1a10b05d7650a85d611fb700e29afab9b543c
This commit is contained in:
Ilia Permiashkin
2026-08-14 15:30:33 +00:00
committed by intellij-monorepo-bot
parent ec5e10adf0
commit 9ae7249ee2
2 changed files with 20 additions and 13 deletions
@@ -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<Problem>, manager: SpellCheckerManager): List<TypoProblem> =
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<ProblemFix.Part.Change>()
.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<Typo> {
val textSpeller = getTextSpeller(project) ?: return emptyList()
@@ -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 <TYPO descr="Typo: In word 'asdkjasjdhasjdasjdhajdzxc'">asdkjasjdhasjdasjdhajdzxc</TYPO>
""".trimIndent())
myFixture.checkHighlighting()
}
}