Search in sources :

Example 1 with CodeCompletionHandlerBase

use of com.intellij.codeInsight.completion.CodeCompletionHandlerBase 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 CodeCompletionHandlerBase

use of com.intellij.codeInsight.completion.CodeCompletionHandlerBase in project Perl5-IDEA by Camelcade.

the class PerlAnnotationInsertHandler method handleInsert.

@Override
public void handleInsert(final InsertionContext context, LookupElement item) {
    final Editor editor = context.getEditor();
    if ("returns".equals(item.getLookupString())) {
        EditorModificationUtil.insertStringAtCaret(editor, " ");
        context.setLaterRunnable(() -> new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(context.getProject(), editor, 1));
    }
}
Also used : CodeCompletionHandlerBase(com.intellij.codeInsight.completion.CodeCompletionHandlerBase) Editor(com.intellij.openapi.editor.Editor)

Example 3 with CodeCompletionHandlerBase

use of com.intellij.codeInsight.completion.CodeCompletionHandlerBase in project smali by JesusFreke.

the class SmaliCodeFragmentFactoryTest method assertCompletionContains.

private void assertCompletionContains(String completionText, PsiElement context, String[] expectedItems, String[] disallowedItems) {
    SmaliCodeFragmentFactory codeFragmentFactory = new SmaliCodeFragmentFactory();
    JavaCodeFragment fragment = codeFragmentFactory.createCodeFragment(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, completionText), context, getProject());
    Editor editor = createEditor(fragment.getVirtualFile());
    editor.getCaretModel().moveToOffset(completionText.length());
    new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(getProject(), editor);
    List<LookupElement> elements = LookupManager.getInstance(getProject()).getActiveLookup().getItems();
    HashSet expectedSet = Sets.newHashSet(expectedItems);
    HashSet disallowedSet = Sets.newHashSet(disallowedItems);
    for (LookupElement element : elements) {
        expectedSet.remove(element.toString());
        Assert.assertFalse(disallowedSet.contains(element.toString()));
    }
    Assert.assertTrue(expectedSet.size() == 0);
}
Also used : SmaliCodeFragmentFactory(org.jf.smalidea.debugging.SmaliCodeFragmentFactory) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) CodeCompletionHandlerBase(com.intellij.codeInsight.completion.CodeCompletionHandlerBase) Editor(com.intellij.openapi.editor.Editor) LookupElement(com.intellij.codeInsight.lookup.LookupElement) JavaCodeFragment(com.intellij.psi.JavaCodeFragment) HashSet(java.util.HashSet)

Example 4 with CodeCompletionHandlerBase

use of com.intellij.codeInsight.completion.CodeCompletionHandlerBase in project intellij-plugins by JetBrains.

the class FlexCssCompletionTest method testClassReferenceCompletion.

@JSTestOptions({ JSTestOption.WithJsSupportLoader, JSTestOption.WithFlexFacet })
public void testClassReferenceCompletion() throws Exception {
    configureByFiles(null, FlexCompletionTest.BASE_PATH + getTestName(false) + ".css");
    new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(myProject, myEditor);
    checkResultByFile(FlexCompletionTest.BASE_PATH + getTestName(false) + "_after.css");
}
Also used : CodeCompletionHandlerBase(com.intellij.codeInsight.completion.CodeCompletionHandlerBase) JSTestOptions(com.intellij.lang.javascript.JSTestOptions)

Example 5 with CodeCompletionHandlerBase

use of com.intellij.codeInsight.completion.CodeCompletionHandlerBase in project intellij-community by JetBrains.

the class XmlHighlightingTest method testCorrectGeneratedDtdUpdate.

public void testCorrectGeneratedDtdUpdate() throws Exception {
    configureByFile(BASE_PATH + getTestName(false) + ".xml");
    Collection<HighlightInfo> infos = filterInfos(doHighlighting());
    assertEquals(2, infos.size());
    WriteCommandAction.runWriteCommandAction(null, () -> EditorModificationUtil.deleteSelectedText(myEditor));
    infos = filterInfos(doHighlighting());
    assertEquals(11, infos.size());
    WriteCommandAction.runWriteCommandAction(null, () -> EditorModificationUtil.insertStringAtCaret(myEditor, "<"));
    new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(myProject, myEditor);
    infos = filterInfos(doHighlighting());
    assertEquals(2, infos.size());
    LookupManager.getInstance(myProject).hideActiveLookup();
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) CodeCompletionHandlerBase(com.intellij.codeInsight.completion.CodeCompletionHandlerBase)

Aggregations

CodeCompletionHandlerBase (com.intellij.codeInsight.completion.CodeCompletionHandlerBase)5 Editor (com.intellij.openapi.editor.Editor)2 CompletionProgressIndicator (com.intellij.codeInsight.completion.CompletionProgressIndicator)1 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 TextWithImportsImpl (com.intellij.debugger.engine.evaluation.TextWithImportsImpl)1 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)1 com.intellij.openapi.fileEditor (com.intellij.openapi.fileEditor)1 JavaCodeFragment (com.intellij.psi.JavaCodeFragment)1 HashSet (java.util.HashSet)1 SmaliCodeFragmentFactory (org.jf.smalidea.debugging.SmaliCodeFragmentFactory)1