Search in sources :

Example 1 with LookupEx

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

the class PyTestCase method completeCaretWithMultipleVariants.

/**
   * When you have more than one completion variant, you may use this method providing variant to choose.
   * It only works for one caret (multiple carets not supported) and since it puts tab after completion, be sure to limit
   * line somehow (i.e. with comment).
   * <br/>
   * Example: "user.n[caret]." There are "name" and "nose" fields.
   * By calling this function with "nose" you will end with "user.nose  ".
   */
protected final void completeCaretWithMultipleVariants(@NotNull final String... desiredVariants) {
    final LookupElement[] lookupElements = myFixture.completeBasic();
    final LookupEx lookup = myFixture.getLookup();
    if (lookupElements != null && lookupElements.length > 1) {
        // More than one element returned, check directly because completion can't work in this case
        for (final LookupElement element : lookupElements) {
            final String suggestedString = element.getLookupString();
            if (Arrays.asList(desiredVariants).contains(suggestedString)) {
                myFixture.getLookup().setCurrentItem(element);
                lookup.setCurrentItem(element);
                myFixture.completeBasicAllCarets('\t');
                return;
            }
        }
    }
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) LookupEx(com.intellij.codeInsight.lookup.LookupEx)

Example 2 with LookupEx

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

the class ShowIntentionActionsHandler method invoke.

@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    if (editor instanceof EditorWindow) {
        editor = ((EditorWindow) editor).getDelegate();
        file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
    }
    final LookupEx lookup = LookupManager.getActiveLookup(editor);
    if (lookup != null) {
        lookup.showElementActions();
        return;
    }
    final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(project);
    letAutoImportComplete(editor, file, codeAnalyzer);
    ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
    ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);
    IntentionHintComponent hintComponent = codeAnalyzer.getLastIntentionHint();
    if (hintComponent != null) {
        IntentionHintComponent.PopupUpdateResult result = hintComponent.isForEditor(editor) ? hintComponent.updateActions(intentions) : IntentionHintComponent.PopupUpdateResult.HIDE_AND_RECREATE;
        if (result == IntentionHintComponent.PopupUpdateResult.HIDE_AND_RECREATE) {
            hintComponent.hide();
        }
    }
    if (HintManagerImpl.getInstanceImpl().performCurrentQuestionAction())
        return;
    //intentions check isWritable before modification: if (!file.isWritable()) return;
    TemplateState state = TemplateManagerImpl.getTemplateState(editor);
    if (state != null && !state.isFinished()) {
        return;
    }
    if (!intentions.isEmpty()) {
        IntentionHintComponent.showIntentionHint(project, file, editor, intentions, true);
    }
}
Also used : ShowIntentionsPass(com.intellij.codeInsight.daemon.impl.ShowIntentionsPass) DaemonCodeAnalyzerImpl(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl) LookupEx(com.intellij.codeInsight.lookup.LookupEx) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 3 with LookupEx

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

the class DocumentationManager method showJavaDocInfo.

public void showJavaDocInfo(final Editor editor, @Nullable final PsiFile file, boolean requestFocus, @Nullable final Runnable closeCallback) {
    myEditor = editor;
    final Project project = getProject(file);
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    final PsiElement list = ParameterInfoController.findArgumentList(file, editor.getCaretModel().getOffset(), -1);
    PsiElement expressionList = null;
    if (list != null) {
        LookupEx lookup = LookupManager.getInstance(myProject).getActiveLookup();
        if (lookup != null) {
            // take completion variants for documentation then
            expressionList = null;
        } else {
            expressionList = list;
        }
    }
    final PsiElement originalElement = getContextElement(editor, file);
    PsiElement element = assertSameProject(findTargetElement(editor, file));
    if (element == null && expressionList != null) {
        element = expressionList;
    }
    //file == null for text field editor
    if (element == null && file == null)
        return;
    if (element == null) {
        // look if we are within a javadoc comment
        element = assertSameProject(originalElement);
        if (element == null)
            return;
        PsiComment comment = PsiTreeUtil.getParentOfType(element, PsiComment.class);
        if (comment == null)
            return;
        element = comment instanceof PsiDocCommentBase ? ((PsiDocCommentBase) comment).getOwner() : comment.getParent();
        if (element == null)
            return;
    //if (!(element instanceof PsiDocCommentOwner)) return null;
    }
    final PopupUpdateProcessor updateProcessor = new PopupUpdateProcessor(project) {

        @Override
        public void updatePopup(Object lookupIteObject) {
            if (lookupIteObject == null) {
                return;
            }
            if (lookupIteObject instanceof PsiElement) {
                doShowJavaDocInfo((PsiElement) lookupIteObject, false, this, originalElement, closeCallback);
                return;
            }
            DocumentationProvider documentationProvider = getProviderFromElement(file);
            PsiElement element = documentationProvider.getDocumentationElementForLookupItem(PsiManager.getInstance(myProject), lookupIteObject, originalElement);
            if (element == null)
                return;
            if (myEditor != null) {
                final PsiFile file = element.getContainingFile();
                if (file != null) {
                    Editor editor = myEditor;
                    showJavaDocInfo(myEditor, file, false);
                    myEditor = editor;
                }
            } else {
                doShowJavaDocInfo(element, false, this, originalElement, closeCallback);
            }
        }
    };
    doShowJavaDocInfo(element, requestFocus, updateProcessor, originalElement, closeCallback);
}
Also used : Project(com.intellij.openapi.project.Project) PopupUpdateProcessor(com.intellij.ui.popup.PopupUpdateProcessor) LookupEx(com.intellij.codeInsight.lookup.LookupEx) Editor(com.intellij.openapi.editor.Editor)

