SmartCompletion results
Hello,
Is it possible to know how many items SmartCompletion would return without triggering SmartCodeCompletionAction?
In 7th version of IDEA there were very nice method SmartCodeCompletionHandler::getLookupData but now it's gone.
Thanks.
:sergiy
Please sign in to leave a comment.
Hello Sergiy,
The list of items for code completion is now filled asynchronously, so there
is no way to fetch the number of items in advance.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
CompletionService.performCompletion(new CompletionParameters(...), ]]>).
Please note that this process can take a very long time, so use it wisely.
Thanks Dmitry,
Actually I don't need to know all lookup items, it's enough to know that there is at least one. Is it possible to find out if "there is something to suggest"?
I'm trying to port to 8th this plugin http://plugins.intellij.net/plugin/?id=1315
:sergiy
Thanks Peter.
Does this look right?
public class NextGenCompletion extends AnAction {
public void actionPerformed(AnActionEvent e) {
final Project project = e.getData(DataKeys.PROJECT);
if(project == null)
return;
final PsiFile psiFile = e.getData(DataKeys.PSI_FILE);
if (psiFile == null)
return;
final Editor editor = e.getData(DataKeys.EDITOR);
if (editor == null)
return;
int offset = editor.getCaretModel().getOffset();
PsiElement psiElement = psiFile.findElementAt(offset);
if(psiElement == null)
return;
CompletionParameters parameters = new CompletionParameters(psiElement, psiFile, CompletionType.SMART, offset, 1);
Consumer<LookupElement> consumer = new Consumer<LookupElement>() {
public void consume(LookupElement lookupElement) {
System.out.println("lookupString = " + lookupElement.getLookupString());
}
};
CompletionService.getCompletionService().performCompletion(parameters, consumer);
}
}
I get NullPointerException instead of lookup strings in a console, I guess doing something wrong...
at com.intellij.codeInsight.completion.JavaMethodMergingContributor.fillCompletionVariants(JavaMethodMergingContributor.java:7)
at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:78)
at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:69)
at com.intellij.codeInsight.completion.CompletionService.performCompletion(CompletionService.java:106)
at org.dubikdev.codecompletionng.NextGenCompletion.actionPerformed(NextGenCompletion.java:46)
at com.intellij.openapi.actionSystem.impl.ActionButton.a(ActionButton.java:61)
at com.intellij.openapi.actionSystem.impl.ActionButton.a(ActionButton.java:89)
at com.intellij.openapi.actionSystem.impl.ActionButton.processMouseEvent(ActionButton.java:23)
at java.awt.Component.processEvent(Component.java:5367)
at java.awt.Container.processEvent(Container.java:2010)
at java.awt.Component.dispatchEventImpl(Component.java:4068)
at java.awt.Container.dispatchEventImpl(Container.java:2068)
at java.awt.Component.dispatchEvent(Component.java:3903)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
at java.awt.Container.dispatchEventImpl(Container.java:2054)
at java.awt.Window.dispatchEventImpl(Window.java:1801)
at java.awt.Component.dispatchEvent(Component.java:3903)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at com.intellij.ide.IdeEventQueue.c(IdeEventQueue.java:35)
at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:223)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:217)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
:sergiy
Oh yes. Some completion clients assume that when they are invoked, a
full-blown completion is in progress. And I can understand that. Will be
fixed in next EAP.
Thanks Peter, looking forward.