From faeb98c6667f56bcd99119ce276155bec65a8a3b Mon Sep 17 00:00:00 2001 From: Dmitry Osinovskiy Date: Thu, 10 Apr 2025 15:08:15 +0200 Subject: [PATCH] Action search: make it possible to use from AI GitOrigin-RevId: cdedc88fa44bd6d26679a38615f9ede3b3da3141 --- .../util/gotoByName/ActionAsyncProvider.kt | 43 +++++++++++++++---- .../ide/util/gotoByName/GotoActionModel.java | 2 +- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ActionAsyncProvider.kt b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ActionAsyncProvider.kt index c6b86cd84baa..7f9f082e9fdd 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ActionAsyncProvider.kt +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ActionAsyncProvider.kt @@ -74,18 +74,43 @@ class ActionAsyncProvider(private val model: GotoActionModel) { val actionIds = (actionManager as ActionManagerImpl).actionIds scope.launch { - val abbreviationsJob = processAbbreviations(pattern, presentationProvider, consumer) - - val nonMatchedIdsChannel = Channel(capacity = Channel.UNLIMITED) - val matchedStubsJob = processMatchedActionsAndStubs(pattern, actionIds, presentationProvider, consumer, nonMatchedIdsChannel, abbreviationsJob) - val unmatchedStubsJob = processUnmatchedStubs(nonMatchedIdsChannel, pattern, presentationProvider, consumer, matchedStubsJob) - - val topHitsJob = processTopHits(pattern, presentationProvider, consumer, unmatchedStubsJob) - val intentionsJob = processIntentions(pattern, presentationProvider, consumer, topHitsJob) - processOptions(pattern, presentationProvider, consumer, intentionsJob) + runFilterJobs(presentationProvider, pattern, consumer, actionIds) } } + suspend fun filterElementsSuspend( + scope: CoroutineScope, + presentationProvider: suspend (AnAction) -> Presentation, + pattern: String, + consumer: suspend (MatchedValue) -> Boolean, + ) { + if (pattern.isEmpty()) return + + LOG.debug { "Start actions searching ($pattern)" } + + val actionIds = (actionManager as ActionManagerImpl).actionIds + + scope.runFilterJobs( presentationProvider, pattern, consumer, actionIds).forEach { it.join() } + } + + fun CoroutineScope.runFilterJobs( + presentationProvider: suspend (AnAction) -> Presentation, + pattern: String, + consumer: suspend (MatchedValue) -> Boolean, + actionIds: Set + ): List { + val abbreviationsJob = processAbbreviations(pattern, presentationProvider, consumer) + + val nonMatchedIdsChannel = Channel(capacity = Channel.UNLIMITED) + val matchedStubsJob = processMatchedActionsAndStubs(pattern, actionIds, presentationProvider, consumer, nonMatchedIdsChannel, abbreviationsJob) + val unmatchedStubsJob = processUnmatchedStubs(nonMatchedIdsChannel, pattern, presentationProvider, consumer, matchedStubsJob) + + val topHitsJob = processTopHits(pattern, presentationProvider, consumer, unmatchedStubsJob) + val intentionsJob = processIntentions(pattern, presentationProvider, consumer, topHitsJob) + val processOptionsJob = processOptions(pattern, presentationProvider, consumer, intentionsJob) + return listOf(abbreviationsJob, matchedStubsJob, unmatchedStubsJob, topHitsJob, intentionsJob, processOptionsJob) + } + private fun CoroutineScope.processAbbreviations(pattern: String, presentationProvider: suspend (AnAction) -> Presentation, consumer: suspend (MatchedValue) -> Boolean diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java index 0ddbd5a31d0d..bc9414271b4d 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java @@ -182,7 +182,7 @@ public final class GotoActionModel implements ChooseByNameModel, Comparator