mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-108197 Warn user about incomplete completion results in dumb mode
This commit is contained in:
+7
-4
@@ -46,6 +46,7 @@ import com.intellij.openapi.progress.util.ProgressWrapper;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -178,7 +179,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
if (FeatureUsageTracker.getInstance().isToBeAdvertisedInLookup(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_CONTROL_DOT, getProject())) {
|
||||
myLookup.addAdvertisement("Press " +
|
||||
CompletionContributor.getActionShortcut(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_DOT) +
|
||||
" to choose the selected (or first) suggestion and insert a dot afterwards");
|
||||
" to choose the selected (or first) suggestion and insert a dot afterwards", null);
|
||||
}
|
||||
} else {
|
||||
myLookup.setFocusDegree(LookupImpl.FocusDegree.FOCUSED);
|
||||
@@ -188,15 +189,17 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
.isToBeAdvertisedInLookup(CodeCompletionFeatures.EDITING_COMPLETION_CONTROL_ENTER, getProject())) {
|
||||
myLookup.addAdvertisement("Press " +
|
||||
CompletionContributor.getActionShortcut(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_ALWAYS) +
|
||||
" to choose the selected (or first) suggestion");
|
||||
" to choose the selected (or first) suggestion", null);
|
||||
}
|
||||
if (!myEditor.isOneLineMode() &&
|
||||
FeatureUsageTracker.getInstance()
|
||||
.isToBeAdvertisedInLookup(CodeCompletionFeatures.EDITING_COMPLETION_CONTROL_ARROWS, getProject())) {
|
||||
myLookup.addAdvertisement(CompletionContributor.getActionShortcut(IdeActions.ACTION_LOOKUP_DOWN) + " and " +
|
||||
CompletionContributor.getActionShortcut(IdeActions.ACTION_LOOKUP_UP) +
|
||||
" will move caret down and up in the editor");
|
||||
" will move caret down and up in the editor", null);
|
||||
}
|
||||
} else if (DumbService.isDumb(getProject())) {
|
||||
myLookup.addAdvertisement("Completion results might be incomplete until indexing is complete", MessageType.WARNING.getPopupBackground());
|
||||
}
|
||||
|
||||
ProgressManager.checkCanceled();
|
||||
@@ -333,7 +336,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
PerformanceWatcher.getInstance().dumpThreads(true);
|
||||
}
|
||||
|
||||
if (StringUtil.isEmpty(myLookup.getAdvertisementText()) && !isAutopopupCompletion()) {
|
||||
if (StringUtil.isEmpty(myLookup.getAdvertisementText()) && !isAutopopupCompletion() && !DumbService.isDumb(getProject())) {
|
||||
final String text = DefaultCompletionContributor.getDefaultAdvertisementText(myParameters);
|
||||
if (text != null) {
|
||||
myLookup.setAdvertisementText(text);
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
package com.intellij.codeInsight.lookup.impl;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.ui.ClickListener;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.GridBag;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -34,7 +37,7 @@ import java.util.Random;
|
||||
* @author peter
|
||||
*/
|
||||
public class Advertiser {
|
||||
private final List<String> myTexts = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
private final List<Pair<String, Color>> myTexts = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
private volatile Dimension myCachedPrefSize;
|
||||
private final JPanel myComponent = new JPanel(new GridBagLayout()) {
|
||||
private JLabel mySample = createLabel();
|
||||
@@ -54,8 +57,8 @@ public class Advertiser {
|
||||
}
|
||||
|
||||
int maxSize = 0;
|
||||
for (String label : myTexts) {
|
||||
mySample.setText(prepareText(label));
|
||||
for (Pair<String, Color> label : myTexts) {
|
||||
mySample.setText(prepareText(label.first));
|
||||
maxSize = Math.max(maxSize, mySample.getPreferredSize().width);
|
||||
}
|
||||
|
||||
@@ -92,11 +95,14 @@ public class Advertiser {
|
||||
private void updateAdvertisements() {
|
||||
myNextLabel.setVisible(myTexts.size() > 1);
|
||||
if (!myTexts.isEmpty()) {
|
||||
String text = myTexts.get(myCurrentItem % myTexts.size());
|
||||
Pair<String, Color> pair = myTexts.get(myCurrentItem % myTexts.size());
|
||||
String text = pair.first;
|
||||
myTextPanel.setText(prepareText(text));
|
||||
myComponent.setBackground(pair.second);
|
||||
}
|
||||
else {
|
||||
myTextPanel.setText("");
|
||||
myComponent.setBackground(null);
|
||||
}
|
||||
myCachedPrefSize = null;
|
||||
myComponent.revalidate();
|
||||
@@ -131,9 +137,9 @@ public class Advertiser {
|
||||
return font.deriveFont((float)(font.getSize() - 2));
|
||||
}
|
||||
|
||||
public void addAdvertisement(@NotNull String text) {
|
||||
public void addAdvertisement(@NotNull String text, @Nullable Color bgColor) {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
myTexts.add(text);
|
||||
myTexts.add(Pair.create(text, bgColor));
|
||||
updateAdvertisements();
|
||||
}
|
||||
|
||||
@@ -142,6 +148,11 @@ public class Advertiser {
|
||||
}
|
||||
|
||||
public List<String> getAdvertisements() {
|
||||
return myTexts;
|
||||
return ContainerUtil.map(myTexts, new Function<Pair<String, Color>, String>() {
|
||||
@Override
|
||||
public String fun(Pair<String, Color> pair) {
|
||||
return pair.first;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,6 @@ import com.intellij.ui.plaf.beg.BegPopupMenuBorder;
|
||||
import com.intellij.ui.popup.AbstractPopup;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.CollectConsumer;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.containers.ConcurrentHashMap;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -378,7 +377,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
public void setAdvertisementText(@Nullable String text) {
|
||||
myAdText = text;
|
||||
if (StringUtil.isNotEmpty(text)) {
|
||||
addAdvertisement(ObjectUtils.assertNotNull(text));
|
||||
addAdvertisement(text, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1294,12 +1293,12 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
requestResize();
|
||||
}
|
||||
|
||||
public void addAdvertisement(@NotNull final String text) {
|
||||
public void addAdvertisement(@NotNull final String text, final @Nullable Color bgColor) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!myDisposed) {
|
||||
myAdComponent.addAdvertisement(text);
|
||||
myAdComponent.addAdvertisement(text, bgColor);
|
||||
if (myShown) {
|
||||
requestResize();
|
||||
refreshUi(false, false);
|
||||
|
||||
Reference in New Issue
Block a user