Search in sources :

Example 1 with CompletionProgressIndicator

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();
        }
    });
}
Also used : CompletionProgressIndicator(com.intellij.codeInsight.completion.CompletionProgressIndicator) CodeCompletionHandlerBase(com.intellij.codeInsight.completion.CodeCompletionHandlerBase) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor)

Example 2 with CompletionProgressIndicator

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);
}
Also used : CompletionProgressIndicator(com.intellij.codeInsight.completion.CompletionProgressIndicator) Editor(com.intellij.openapi.editor.Editor)

Example 3 with CompletionProgressIndicator

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);
    });
}
Also used : CompletionProgressIndicator(com.intellij.codeInsight.completion.CompletionProgressIndicator) CompletionPhase(com.intellij.codeInsight.completion.CompletionPhase) PsiFile(com.intellij.psi.PsiFile)

Example 4 with CompletionProgressIndicator

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;
}
Also used : CompletionProgressIndicator(com.intellij.codeInsight.completion.CompletionProgressIndicator) CharFilter(com.intellij.codeInsight.lookup.CharFilter) Document(com.intellij.openapi.editor.Document) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Aggregations

CompletionProgressIndicator (com.intellij.codeInsight.completion.CompletionProgressIndicator)4 CodeCompletionHandlerBase (com.intellij.codeInsight.completion.CodeCompletionHandlerBase)1 CompletionPhase (com.intellij.codeInsight.completion.CompletionPhase)1 CharFilter (com.intellij.codeInsight.lookup.CharFilter)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 com.intellij.openapi.fileEditor (com.intellij.openapi.fileEditor)1 PsiFile (com.intellij.psi.PsiFile)1