IJPL-176078 fix search everywhere actions updating in remote dev by making update concurrent

(cherry picked from commit 3b879210ff3d616daede7fa79b3b2a8d7efbdd4a)

IJ-MR-153792

(cherry picked from commit be996f6a207935ce77e2973dde7322fd1460d3e1)


(cherry picked from commit 8325e0d47844fa654fa129e5305323fe537cd7f7)

IJ-CR-153899

GitOrigin-RevId: 024d9dbd7fc715656df0b63109faccf380ff8ac2
This commit is contained in:
Ivan.Yarkov
2025-01-28 12:49:18 +02:00
committed by intellij-monorepo-bot
parent 25d0da7ea1
commit 0c64f075c1

View File

@@ -114,28 +114,29 @@ internal class ActionAsyncProvider(private val model: GotoActionModel) {
awaitJob?.join() //wait until all items from previous step are processed
LOG.debug { "Process matched actions for \"$pattern\"" }
list.forEachConcurrentOrdered { matchedActionOrStub, awaitMyTurn ->
list.forEachConcurrentOrdered ({ matchedActionOrStub ->
val action = matchedActionOrStub.action
val matchedAction = if (action is ActionStubBase) loadAction(action.id)?.let { MatchedAction(it, matchedActionOrStub.mode, matchedActionOrStub.weight) } else matchedActionOrStub
if (matchedAction == null) return@forEachConcurrentOrdered
if (matchedAction == null) return@forEachConcurrentOrdered null
val matchedValue = matchItem(
item = wrapAnAction(action = matchedAction.action, presentationProvider = presentationProvider, matchMode = matchedAction.mode),
matcher = weightMatcher,
pattern = pattern,
matchType = MatchedValueType.ACTION,
)
awaitMyTurn()
return@forEachConcurrentOrdered matchedValue
}, { matchedValue ->
if (!consumer(matchedValue)) cancel()
}
})
}
private suspend fun <T> Collection<T>.forEachConcurrentOrdered(action: suspend (T, suspend () -> Unit) -> Unit) {
suspend fun runConcurrent(item: T, jobToAwait: Job?): Job = coroutineScope {
launch { action(item) { jobToAwait?.join() } }
private suspend fun <TIn, TOut : Any> Collection<TIn>.forEachConcurrentOrdered(concurrentAction: suspend (TIn) -> TOut?, orderedAction: suspend (TOut) -> Unit) {
coroutineScope {
this@forEachConcurrentOrdered.mapNotNull { async { concurrentAction(it) } }.forEach {
orderedAction(it.await() ?: return@forEach)
}
}
var prevItemJob: Job? = null
forEach { prevItemJob = runConcurrent(it, prevItemJob) }
}
private suspend fun collectMatchedActions(pattern: String, allIds: Collection<String>, weightMatcher: MinusculeMatcher, unmatchedIdsChannel: SendChannel<String>): List<MatchedAction> = coroutineScope {