use of com.intellij.codeInsight.completion.CompletionProgressIndicator in project intellij-community by JetBrains.
the class CodeInsightTestFixtureImpl method complete.
@Override
public LookupElement[] complete(@NotNull final CompletionType type, final int invocationCount) {
assertInitialized();
myEmptyLookup = false;
return UIUtil.invokeAndWaitIfNeeded(new Computable<LookupElement[]>() {
@Override
public LookupElement[] compute() {
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
@Override
public void run() {
final CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(type) {
@Override
@SuppressWarnings("deprecation")
protected void completionFinished(CompletionProgressIndicator indicator, boolean hasModifiers) {
myEmptyLookup = indicator.getLookup().getItems().isEmpty();
super.completionFinished(indicator, hasModifiers);
}
};
Editor editor = getCompletionEditor();
assertNotNull(editor);
handler.invokeCompletion(getProject(), editor, invocationCount);
// to compare with file text
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
}
}, null, null, getEditor().getDocument());
return getLookupElements();
}
});
}
use of com.intellij.codeInsight.completion.CompletionProgressIndicator in project intellij-community by JetBrains.
the class BackspaceHandler method truncatePrefix.
static void truncatePrefix(final DataContext dataContext, LookupImpl lookup, final EditorActionHandler handler, final int hideOffset, final Caret caret) {
final Editor editor = lookup.getEditor();
if (!lookup.performGuardedChange(() -> handler.execute(editor, caret, dataContext))) {
return;
}
final CompletionProgressIndicator process = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
if (lookup.truncatePrefix(process == null || !process.isAutopopupCompletion())) {
return;
}
if (process != null) {
if (hideOffset < editor.getCaretModel().getOffset()) {
process.scheduleRestart();
return;
}
process.prefixUpdated();
}
lookup.hideLookup(false);
}
use of com.intellij.codeInsight.completion.CompletionProgressIndicator in project intellij-community by JetBrains.
the class AutoPopupController method scheduleAutoPopup.
public void scheduleAutoPopup(final Editor editor, CompletionType completionType, @Nullable final Condition<PsiFile> condition) {
if (ApplicationManager.getApplication().isUnitTestMode() && !CompletionAutoPopupHandler.ourTestingAutopopup) {
return;
}
boolean alwaysAutoPopup = editor != null && Boolean.TRUE.equals(editor.getUserData(ALWAYS_AUTO_POPUP));
if (!CodeInsightSettings.getInstance().AUTO_POPUP_COMPLETION_LOOKUP && !alwaysAutoPopup) {
return;
}
if (PowerSaveMode.isEnabled()) {
return;
}
if (!CompletionServiceImpl.isPhase(CompletionPhase.CommittingDocuments.class, CompletionPhase.NoCompletion.getClass())) {
return;
}
final CompletionProgressIndicator currentCompletion = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
if (currentCompletion != null) {
currentCompletion.closeAndFinish(true);
}
final CompletionPhase.CommittingDocuments phase = new CompletionPhase.CommittingDocuments(null, editor);
CompletionServiceImpl.setCompletionPhase(phase);
phase.ignoreCurrentDocumentChange();
runTransactionWithEverythingCommitted(myProject, () -> {
if (phase.checkExpired())
return;
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
if (file != null && condition != null && !condition.value(file)) {
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
return;
}
CompletionAutoPopupHandler.invokeCompletion(completionType, true, myProject, editor, 0, false);
});
}
use of com.intellij.codeInsight.completion.CompletionProgressIndicator in project intellij-community by JetBrains.
the class LookupTypedHandler method beforeCharTyped.
private static boolean beforeCharTyped(final char charTyped, Project project, final Editor originalEditor, final Editor editor, PsiFile file) {
final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(originalEditor);
if (lookup == null) {
return false;
}
if (charTyped == ' ' && ChooseItemAction.hasTemplatePrefix(lookup, TemplateSettings.SPACE_CHAR)) {
return false;
}
final CharFilter.Result result = getLookupAction(charTyped, lookup);
if (lookup.isLookupDisposed()) {
return false;
}
if (result == CharFilter.Result.ADD_TO_PREFIX) {
Document document = editor.getDocument();
long modificationStamp = document.getModificationStamp();
if (!lookup.performGuardedChange(() -> EditorModificationUtil.typeInStringAtCaretHonorMultipleCarets(originalEditor, String.valueOf(charTyped), true))) {
return true;
}
lookup.appendPrefix(charTyped);
if (lookup.isStartCompletionWhenNothingMatches() && lookup.getItems().isEmpty()) {
final CompletionProgressIndicator completion = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
if (completion != null) {
completion.scheduleRestart();
} else {
AutoPopupController.getInstance(editor.getProject()).scheduleAutoPopup(editor);
}
}
AutoHardWrapHandler.getInstance().wrapLineIfNecessary(editor, DataManager.getInstance().getDataContext(editor.getContentComponent()), modificationStamp);
final CompletionProgressIndicator completion = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
if (completion != null) {
completion.prefixUpdated();
}
return true;
}
if (result == CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP && lookup.isFocused()) {
LookupElement item = lookup.getCurrentItem();
if (item != null) {
if (completeTillTypedCharOccurrence(charTyped, lookup, item)) {
return true;
}
FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_DOT_ETC);
lookup.finishLookupInWritableFile(charTyped, item);
return true;
}
}
lookup.hide();
TypedHandler.autoPopupCompletion(editor, charTyped, project, file);
return false;
}
Aggregations