Search in sources :

Example 26 with LookupImpl

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

the class ShowQuickDocInfoAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    if (project != null && editor != null) {
        FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_FEATURE);
        final LookupImpl lookup = (LookupImpl) LookupManager.getInstance(project).getActiveLookup();
        if (lookup != null) {
            //dumpLookupElementWeights(lookup);
            FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_LOOKUP_FEATURE);
        }
        actionPerformedImpl(project, editor);
    } else if (project != null && element != null) {
        FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_CTRLN_FEATURE);
        CommandProcessor.getInstance().executeCommand(project, () -> DocumentationManager.getInstance(project).showJavaDocInfo(element, null), getCommandName(), null);
    }
}
Also used : Project(com.intellij.openapi.project.Project) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Example 27 with LookupImpl

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

the class CompletionAutoPopupHandler method checkAutoPopup.

@Override
public Result checkAutoPopup(char charTyped, final Project project, final Editor editor, final PsiFile file) {
    LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(editor);
    if (LOG.isDebugEnabled()) {
        LOG.debug("checkAutoPopup: character=" + charTyped + ";");
        LOG.debug("phase=" + CompletionServiceImpl.getCompletionPhase());
        LOG.debug("lookup=" + lookup);
        LOG.debug("currentCompletion=" + CompletionServiceImpl.getCompletionService().getCurrentCompletion());
    }
    if (lookup != null) {
        if (editor.getSelectionModel().hasSelection()) {
            lookup.performGuardedChange(() -> EditorModificationUtil.deleteSelectedText(editor));
        }
        return Result.STOP;
    }
    if (Character.isLetter(charTyped) || charTyped == '_') {
        AutoPopupController.getInstance(project).scheduleAutoPopup(editor);
        return Result.STOP;
    }
    return Result.CONTINUE;
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl)

Example 28 with LookupImpl

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

the class CompletionTestBase method doTest.

protected void doTest(String directory) {
    CamelHumpMatcher.forceStartMatching(myFixture.getTestRootDisposable());
    final List<String> stringList = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test");
    if (directory.length() != 0)
        directory += "/";
    final String fileName = directory + getTestName(true) + "." + getExtension();
    myFixture.addFileToProject(fileName, stringList.get(0));
    myFixture.configureByFile(fileName);
    boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX;
    CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = false;
    CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false;
    String result = "";
    try {
        myFixture.completeBasic();
        final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myFixture.getEditor());
        if (lookup != null) {
            List<LookupElement> items = lookup.getItems();
            if (!addReferenceVariants()) {
                items = ContainerUtil.findAll(items, lookupElement -> {
                    final Object o = lookupElement.getObject();
                    return !(o instanceof PsiMember) && !(o instanceof GrVariable) && !(o instanceof GroovyResolveResult) && !(o instanceof PsiPackage);
                });
            }
            Collections.sort(items, (o1, o2) -> o1.getLookupString().compareTo(o2.getLookupString()));
            result = "";
            for (LookupElement item : items) {
                result = result + "\n" + item.getLookupString();
            }
            result = result.trim();
            LookupManager.getInstance(myFixture.getProject()).hideActiveLookup();
        }
    } finally {
        CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = true;
        CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = old;
    }
    assertEquals(StringUtil.trimEnd(stringList.get(1), "\n"), result);
}
Also used : PsiPackage(com.intellij.psi.PsiPackage) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) PsiMember(com.intellij.psi.PsiMember) JavaCodeInsightFixtureTestCase(com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase) LookupElement(com.intellij.codeInsight.lookup.LookupElement) StringUtil(com.intellij.openapi.util.text.StringUtil) LookupManager(com.intellij.codeInsight.lookup.LookupManager) CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) TestUtils(org.jetbrains.plugins.groovy.util.TestUtils) ContainerUtil(com.intellij.util.containers.ContainerUtil) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) List(java.util.List) GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) CamelHumpMatcher(com.intellij.codeInsight.completion.impl.CamelHumpMatcher) Collections(java.util.Collections) GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) PsiPackage(com.intellij.psi.PsiPackage) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiMember(com.intellij.psi.PsiMember)

Example 29 with LookupImpl

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

the class CompletionTestCase method selectItem.

protected void selectItem(LookupElement item, char ch) {
    final LookupImpl lookup = (LookupImpl) LookupManager.getInstance(myProject).getActiveLookup();
    assert lookup != null;
    lookup.setCurrentItem(item);
    lookup.finishLookup(ch);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl)

Example 30 with LookupImpl

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

the class LightCompletionTestCase method complete.

protected void complete(final int time) {
    new CodeCompletionHandlerBase(myType).invokeCompletion(getProject(), getEditor(), time);
    LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
    myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY);
    myPrefix = lookup == null ? null : lookup.itemPattern(lookup.getItems().get(0));
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl)

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