mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lookup available from CompletionParameters
This commit is contained in:
+8
-1
@@ -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() {
|
||||
|
||||
+12
-4
@@ -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());
|
||||
|
||||
+5
-8
@@ -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;
|
||||
}
|
||||
|
||||
+3
-3
@@ -109,13 +109,13 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
private final ConcurrentHashMap<LookupElement, CompletionSorterImpl> myItemSorters = new ConcurrentHashMap<LookupElement, CompletionSorterImpl>();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user