IJPL-163538 passpresentationProvider as an argument to updateBeforeShowSuspend

(cherry picked from commit 205f27e684abd04ab459c361f0e85e3bc0091e3a)

IJ-MR-146410

(cherry picked from commit 662c25549482d087af9bfeef61cb901ca3e7b4f0)


(cherry picked from commit 664c1e97f1b21b4be29a6f17fea985929e0d2488)

IJ-CR-153899

GitOrigin-RevId: e03f9bc4940670ef651d5ab1d2b35a9e4ef98382
This commit is contained in:
Mikhail Sokolov
2024-10-10 18:03:49 +02:00
committed by intellij-monorepo-bot
parent 66fe716c81
commit f0bbdc36e0
2 changed files with 12 additions and 20 deletions

View File

@@ -91,8 +91,7 @@ internal class ActionAsyncProvider(private val model: GotoActionModel) {
actionIds.forEachConcurrent { id ->
val action = loadAction(id) ?: return@forEachConcurrent
val presentation = presentationProvider(action)
val wrapper = wrapAnAction(action, presentation)
val wrapper = wrapAnAction(action, presentationProvider)
val degree = matcher.matchingDegree(pattern)
val matchedValue = abbreviationMatchedValue(wrapper, pattern, degree)
if (!consumer(matchedValue)) cancel()
@@ -117,9 +116,8 @@ internal class ActionAsyncProvider(private val model: GotoActionModel) {
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
val presentation = presentationProvider(matchedAction.action)
val matchedValue = matchItem(
item = wrapAnAction(action = matchedAction.action, presentation = presentation, matchMode = matchedAction.mode),
item = wrapAnAction(action = matchedAction.action, presentationProvider = presentationProvider, matchMode = matchedAction.mode),
matcher = weightMatcher,
pattern = pattern,
matchType = MatchedValueType.ACTION,
@@ -192,8 +190,7 @@ internal class ActionAsyncProvider(private val model: GotoActionModel) {
val weight = calcElementWeight(element = action, pattern = pattern, matcher = weightMatcher)
val matchedAction = MatchedAction(action = action, mode = mode, weight = weight)
val presentation = presentationProvider(matchedAction.action)
val item = wrapAnAction(matchedAction.action, presentation, matchedAction.mode)
val item = wrapAnAction(matchedAction.action, presentationProvider, matchedAction.mode)
val matchedValue = matchItem(item = item, matcher = weightMatcher, pattern = pattern, matchType = MatchedValueType.ACTION)
return@runCatching matchedValue
}.getOrLogException(LOG)
@@ -237,7 +234,7 @@ internal class ActionAsyncProvider(private val model: GotoActionModel) {
}
val matchedValues = collector.result.mapConcurrent { item ->
val obj = (item as? AnAction)?.let { wrapAnAction(action = it, presentation = presentationProvider(it)) } ?: item
val obj = (item as? AnAction)?.let { wrapAnAction(action = it, presentationProvider = presentationProvider) } ?: item
matchItem(item = obj, matcher = matcher, pattern = pattern, matchType = MatchedValueType.TOP_HIT)
}.sortedWith(MATCHED_VALUE_COMPARATOR)
@@ -369,9 +366,10 @@ internal class ActionAsyncProvider(private val model: GotoActionModel) {
return if (weight == null) MatchedValue(item, pattern, matchType) else MatchedValue(item, pattern, weight, matchType)
}
private suspend fun wrapAnAction(action: AnAction, presentation: Presentation, matchMode: MatchMode = MatchMode.NAME): ActionWrapper {
private suspend fun wrapAnAction(action: AnAction, presentationProvider: suspend (AnAction) -> Presentation, matchMode: MatchMode = MatchMode.NAME): ActionWrapper {
val groupMapping = model.getGroupMapping(action)
groupMapping?.updateBeforeShowSuspend(model.updateSession)
groupMapping?.updateBeforeShowSuspend(presentationProvider)
val presentation = presentationProvider(action)
return ActionWrapper(action, groupMapping, matchMode, presentation)
}

View File

@@ -2,10 +2,10 @@
package com.intellij.ide.util.gotoByName
import com.intellij.openapi.actionSystem.ActionGroup
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.actionSystem.Presentation
import com.intellij.openapi.actionSystem.UpdateSession
import com.intellij.openapi.actionSystem.impl.SuspendingUpdateSession
import com.intellij.openapi.util.Comparing
import com.intellij.openapi.util.NlsActions.ActionText
import com.intellij.openapi.util.text.StringUtil
@@ -43,18 +43,12 @@ class GroupMapping @JvmOverloads constructor(private val myShowNonPopupGroups: B
return if (path != null) getPathName(path) else null
}
suspend fun updateBeforeShowSuspend(session: UpdateSession) {
val suspendingSession = (session as? SuspendingUpdateSession)
if (suspendingSession == null) {
updateBeforeShow(session)
return
}
suspend fun updateBeforeShowSuspend(presentationProvider: suspend (AnAction) -> Presentation) {
if (myBestNameComputed) return
myBestNameComputed = true
for (path in myPaths) {
val name = getActualPathNameSuspend(path, suspendingSession)
val name = getActualPathNameSuspend(path, presentationProvider)
if (name != null) {
myBestGroupName = name
return
@@ -86,10 +80,10 @@ class GroupMapping @JvmOverloads constructor(private val myShowNonPopupGroups: B
return StringUtil.nullize(name)
}
private suspend fun getActualPathNameSuspend(path: List<ActionGroup>, session: SuspendingUpdateSession): @Nls String? {
private suspend fun getActualPathNameSuspend(path: List<ActionGroup>, presentationProvider: suspend (AnAction) -> Presentation): @Nls String? {
var name = ""
for (group in path) {
val presentation = session.presentationSuspend(group)
val presentation = presentationProvider(group)
if (!presentation.isVisible()) return null
name = appendGroupName(name, group, presentation)
}