Action search: make it possible to use from AI

GitOrigin-RevId: cdedc88fa44bd6d26679a38615f9ede3b3da3141
This commit is contained in:
Dmitry Osinovskiy
2025-04-12 14:44:49 +00:00
committed by intellij-monorepo-bot
parent 675dbd16f3
commit faeb98c666
2 changed files with 35 additions and 10 deletions
@@ -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<String>(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<String>
): List<Job> {
val abbreviationsJob = processAbbreviations(pattern, presentationProvider, consumer)
val nonMatchedIdsChannel = Channel<String>(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
@@ -182,7 +182,7 @@ public final class GotoActionModel implements ChooseByNameModel, Comparator<Obje
public static class MatchedValue implements MergeableElement, UiInspectorContextProvider {
public final @NotNull Object value;
final @NotNull MatchedValueType type;
final @NotNull String pattern;
public final @NotNull String pattern;
final int matchingDegree;
public @Nullable Double similarityScore = null;