Example 4 with LookupEx

use of com.intellij.codeInsight.lookup.LookupEx in project Perl5-IDEA by Camelcade.

the class PerlCompletionPopupTest method doCheckAutopopupResult.

private void doCheckAutopopupResult(@NotNull String type, boolean result) {
    myTester.typeWithPauses(type);
    LookupEx activeLookup = LookupManager.getActiveLookup(getEditor());
    if (result) {
        assertNotNull(activeLookup);
    } else {
        assertNull(activeLookup);
    }
}
Also used : LookupEx(com.intellij.codeInsight.lookup.LookupEx)

Example 5 with LookupEx

use of com.intellij.codeInsight.lookup.LookupEx in project android by JetBrains.

the class AndroidLayoutDomTest method testDimenUnitsCompletion1.

public void testDimenUnitsCompletion1() throws Exception {
    VirtualFile file = copyFileToProject(getTestName(true) + ".xml");
    myFixture.configureFromExistingVirtualFile(file);
    myFixture.complete(CompletionType.BASIC);
    UsefulTestCase.assertSameElements(myFixture.getLookupElementStrings(), "3dp", "3px", "3sp", "3pt", "3mm", "3in");
    PsiElement originalElement = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
    LookupEx lookup = myFixture.getLookup();
    LookupElement dpElement = null;
    LookupElement pxElement = null;
    for (LookupElement element : lookup.getItems()) {
        if (element.getLookupString().endsWith("dp")) {
            dpElement = element;
        } else if (element.getLookupString().endsWith("px")) {
            pxElement = element;
        }
    }
    DocumentationProvider provider;
    PsiElement docTargetElement;
    lookup.setCurrentItem(dpElement);
    docTargetElement = DocumentationManager.getInstance(getProject()).findTargetElement(myFixture.getEditor(), myFixture.getFile(), originalElement);
    provider = DocumentationManager.getProviderFromElement(docTargetElement);
    assertEquals("<html><body><b>Density-independent Pixels</b> - an abstract unit that is based on the physical " + "density of the screen.</body></html>", provider.generateDoc(docTargetElement, originalElement));
    lookup.setCurrentItem(pxElement);
    docTargetElement = DocumentationManager.getInstance(getProject()).findTargetElement(myFixture.getEditor(), myFixture.getFile(), originalElement);
    provider = DocumentationManager.getProviderFromElement(docTargetElement);
    assertEquals("<html><body><b>Pixels</b> - corresponds to actual pixels on the screen. Not recommended.</body></html>", provider.generateDoc(docTargetElement, originalElement));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LookupEx(com.intellij.codeInsight.lookup.LookupEx) LookupElement(com.intellij.codeInsight.lookup.LookupElement) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Aggregations

LookupEx (com.intellij.codeInsight.lookup.LookupEx)9 LookupElement (com.intellij.codeInsight.lookup.LookupElement)4 LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)2 Editor (com.intellij.openapi.editor.Editor)2 Project (com.intellij.openapi.project.Project)2 DaemonCodeAnalyzerImpl (com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl)1 ShowIntentionsPass (com.intellij.codeInsight.daemon.impl.ShowIntentionsPass)1 LookupAdapter (com.intellij.codeInsight.lookup.LookupAdapter)1 LookupEvent (com.intellij.codeInsight.lookup.LookupEvent)1 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)1 EditorWindow (com.intellij.injected.editor.EditorWindow)1 DocumentationProvider (com.intellij.lang.documentation.DocumentationProvider)1 Document (com.intellij.openapi.editor.Document)1 DocCommandGroupId (com.intellij.openapi.editor.actionSystem.DocCommandGroupId)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 RefactoringActionHandler (com.intellij.refactoring.RefactoringActionHandler)1 InplaceRefactoring (com.intellij.refactoring.rename.inplace.InplaceRefactoring)1 SpellCheckingInspection (com.intellij.spellchecker.inspections.SpellCheckingInspection)1 PopupUpdateProcessor (com.intellij.ui.popup.PopupUpdateProcessor)1