use of com.intellij.codeInsight.completion.CompletionProcess in project intellij-community by JetBrains.
the class ChooseItemAction method hasTemplatePrefix.
public static boolean hasTemplatePrefix(LookupImpl lookup, char shortcutChar) {
// to bring the list model up to date
lookup.refreshUi(false, false);
CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion();
if (completion == null || !completion.isAutopopupCompletion()) {
return false;
}
if (lookup.isSelectionTouched()) {
return false;
}
final PsiFile file = lookup.getPsiFile();
if (file == null)
return false;
final Editor editor = lookup.getEditor();
final int offset = editor.getCaretModel().getOffset();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument());
final LiveTemplateLookupElement liveTemplateLookup = ContainerUtil.findInstance(lookup.getItems(), LiveTemplateLookupElement.class);
if (liveTemplateLookup == null || !liveTemplateLookup.sudden) {
// in this case we should check custom templates that provides completion lookup.
if (LiveTemplateCompletionContributor.customTemplateAvailableAndHasCompletionItem(shortcutChar, editor, file, offset)) {
return true;
}
List<TemplateImpl> templates = TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier(editor, file, false);
TemplateImpl template = LiveTemplateCompletionContributor.findFullMatchedApplicableTemplate(editor, offset, templates);
if (template != null && shortcutChar == TemplateSettings.getInstance().getShortcutChar(template)) {
return true;
}
return false;
}
return liveTemplateLookup.getTemplateShortcut() == shortcutChar;
}
use of com.intellij.codeInsight.completion.CompletionProcess in project intellij-community by JetBrains.
the class LookupManagerImpl method createLookup.
@NotNull
@Override
public LookupImpl createLookup(@NotNull final Editor editor, @NotNull LookupElement[] items, @NotNull final String prefix, @NotNull final LookupArranger arranger) {
hideActiveLookup();
final CodeInsightSettings settings = CodeInsightSettings.getInstance();
final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
final LookupImpl lookup = createLookup(editor, arranger, myProject);
final Alarm alarm = new Alarm();
final Runnable request = () -> {
if (myActiveLookup != lookup)
return;
LookupElement currentItem = lookup.getCurrentItem();
if (currentItem != null && currentItem.isValid() && isAutoPopupJavadocSupportedBy(currentItem)) {
final CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion();
if (completion != null && !completion.isAutopopupCompletion()) {
try {
DocumentationManager.getInstance(myProject).showJavaDocInfo(editor, psiFile, false);
} catch (IndexNotReadyException ignored) {
}
}
}
};
if (settings.AUTO_POPUP_JAVADOC_INFO) {
alarm.addRequest(request, settings.JAVADOC_INFO_DELAY);
}
ApplicationManager.getApplication().assertIsDispatchThread();
myActiveLookup = lookup;
myActiveLookupEditor = editor;
myActiveLookup.addLookupListener(new LookupAdapter() {
@Override
public void itemSelected(LookupEvent event) {
lookupClosed();
}
@Override
public void lookupCanceled(LookupEvent event) {
lookupClosed();
}
@Override
public void currentItemChanged(LookupEvent event) {
alarm.cancelAllRequests();
if (settings.AUTO_POPUP_JAVADOC_INFO && DocumentationManager.getInstance(myProject).getDocInfoHint() == null) {
alarm.addRequest(request, settings.JAVADOC_INFO_DELAY);
}
}
private void lookupClosed() {
ApplicationManager.getApplication().assertIsDispatchThread();
alarm.cancelAllRequests();
lookup.removeLookupListener(this);
}
});
Disposer.register(lookup, new Disposable() {
@Override
public void dispose() {
myActiveLookup = null;
myActiveLookupEditor = null;
myPropertyChangeSupport.firePropertyChange(PROP_ACTIVE_LOOKUP, lookup, null);
}
});
CamelHumpMatcher matcher = new CamelHumpMatcher(prefix);
if (items.length > 0) {
for (final LookupElement item : items) {
myActiveLookup.addItem(item, matcher);
}
myActiveLookup.refreshUi(true, true);
} else {
// no items -> no doc
alarm.cancelAllRequests();
}
myPropertyChangeSupport.firePropertyChange(PROP_ACTIVE_LOOKUP, null, myActiveLookup);
return lookup;
}
Aggregations