Search in sources :

Example 21 with LookupImpl

use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.

the class CodeInsightTestUtil method doLiveTemplateTest.

public static void doLiveTemplateTest(@NotNull final CodeInsightTestFixture fixture, @NotNull final String before, @NotNull final String after) {
    fixture.configureByFile(before);
    new ListTemplatesAction().actionPerformedImpl(fixture.getProject(), fixture.getEditor());
    final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(fixture.getEditor());
    assert lookup != null;
    lookup.finishLookup(Lookup.NORMAL_SELECT_CHAR);
    fixture.checkResultByFile(after, false);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) ListTemplatesAction(com.intellij.codeInsight.template.impl.actions.ListTemplatesAction)

Example 22 with LookupImpl

use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.

the class BaseRefactoringAction method actionPerformed.

@Override
public final void actionPerformed(@NotNull AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    Project project = e.getProject();
    if (project == null)
        return;
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    final Editor editor = e.getData(CommonDataKeys.EDITOR);
    final PsiElement[] elements = getPsiElementArray(dataContext);
    int eventCount = IdeEventQueue.getInstance().getEventCount();
    RefactoringActionHandler handler;
    try {
        handler = getHandler(dataContext);
    } catch (ProcessCanceledException ignored) {
        return;
    }
    if (handler == null) {
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.symbol.to.refactor"));
        CommonRefactoringUtil.showErrorHint(project, editor, message, RefactoringBundle.getCannotRefactorMessage(null), null);
        return;
    }
    InplaceRefactoring activeInplaceRenamer = InplaceRefactoring.getActiveInplaceRenamer(editor);
    if (!InplaceRefactoring.canStartAnotherRefactoring(editor, project, handler, elements) && activeInplaceRenamer != null) {
        InplaceRefactoring.unableToStartWarning(project, editor);
        return;
    }
    if (activeInplaceRenamer == null) {
        final LookupEx lookup = LookupManager.getActiveLookup(editor);
        if (lookup instanceof LookupImpl) {
            Runnable command = () -> ((LookupImpl) lookup).finishLookup(Lookup.NORMAL_SELECT_CHAR);
            Document doc = editor.getDocument();
            DocCommandGroupId group = DocCommandGroupId.noneGroupId(doc);
            CommandProcessor.getInstance().executeCommand(editor.getProject(), command, "Completion", group, UndoConfirmationPolicy.DEFAULT, doc);
        }
    }
    IdeEventQueue.getInstance().setEventCount(eventCount);
    if (editor != null) {
        final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
        if (file == null)
            return;
        DaemonCodeAnalyzer.getInstance(project).autoImportReferenceAtCursor(editor, file);
        handler.invoke(project, editor, file, dataContext);
    } else {
        handler.invoke(project, elements, dataContext);
    }
}
Also used : RefactoringActionHandler(com.intellij.refactoring.RefactoringActionHandler) Document(com.intellij.openapi.editor.Document) Project(com.intellij.openapi.project.Project) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) DocCommandGroupId(com.intellij.openapi.editor.actionSystem.DocCommandGroupId) Editor(com.intellij.openapi.editor.Editor) LookupEx(com.intellij.codeInsight.lookup.LookupEx) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) InplaceRefactoring(com.intellij.refactoring.rename.inplace.InplaceRefactoring)

Example 23 with LookupImpl

use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.

the class CodeCompletionHandlerBase method doComplete.

