Search in sources :

Example 91 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-plugins by JetBrains.

the class CompletionTest method doTest.

private void doTest() {
    final String testName = getTestName(true);
    myFixture.configureByFile(testName + ".feature");
    LookupElement[] result = myFixture.completeBasic();
    LookupElement scenarioOutlineLookupElement = null;
    for (LookupElement lookupElement : result) {
        if (lookupElement.getUserDataString().contains("Scenario")) {
            scenarioOutlineLookupElement = lookupElement;
            break;
        }
    }
    assert scenarioOutlineLookupElement != null;
    myFixture.getLookup().setCurrentItem(scenarioOutlineLookupElement);
    myFixture.finishLookup(Lookup.REPLACE_SELECT_CHAR);
    myFixture.checkResultByFile(testName + "_after.feature");
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 92 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement 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)

Example 93 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-plugins by JetBrains.

the class DartServerCompletionTest method selectLookup.

private void selectLookup(@NotNull final String lookupToSelect, final char completionChar) {
    final LookupEx activeLookup = LookupManager.getActiveLookup(getEditor());
    assertNotNull(activeLookup);
    final LookupElement lookup = ContainerUtil.find(activeLookup.getItems(), element -> lookupToSelect.equals(element.getLookupString()));
    assertNotNull(lookupToSelect + " is not in the completion list", lookup);
    activeLookup.setCurrentItem(lookup);
    myFixture.finishLookup(completionChar);
}
Also used : LookupEx(com.intellij.codeInsight.lookup.LookupEx) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 94 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-plugins by JetBrains.

the class ActionScriptCompletionTest method testTwoSdks.

public void testTwoSdks() throws Exception {
    final Sdk sdk45 = FlexTestUtils.createSdk(FlexTestUtils.getPathToCompleteFlexSdk("4.5"), null, true);
    final Sdk sdk46 = FlexTestUtils.createSdk(FlexTestUtils.getPathToCompleteFlexSdk("4.6"), null, false);
    FlexTestUtils.modifyConfigs(myProject, new Consumer<FlexProjectConfigurationEditor>() {

        public void consume(final FlexProjectConfigurationEditor editor) {
            ModifiableFlexBuildConfiguration bc1 = editor.getConfigurations(myModule)[0];
            bc1.setName("1");
            FlexTestUtils.setSdk(bc1, sdk45);
            ModifiableFlexBuildConfiguration bc2 = editor.createConfiguration(myModule);
            bc2.setName("2");
            FlexTestUtils.setSdk(bc2, sdk46);
        }
    });
    final FlexBuildConfigurationManager m = FlexBuildConfigurationManager.getInstance(myModule);
    class TestZZ implements ThrowableRunnable<Exception> {

        private final String myBcName;

        private final String myExpectedTypeText;

        TestZZ(final String bcName, final String expectedTypeText) {
            myBcName = bcName;
            myExpectedTypeText = expectedTypeText;
        }

        @Override
        public void run() throws Exception {
            m.setActiveBuildConfiguration(m.findConfigurationByName(myBcName));
            defaultTest();
            for (LookupElement item : myItems) {
                final LookupElementPresentation p = new LookupElementPresentation();
                item.renderElement(p);
                assertEquals(myExpectedTypeText, p.getTypeText());
            }
        }
    }
    new TestZZ("1", sdk45.getName()).run();
    new TestZZ("2", sdk46.getName()).run();
    new TestZZ("1", sdk45.getName()).run();
}
Also used : FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) ThrowableRunnable(com.intellij.util.ThrowableRunnable) LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) Sdk(com.intellij.openapi.projectRoots.Sdk) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)

Example 95 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-plugins by JetBrains.

the class FlexCompletionInTextFieldBase method checkTextFieldCompletion.

protected void checkTextFieldCompletion(JSExpressionCodeFragment fragment, String[] included, String[] excluded, @Nullable String choose, String file) throws Exception {
    doTestForEditorTextField(fragment, "", "js2", file);
    assertContains(myItems, true, included);
    assertContains(myItems, false, excluded);
    if (choose != null) {
        boolean found = false;
        for (LookupElement item : myItems) {
            if (choose.equals(item.getLookupString())) {
                selectItem(item);
                found = true;
                break;
            }
        }
        assertTrue("Item '" + choose + "' not found in lookup", found);
        checkResultByFile(BASE_PATH + getTestName(false) + "_after.txt");
    }
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Aggregations

LookupElement (com.intellij.codeInsight.lookup.LookupElement)183 PsiElement (com.intellij.psi.PsiElement)33 NotNull (org.jetbrains.annotations.NotNull)32 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)20 Nullable (org.jetbrains.annotations.Nullable)17 ArrayList (java.util.ArrayList)14 Project (com.intellij.openapi.project.Project)12 LookupElementPresentation (com.intellij.codeInsight.lookup.LookupElementPresentation)10 Document (com.intellij.openapi.editor.Document)10 PsiFile (com.intellij.psi.PsiFile)10 Editor (com.intellij.openapi.editor.Editor)9 THashSet (gnu.trove.THashSet)8 LinkedHashSet (java.util.LinkedHashSet)8 PrioritizedLookupElement (com.intellij.codeInsight.completion.PrioritizedLookupElement)7 XmlTag (com.intellij.psi.xml.XmlTag)7 Consumer (com.intellij.util.Consumer)7 HashSet (java.util.HashSet)7 InsertionContext (com.intellij.codeInsight.completion.InsertionContext)6 PsiTypeLookupItem (com.intellij.codeInsight.lookup.PsiTypeLookupItem)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6