From b67bae7de8aa9300ac07512bb5bc689c3e814b63 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Fri, 13 Feb 2026 17:12:42 +0100 Subject: [PATCH] IJPL-207762 simplify API around LookupArranger#additionalMatcher GitOrigin-RevId: 707fb91d01b7bebc1244bad443b76e2987778d6b --- .../codeInsight/lookup/LookupArranger.java | 8 +++---- .../command/CommandCompletionService.kt | 21 +++++++++---------- .../codeInsight/lookup/impl/LookupImpl.java | 16 +++++++------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/platform/analysis-api/src/com/intellij/codeInsight/lookup/LookupArranger.java b/platform/analysis-api/src/com/intellij/codeInsight/lookup/LookupArranger.java index 57ce4d5e23cf..ac3d539bd1df 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/lookup/LookupArranger.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/lookup/LookupArranger.java @@ -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 matcher) { + public void setAdditionalMatcher(@Nullable Predicate matcher) { myAdditionalMatcher = matcher; } @ApiStatus.Internal - @ApiStatus.Experimental public @Nullable Predicate getAdditionalMatcher() { return myAdditionalMatcher; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/command/CommandCompletionService.kt b/platform/lang-impl/src/com/intellij/codeInsight/completion/command/CommandCompletionService.kt index 0edcfa9ada5c..811f3950c1ff 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/command/CommandCompletionService.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/command/CommandCompletionService.kt @@ -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 { - 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 { + override fun value(e: LookupElement): Boolean = + e.`as`(CommandCompletionLookupElement::class.java) != null || + (showPostfixAsSeparateGroup && e.`as`(PostfixTemplateLookupElement::class.java) != null) } - private object NotPostfixCompletionLookupItemFilter : Condition { + private object NotPostfixCompletionLookupItemMatcher : Condition { override fun value(e: LookupElement?): Boolean { return e != null && e.`as`(PostfixTemplateLookupElement::class.java) == null } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index b8aaeb4d3f4d..19c18dc3feac 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -291,10 +291,14 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable, } public void setArranger(@NotNull LookupArranger arranger) { - Predicate 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 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 additionalMatcher = myArranger.getAdditionalMatcher(); - if (additionalMatcher != null) { - copy.registerAdditionalMatcher(additionalMatcher); - } - myArranger = copy; + setArranger(copy); requestResize(); }