mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IJPL-207762 simplify API around LookupArranger#additionalMatcher
GitOrigin-RevId: 707fb91d01b7bebc1244bad443b76e2987778d6b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bc0b8293d4
commit
b67bae7de8
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package com.intellij.codeInsight.lookup;
|
||||
|
||||
@@ -84,19 +84,17 @@ public abstract class LookupArranger implements WeighingContext {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an additional matcher for the lookup.
|
||||
* Sets an additional matcher for the lookup.
|
||||
* Every item is checked by this matcher.
|
||||
*
|
||||
* @param matcher an additional matcher to register
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
@ApiStatus.Experimental
|
||||
public void registerAdditionalMatcher(@NotNull Predicate<LookupElement> matcher) {
|
||||
public void setAdditionalMatcher(@Nullable Predicate<LookupElement> matcher) {
|
||||
myAdditionalMatcher = matcher;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
@ApiStatus.Experimental
|
||||
public @Nullable Predicate<LookupElement> getAdditionalMatcher() {
|
||||
return myAdditionalMatcher;
|
||||
}
|
||||
|
||||
+10
-11
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.completion.command
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle
|
||||
@@ -105,7 +105,7 @@ internal class CommandCompletionService(
|
||||
!document.immutableCharSequence.substring(offsetOfFullIndex, currentOffset).startsWith(fullSuffix)) {
|
||||
if (installed != true) return
|
||||
lookup.removeUserData(INSTALLED_ADDITIONAL_MATCHER_KEY)
|
||||
lookup.arranger.registerAdditionalMatcher { true }
|
||||
lookup.arranger.additionalMatcher = null
|
||||
lookup.arranger.prefixChanged(lookup)
|
||||
lookup.requestResize()
|
||||
lookup.refreshUi(false, true)
|
||||
@@ -118,10 +118,10 @@ internal class CommandCompletionService(
|
||||
lookup.showIfMeaningless() // stop hiding
|
||||
val showPostfixAsSeparateGroup = PostfixTemplatesSettings.getInstance().isShowAsSeparateGroup
|
||||
if (completionFactory.supportFiltersWithDoublePrefix()) {
|
||||
lookup.arranger.registerAdditionalMatcher(CommandCompletionLookupItemFilter(showPostfixAsSeparateGroup))
|
||||
lookup.arranger.additionalMatcher = CommandCompletionLookupItemMatcher(showPostfixAsSeparateGroup)
|
||||
}
|
||||
else if (!showPostfixAsSeparateGroup) {
|
||||
lookup.arranger.registerAdditionalMatcher(NotPostfixCompletionLookupItemFilter)
|
||||
lookup.arranger.additionalMatcher = NotPostfixCompletionLookupItemMatcher
|
||||
}
|
||||
lookup.arranger.prefixChanged(lookup)
|
||||
lookup.requestResize()
|
||||
@@ -136,7 +136,7 @@ internal class CommandCompletionService(
|
||||
if (showIfMeaningless) {
|
||||
lookup.showIfMeaningless() // stop hiding
|
||||
}
|
||||
lookup.arranger.registerAdditionalMatcher(CommandCompletionLookupItemFilter(PostfixTemplatesSettings.getInstance().isShowAsSeparateGroup))
|
||||
lookup.arranger.additionalMatcher = CommandCompletionLookupItemMatcher(PostfixTemplatesSettings.getInstance().isShowAsSeparateGroup)
|
||||
lookup.arranger.prefixChanged(lookup)
|
||||
lookup.requestResize()
|
||||
lookup.refreshUi(false, true)
|
||||
@@ -185,14 +185,13 @@ internal class CommandCompletionService(
|
||||
lookup.putUserData(INSTALLED_HINT_KEY, true)
|
||||
}
|
||||
|
||||
private class CommandCompletionLookupItemFilter(private val showPostfixAsSeparateGroup: Boolean) : Condition<LookupElement> {
|
||||
override fun value(e: LookupElement?): Boolean {
|
||||
return e != null && (e.`as`(CommandCompletionLookupElement::class.java) != null ||
|
||||
(showPostfixAsSeparateGroup && e.`as`(PostfixTemplateLookupElement::class.java) != null))
|
||||
}
|
||||
private class CommandCompletionLookupItemMatcher(private val showPostfixAsSeparateGroup: Boolean) : Condition<LookupElement> {
|
||||
override fun value(e: LookupElement): Boolean =
|
||||
e.`as`(CommandCompletionLookupElement::class.java) != null ||
|
||||
(showPostfixAsSeparateGroup && e.`as`(PostfixTemplateLookupElement::class.java) != null)
|
||||
}
|
||||
|
||||
private object NotPostfixCompletionLookupItemFilter : Condition<LookupElement> {
|
||||
private object NotPostfixCompletionLookupItemMatcher : Condition<LookupElement> {
|
||||
override fun value(e: LookupElement?): Boolean {
|
||||
return e != null && e.`as`(PostfixTemplateLookupElement::class.java) == null
|
||||
}
|
||||
|
||||
@@ -291,10 +291,14 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable,
|
||||
}
|
||||
|
||||
public void setArranger(@NotNull LookupArranger arranger) {
|
||||
Predicate<LookupElement> previousMatcher = myArranger.getAdditionalMatcher();
|
||||
reuseAdditionalMatcher(myArranger, arranger);
|
||||
myArranger = arranger;
|
||||
if (previousMatcher != null) {
|
||||
myArranger.registerAdditionalMatcher(previousMatcher);
|
||||
}
|
||||
|
||||
private static void reuseAdditionalMatcher(@NotNull LookupArranger oldArranger, @NotNull LookupArranger newArranger) {
|
||||
Predicate<LookupElement> oldMatcher = oldArranger.getAdditionalMatcher();
|
||||
if (oldMatcher != null) {
|
||||
newArranger.setAdditionalMatcher(oldMatcher);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1514,11 +1518,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable,
|
||||
public void markReused() {
|
||||
EDT.assertIsEdt();
|
||||
LookupArranger copy = myArranger.createEmptyCopy();
|
||||
Predicate<LookupElement> additionalMatcher = myArranger.getAdditionalMatcher();
|
||||
if (additionalMatcher != null) {
|
||||
copy.registerAdditionalMatcher(additionalMatcher);
|
||||
}
|
||||
myArranger = copy;
|
||||
setArranger(copy);
|
||||
|
||||
requestResize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user