User: rednesto Date: 28 Apr 23 11:14 Revision: 5811a2656009472bd12b375d46165bd9c31ee4c4 Summary: Search for i18n refs under background progress TeamCity URL: http://ci.mcdev.io:80/viewModification.html?tab=vcsModificationFiles&modId=8450&personal=false Index: src/main/kotlin/translations/reference/TranslationReferenceSearch.kt =================================================================== --- src/main/kotlin/translations/reference/TranslationReferenceSearch.kt (revision b49edfa1fab932d25ce11788387c2f1ad975302b) +++ src/main/kotlin/translations/reference/TranslationReferenceSearch.kt (revision 5811a2656009472bd12b375d46165bd9c31ee4c4) @@ -14,12 +14,17 @@ import com.intellij.find.FindModel import com.intellij.find.impl.FindInProjectUtil import com.intellij.openapi.application.runReadAction +import com.intellij.openapi.progress.ProgressIndicator +import com.intellij.openapi.progress.ProgressManager +import com.intellij.openapi.progress.Task +import com.intellij.openapi.progress.util.ProgressIndicatorBase import com.intellij.psi.PsiReference import com.intellij.psi.search.searches.ReferencesSearch import com.intellij.usages.FindUsagesProcessPresentation import com.intellij.usages.UsageViewPresentation import com.intellij.util.Processor import com.intellij.util.QueryExecutor +import java.util.concurrent.CompletableFuture class TranslationReferenceSearch : QueryExecutor { override fun execute(parameters: ReferencesSearch.SearchParameters, consumer: Processor): Boolean { @@ -48,24 +53,31 @@ .filter { it.isNotEmpty() } .joinToString("|") { "(${Regex.escape(it)})" } - runReadAction { + val future = CompletableFuture() + ProgressManager.getInstance().runProcessWithProgressAsynchronously( + object : Task.Backgroundable(parameters.project, "Searching for references", true) { + override fun run(indicator: ProgressIndicator) { - FindInProjectUtil.findUsages( - model, - parameters.project, - { - if (it.file != null && it.element != null && it.rangeInElement != null) { - val highlighted = it.file?.findElementAt(it.rangeInElement!!.startOffset) - val ref = highlighted?.parent?.references - ?.find { ref -> ref is TranslationReference } as TranslationReference? + FindInProjectUtil.findUsages( + model, + parameters.project, + { + if (it.file != null && it.element != null && it.rangeInElement != null) { + val highlighted = it.file?.findElementAt(it.rangeInElement!!.startOffset) + val ref = highlighted?.parent?.references + ?.find { ref -> ref is TranslationReference } as TranslationReference? - if (ref?.key?.full == key) { - consumer.process(ref) + if (ref?.key?.full == key && !consumer.process(ref)) { + future.complete(false) - } - } - true - }, - FindUsagesProcessPresentation(UsageViewPresentation()), - ) + } + } + true + }, + FindUsagesProcessPresentation(UsageViewPresentation()), + ) + future.complete(true) - } + } - return true + }, + ProgressIndicatorBase() + ) + return future.get() } }