From 2d126042816f414078296bc57219dd90f86c5bce Mon Sep 17 00:00:00 2001 From: Ilia Permiashkin Date: Fri, 22 Aug 2025 14:46:15 +0000 Subject: [PATCH] [grazie] Fix highlighting issues downloading missing languages Merge-request: IJ-MR-173274 Merged-by: Ilia Permiashkin GitOrigin-RevId: c656c911c04e42ab2a22ce6bd1c964c4152be689 --- .../kotlin/com/intellij/grazie/GraziePlugin.kt | 17 +++++++---------- .../grazie/GrazieSpellCheckerEngine.kt | 3 +-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/plugins/grazie/src/main/kotlin/com/intellij/grazie/GraziePlugin.kt b/plugins/grazie/src/main/kotlin/com/intellij/grazie/GraziePlugin.kt index a688932ff8e2..b564b1cc7f75 100644 --- a/plugins/grazie/src/main/kotlin/com/intellij/grazie/GraziePlugin.kt +++ b/plugins/grazie/src/main/kotlin/com/intellij/grazie/GraziePlugin.kt @@ -12,8 +12,7 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.extensions.PluginId import com.intellij.openapi.project.ProjectManager import com.intellij.spellchecker.SpellCheckerManager -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch +import kotlinx.coroutines.async import org.jetbrains.annotations.ApiStatus @ApiStatus.Internal @@ -36,17 +35,15 @@ object GraziePlugin { return } - val newLanguages = newState.enabledLanguages.filterHunspell() - val prevLanguages = prevState.enabledLanguages.filterHunspell() - if (prevLanguages == newLanguages) return + GrazieScope.coroutineScope().async { + val newLanguages = newState.enabledLanguages.filterHunspell() + val prevLanguages = prevState.enabledLanguages.filterHunspell() - GrazieScope.coroutineScope().launch(Dispatchers.IO) { ProjectManager.getInstance().openProjects.forEach { project -> val manager = SpellCheckerManager.getInstance(project) - - (newLanguages - prevLanguages).forEach { manager.spellChecker!!.addDictionary(it.dictionary!!) } - (prevLanguages - newLanguages).forEach { prev -> - val dicPath = getLangDynamicFolder(prev).resolve(prev.hunspellRemote!!.file).toString() + newLanguages.forEach { language -> manager.spellChecker!!.addDictionary(language.dictionary!!) } + (prevLanguages - newLanguages).forEach { language -> + val dicPath = getLangDynamicFolder(language).resolve(language.hunspellRemote!!.file).toString() manager.removeDictionary(dicPath) } diff --git a/spellchecker/src/com/intellij/spellchecker/grazie/GrazieSpellCheckerEngine.kt b/spellchecker/src/com/intellij/spellchecker/grazie/GrazieSpellCheckerEngine.kt index 9b103d70c0a0..ec98c48f83f3 100644 --- a/spellchecker/src/com/intellij/spellchecker/grazie/GrazieSpellCheckerEngine.kt +++ b/spellchecker/src/com/intellij/spellchecker/grazie/GrazieSpellCheckerEngine.kt @@ -37,7 +37,6 @@ import com.intellij.spellchecker.grazie.dictionary.ExtendedWordListWithFrequency import com.intellij.spellchecker.grazie.dictionary.WordListAdapter import com.intellij.spellchecker.grazie.ranker.DiacriticSuggestionRanker import com.intellij.spellchecker.hunspell.HunspellDictionary -import com.intellij.spellchecker.inspections.IdentifierSplitter import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.cancel @@ -145,7 +144,7 @@ class GrazieSpellCheckerEngine( } override fun addDictionary(dictionary: Dictionary) { - adapter.addDictionary(dictionary) + if (!isDictionaryLoad(dictionary.name)) adapter.addDictionary(dictionary) } override fun addModifiableDictionary(dictionary: EditableDictionary) {