diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/AutoCompletionContext.java b/platform/lang-api/src/com/intellij/codeInsight/completion/AutoCompletionContext.java index df0f365dff2f..9c1fdebee559 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/AutoCompletionContext.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/AutoCompletionContext.java @@ -16,6 +16,7 @@ package com.intellij.codeInsight.completion; +import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.LookupElement; /** @@ -25,11 +26,17 @@ public class AutoCompletionContext { private final CompletionParameters myParameters; private final LookupElement[] myItems; private final OffsetMap myOffsetMap; + private final Lookup myLookup; - public AutoCompletionContext(CompletionParameters parameters, LookupElement[] items, OffsetMap offsetMap) { + public AutoCompletionContext(CompletionParameters parameters, LookupElement[] items, OffsetMap offsetMap, Lookup lookup) { myParameters = parameters; myItems = items; myOffsetMap = offsetMap; + myLookup = lookup; + } + + public Lookup getLookup() { + return myLookup; } public CompletionParameters getParameters() { diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionParameters.java b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionParameters.java index d82b19dd8c87..ec16b89110fa 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionParameters.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionParameters.java @@ -15,6 +15,7 @@ */ package com.intellij.codeInsight.completion; +import com.intellij.codeInsight.lookup.Lookup; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import com.intellij.psi.PsiElement; @@ -27,12 +28,13 @@ public class CompletionParameters { private final PsiElement myPosition; private final PsiFile myOriginalFile; private final CompletionType myCompletionType; + private final Lookup myLookup; private final int myOffset; private final int myInvocationCount; private final boolean myRelaxedMatching; protected CompletionParameters(@NotNull final PsiElement position, @NotNull final PsiFile originalFile, - final CompletionType completionType, int offset, final int invocationCount, final boolean relaxedMatching) { + final CompletionType completionType, int offset, final int invocationCount, Lookup lookup, final boolean relaxedMatching) { assert offset >= position.getTextRange().getStartOffset(); myPosition = position; assert position.isValid(); @@ -41,18 +43,19 @@ public class CompletionParameters { myOffset = offset; myInvocationCount = invocationCount; myRelaxedMatching = relaxedMatching; + myLookup = lookup; } public CompletionParameters withType(CompletionType type) { - return new CompletionParameters(myPosition, myOriginalFile, type, myOffset, myInvocationCount, myRelaxedMatching); + return new CompletionParameters(myPosition, myOriginalFile, type, myOffset, myInvocationCount, myLookup, myRelaxedMatching); } public CompletionParameters withInvocationCount(int newCount) { - return new CompletionParameters(myPosition, myOriginalFile, myCompletionType, myOffset, newCount, myRelaxedMatching); + return new CompletionParameters(myPosition, myOriginalFile, myCompletionType, myOffset, newCount, myLookup, myRelaxedMatching); } public CompletionParameters withRelaxedMatching() { - return new CompletionParameters(myPosition, myOriginalFile, myCompletionType, myOffset, myInvocationCount, true); + return new CompletionParameters(myPosition, myOriginalFile, myCompletionType, myOffset, myInvocationCount, myLookup, true); } @NotNull @@ -60,6 +63,11 @@ public class CompletionParameters { return myPosition; } + @NotNull + public Lookup getLookup() { + return myLookup; + } + @Nullable public PsiElement getOriginalPosition() { return myOriginalFile.findElementAt(myPosition.getTextRange().getStartOffset()); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 3717ac6aef30..fd083c3c6f09 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -241,12 +241,10 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { final CompletionParameters parameters = createCompletionParameters(invocationCount, initContext); - final LookupImpl lookup = obtainLookup(editor); - final Semaphore freezeSemaphore = new Semaphore(); freezeSemaphore.down(); final CompletionProgressIndicator indicator = new CompletionProgressIndicator(editor, parameters, this, freezeSemaphore, - initContext.getOffsetMap(), lookup, hasModifiers); + initContext.getOffsetMap(), hasModifiers); boolean sync = (invokedExplicitly || ApplicationManager.getApplication().isUnitTestMode()) && !CompletionAutoPopupHandler.ourTestingAutopopup; @@ -350,12 +348,10 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { LOG.error("wrong text: copy='" + fileCopy.getText() + "'; element='" + insertedElement.getText() + "'; range=" + range); } - return new CompletionParameters(insertedElement, fileCopy.getOriginalFile(), myCompletionType, offset, invocationCount, false); + return new CompletionParameters(insertedElement, fileCopy.getOriginalFile(), myCompletionType, offset, invocationCount, obtainLookup(initContext.getEditor()), false); } - private AutoCompletionDecision shouldAutoComplete( - final CompletionProgressIndicator indicator, - final LookupElement[] items) { + private AutoCompletionDecision shouldAutoComplete(final CompletionProgressIndicator indicator, final LookupElement[] items) { if (!invokedExplicitly) { return AutoCompletionDecision.SHOW_LOOKUP; } @@ -376,8 +372,9 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { return AutoCompletionDecision.insertItem(item); } + AutoCompletionContext context = new AutoCompletionContext(parameters, items, indicator.getOffsetMap(), indicator.getLookup()); for (final CompletionContributor contributor : CompletionContributor.forParameters(parameters)) { - final AutoCompletionDecision decision = contributor.handleAutoCompletionPossibility(new AutoCompletionContext(parameters, items, indicator.getOffsetMap())); + final AutoCompletionDecision decision = contributor.handleAutoCompletionPossibility(context); if (decision != null) { return decision; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index e447f2502cbd..7adcd775e881 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -109,13 +109,13 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement private final ConcurrentHashMap myItemSorters = new ConcurrentHashMap(); public CompletionProgressIndicator(final Editor editor, CompletionParameters parameters, CodeCompletionHandlerBase handler, Semaphore freezeSemaphore, - final OffsetMap offsetMap, LookupImpl lookup, boolean hasModifiers) { + final OffsetMap offsetMap, boolean hasModifiers) { myEditor = editor; myParameters = parameters; myHandler = handler; myFreezeSemaphore = freezeSemaphore; myOffsetMap = offsetMap; - myLookup = lookup; + myLookup = (LookupImpl)parameters.getLookup(); myLookup.setArranger(new CompletionLookupArranger(parameters, this)); @@ -131,7 +131,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement return; } - if (!lookup.isShown()) { + if (!myLookup.isShown()) { scheduleAdvertising(); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/DefaultCompletionContributor.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/DefaultCompletionContributor.java index cbe534857650..5e02cf723ce6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/DefaultCompletionContributor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/DefaultCompletionContributor.java @@ -86,7 +86,7 @@ public class DefaultCompletionContributor extends CompletionContributor { final LookupElement[] items = context.getItems(); if (items.length == 1) { final LookupElement item = items[0]; - if (!StringUtil.isEmpty(item.getPrefixMatcher().getPrefix()) || context.getParameters().getCompletionType() == CompletionType.SMART) { + if (!StringUtil.isEmpty(context.getLookup().itemPattern(item)) || context.getParameters().getCompletionType() == CompletionType.SMART) { return AutoCompletionDecision.insertItem(item); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java index 9446fb54ef8d..a0528315017b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/PrefixMatchingWeigher.java @@ -27,7 +27,7 @@ import java.util.Set; public class PrefixMatchingWeigher extends CompletionWeigher { public Comparable weigh(@NotNull final LookupElement item, @NotNull final CompletionLocation location) { - final String prefix = item.getPrefixMatcher().getPrefix(); + final String prefix = location.getCompletionParameters().getLookup().itemPattern(item); if (prefix.isEmpty()) { return 0; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupEx.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupEx.java new file mode 100644 index 000000000000..9df3cdf958bb --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupEx.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.lookup; + +/** + * @author peter + */ +public interface LookupEx extends Lookup { +} 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 6f7200b2f957..2a0d5195e491 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 @@ -77,7 +77,7 @@ import java.awt.event.MouseEvent; import java.util.*; import java.util.List; -public class LookupImpl extends LightweightHint implements Lookup, Disposable { +public class LookupImpl extends LightweightHint implements LookupEx, Disposable { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.lookup.impl.LookupImpl"); private static final int MAX_PREFERRED_COUNT = 5;