private void doComplete(CompletionInitializationContext initContext, boolean hasModifiers, int invocationCount, OffsetTranslator translator, OffsetsInFile hostOffsets, OffsetsInFile hostCopyOffsets) {
    final Editor editor = initContext.getEditor();
    CompletionAssertions.checkEditorValid(editor);
    CompletionContext context = createCompletionContext(initContext.getFile(), hostCopyOffsets);
    LookupImpl lookup = obtainLookup(editor, initContext.getProject());
    CompletionParameters parameters = createCompletionParameters(invocationCount, context, editor);
    CompletionPhase phase = CompletionServiceImpl.getCompletionPhase();
    if (phase instanceof CompletionPhase.CommittingDocuments) {
        if (phase.indicator != null) {
            phase.indicator.closeAndFinish(false);
        }
        ((CompletionPhase.CommittingDocuments) phase).replaced = true;
    } else {
        CompletionServiceImpl.assertPhase(CompletionPhase.NoCompletion.getClass());
    }
    final CompletionProgressIndicator indicator = new CompletionProgressIndicator(editor, initContext.getCaret(), parameters, this, initContext.getOffsetMap(), hostOffsets, hasModifiers, lookup);
    Disposer.register(indicator, hostCopyOffsets.getOffsets());
    Disposer.register(indicator, context.getOffsetMap());
    Disposer.register(indicator, translator);
    CompletionServiceImpl.setCompletionPhase(synchronous ? new CompletionPhase.Synchronous(indicator) : new CompletionPhase.BgCalculation(indicator));
    indicator.startCompletion(initContext);
    if (!synchronous) {
        return;
    }
    if (indicator.blockingWaitForFinish(ourAutoInsertItemTimeout)) {
        try {
            indicator.getLookup().refreshUi(true, false);
        } catch (Exception e) {
            CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
            LOG.error(e);
            return;
        }
        completionFinished(indicator, hasModifiers);
        return;
    }
    CompletionServiceImpl.setCompletionPhase(new CompletionPhase.BgCalculation(indicator));
    indicator.showLookup();
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 24 with LookupImpl

use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.

the class CompletionLookupArranger method arrangeItems.

@Override
public Pair<List<LookupElement>, Integer> arrangeItems(@NotNull Lookup lookup, boolean onExplicitAction) {
    List<LookupElement> items = getMatchingItems();
    MultiMap<CompletionSorterImpl, LookupElement> itemsBySorter = groupItemsBySorter(items);
    LookupElement relevantSelection = findMostRelevantItem(itemsBySorter);
    LookupImpl lookupImpl = (LookupImpl) lookup;
    List<LookupElement> listModel = isAlphaSorted() ? sortByPresentation(items) : fillModelByRelevance(lookupImpl, ContainerUtil.newIdentityTroveSet(items), itemsBySorter, relevantSelection);
    int toSelect = getItemToSelect(lookupImpl, listModel, onExplicitAction, relevantSelection);
    LOG.assertTrue(toSelect >= 0);
    addDummyItems(items.size() - listModel.size(), listModel);
    return new Pair<>(listModel, toSelect);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) CompletionSorterImpl(com.intellij.codeInsight.completion.impl.CompletionSorterImpl) LiveTemplateLookupElement(com.intellij.codeInsight.template.impl.LiveTemplateLookupElement) Pair(com.intellij.openapi.util.Pair)

Example 25 with LookupImpl

use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.

the class TemplatesCompletionTest method testAutopopupWithEnabledLiveTemplatesInCompletion.

public void testAutopopupWithEnabledLiveTemplatesInCompletion() {
    LiveTemplateCompletionContributor.setShowTemplatesInTests(false, myFixture.getTestRootDisposable());
    configureByFile();
    type("instanceof");
    LookupImpl lookup = getLookup();
    assertNotNull(lookup);
    assertEquals(1, lookup.getItems().size());
    LookupElement item = lookup.getCurrentItem();
    assertNotNull(item);
    assertInstanceOf(item, PostfixTemplateLookupElement.class);
    assertInstanceOf(((PostfixTemplateLookupElement) item).getPostfixTemplate(), InstanceofExpressionPostfixTemplate.class);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Aggregations

LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)39 ListTemplatesAction (com.intellij.codeInsight.template.impl.actions.ListTemplatesAction)5 Document (com.intellij.openapi.editor.Document)5 Editor (com.intellij.openapi.editor.Editor)5 Project (com.intellij.openapi.project.Project)5 LookupElement (com.intellij.codeInsight.lookup.LookupElement)4 PlainPrefixMatcher (com.intellij.codeInsight.completion.PlainPrefixMatcher)2 LookupEx (com.intellij.codeInsight.lookup.LookupEx)2 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 CodeInsightSettings (com.intellij.codeInsight.CodeInsightSettings)1 CamelHumpMatcher (com.intellij.codeInsight.completion.impl.CamelHumpMatcher)1 CompletionSorterImpl (com.intellij.codeInsight.completion.impl.CompletionSorterImpl)1 Lookup (com.intellij.codeInsight.lookup.Lookup)1 LookupManager (com.intellij.codeInsight.lookup.LookupManager)1 LiveTemplateLookupElement (com.intellij.codeInsight.template.impl.LiveTemplateLookupElement)1 CommandAdapter (com.intellij.openapi.command.CommandAdapter)1 CommandEvent (com.intellij.openapi.command.CommandEvent)1 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 DocCommandGroupId (com.intellij.openapi.editor.actionSystem.DocCommandGroupId)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1