com.intellij.codeInsight.completion.CompletionType Java Examples
The following examples show how to use
com.intellij.codeInsight.completion.CompletionType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdditionalLanguagesCompletionContributor.java From intellij with Apache License 2.0 | 6 votes |
public AdditionalLanguagesCompletionContributor() { extend( CompletionType.BASIC, psiElement() .withLanguage(ProjectViewLanguage.INSTANCE) .inside( psiElement(ProjectViewPsiListSection.class) .withText( StandardPatterns.string() .startsWith(AdditionalLanguagesSection.KEY.getName()))), new CompletionProvider<CompletionParameters>() { @Override protected void addCompletions( CompletionParameters parameters, ProcessingContext context, CompletionResultSet result) { for (LanguageClass type : availableAdditionalLanguages(parameters.getEditor().getProject())) { result.addElement(LookupElementBuilder.create(type.getName())); } } }); }
Example #2
Source File: PantsCompletionTestBase.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
protected void doTestVariantsInner(String fileName) throws Throwable { final VirtualFile virtualFile = myFixture.copyFileToProject(fileName); final Scanner in = new Scanner(virtualFile.getInputStream()); final CompletionType type = CompletionType.valueOf(in.next()); final int count = in.nextInt(); final CheckType checkType = CheckType.valueOf(in.next()); final List<String> variants = new ArrayList<>(); while (in.hasNext()) { final String variant = StringUtil.strip(in.next(), CharFilter.NOT_WHITESPACE_FILTER); if (variant.length() > 0) { variants.add(variant); } } myFixture.complete(type, count); checkCompletion(checkType, variants); }
Example #3
Source File: TCACompletionContributorTest.java From idea-php-typo3-plugin with MIT License | 6 votes |
public void testCanCompleteRenderTypes() { List<String> lookupElementStrings; myFixture.configureByText(PhpFileType.INSTANCE, "<?php $foo = ['renderType' => '<caret>'];"); myFixture.complete(CompletionType.BASIC); lookupElementStrings = myFixture.getLookupElementStrings(); assertTrue("Can complete empty value", lookupElementStrings.contains("selectSingle")); myFixture.configureByText(PhpFileType.INSTANCE, "<?php $foo = ['renderType' => 's<caret>'];"); myFixture.complete(CompletionType.BASIC); lookupElementStrings = myFixture.getLookupElementStrings(); assertTrue("Can complete partial value", lookupElementStrings.contains("selectSingle")); myFixture.configureByText(PhpFileType.INSTANCE, "<?php $GLOBALS['renderType'] = '<caret>'];"); myFixture.complete(CompletionType.BASIC); lookupElementStrings = myFixture.getLookupElementStrings(); assertTrue("Can complete empty value", lookupElementStrings.contains("selectSingle")); myFixture.configureByText(PhpFileType.INSTANCE, "<?php $GLOBALS['renderType'] = 's<caret>'];"); myFixture.complete(CompletionType.BASIC); lookupElementStrings = myFixture.getLookupElementStrings(); assertTrue("Can complete partial value", lookupElementStrings.contains("selectSingle")); }
Example #4
Source File: TCACompletionContributorTest.java From idea-php-typo3-plugin with MIT License | 6 votes |
public void testCanCompleteTypes() { List<String> lookupElementStrings; myFixture.configureByText(PhpFileType.INSTANCE, "<?php $foo = ['type' => '<caret>'];"); myFixture.complete(CompletionType.BASIC); lookupElementStrings = myFixture.getLookupElementStrings(); assertTrue("Can complete empty value", lookupElementStrings.contains("text")); myFixture.configureByText(PhpFileType.INSTANCE, "<?php $foo = ['type' => 't<caret>'];"); myFixture.complete(CompletionType.BASIC); lookupElementStrings = myFixture.getLookupElementStrings(); assertTrue("Can complete partial value", lookupElementStrings.contains("text")); myFixture.configureByText(PhpFileType.INSTANCE, "<?php $GLOBALS['type'] = '<caret>'];"); myFixture.complete(CompletionType.BASIC); lookupElementStrings = myFixture.getLookupElementStrings(); assertTrue("Can complete empty value", lookupElementStrings.contains("text")); myFixture.configureByText(PhpFileType.INSTANCE, "<?php $GLOBALS['type'] = 't<caret>'];"); myFixture.complete(CompletionType.BASIC); lookupElementStrings = myFixture.getLookupElementStrings(); assertTrue("Can complete partial value", lookupElementStrings.contains("text")); }
Example #5
Source File: CodeInsightTestFixtureImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void testCompletionTyping(final String[] filesBefore, String toType, final String fileAfter) { assertInitialized(); configureByFiles(filesBefore); complete(CompletionType.BASIC); for (int i = 0; i < toType.length(); i++) { type(toType.charAt(i)); } try { checkResultByFile(fileAfter); } catch (RuntimeException e) { System.out.println("LookupElementStrings = " + getLookupElementStrings()); throw e; } }
Example #6
Source File: AutoPopupControllerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void scheduleAutoPopup(@Nonnull Editor editor, @Nonnull CompletionType completionType, @Nullable final Condition<? super PsiFile> condition) { //if (ApplicationManager.getApplication().isUnitTestMode() && !TestModeFlags.is(CompletionAutoPopupHandler.ourTestingAutopopup)) { // return; //} boolean alwaysAutoPopup = Boolean.TRUE.equals(editor.getUserData(ALWAYS_AUTO_POPUP)); if (!CodeInsightSettings.getInstance().AUTO_POPUP_COMPLETION_LOOKUP && !alwaysAutoPopup) { return; } if (PowerSaveMode.isEnabled()) { return; } if (!CompletionServiceImpl.isPhase(CompletionPhase.CommittingDocuments.class, CompletionPhase.NoCompletion.getClass())) { return; } final CompletionProgressIndicator currentCompletion = CompletionServiceImpl.getCurrentCompletionProgressIndicator(); if (currentCompletion != null) { currentCompletion.closeAndFinish(true); } CompletionPhase.CommittingDocuments.scheduleAsyncCompletion(editor, completionType, condition, myProject, null); }
Example #7
Source File: HaskellCompletionTestBase.java From intellij-haskforce with Apache License 2.0 | 6 votes |
protected void doTestVariantsInner(CompletionType type, int count, CheckType checkType, String... variants) throws Throwable { myFixture.complete(type, count); List<String> stringList = myFixture.getLookupElementStrings(); assertNotNull("\nPossibly the single variant has been completed.\n" + "File after:\n" + myFixture.getFile().getText(), stringList); Collection<String> varList = new ArrayList<String>(Arrays.asList(variants)); if (checkType == CheckType.EQUALS) { UsefulTestCase.assertSameElements(stringList, variants); } else if (checkType == CheckType.INCLUDES) { varList.removeAll(stringList); assertTrue("Missing variants: " + varList, varList.isEmpty()); } else if (checkType == CheckType.EXCLUDES) { varList.retainAll(stringList); assertTrue("Unexpected variants: " + varList, varList.isEmpty()); } }
Example #8
Source File: BashPerformanceTest.java From BashSupport with Apache License 2.0 | 6 votes |
private void doTest(final int iterations) { myFixture.configureByFile("functions_issue96.bash"); enableInspections(); long start = System.currentTimeMillis(); PlatformTestUtil.startPerformanceTest(getTestName(true), iterations * 2000, () -> { for (int i = 0; i < iterations; i++) { long innerStart = System.currentTimeMillis(); Editor editor = myFixture.getEditor(); editor.getCaretModel().moveToOffset(editor.getDocument().getTextLength()); myFixture.type("\n"); myFixture.type("echo \"hello world\"\n"); myFixture.type("pri"); myFixture.complete(CompletionType.BASIC); System.out.println("Cycle duration: " + (System.currentTimeMillis() - innerStart)); } }).usesAllCPUCores().attempts(1).assertTiming(); System.out.println("Complete duration: " + (System.currentTimeMillis() - start)); }
Example #9
Source File: ShaderLabCGCompletionContributor.java From consulo-unity3d with Apache License 2.0 | 6 votes |
public ShaderLabCGCompletionContributor() { extend(CompletionType.BASIC, StandardPatterns.psiElement().withLanguage(CGLanguage.INSTANCE), new CompletionProvider() { @RequiredReadAction @Override public void addCompletions(@Nonnull CompletionParameters parameters, ProcessingContext context, @Nonnull final CompletionResultSet result) { Place shreds = InjectedLanguageUtil.getShreds(parameters.getOriginalFile()); for(PsiLanguageInjectionHost.Shred shred : shreds) { PsiLanguageInjectionHost host = shred.getHost(); if(host instanceof ShaderCGScript) { ShaderLabFile containingFile = (ShaderLabFile) host.getContainingFile(); ShaderReference.consumeProperties(containingFile, result::addElement); } } } }); }
Example #10
Source File: HaxeCompletionTestBase.java From intellij-haxe with Apache License 2.0 | 6 votes |
protected void doTestVariantsInner(String fileName) throws Throwable { final VirtualFile virtualFile = myFixture.copyFileToProject(fileName); final Scanner in = new Scanner(virtualFile.getInputStream()); final CompletionType type = CompletionType.valueOf(in.next()); final int count = in.nextInt(); final CheckType checkType = CheckType.valueOf(in.next()); final List<String> variants = new ArrayList<String>(); while (in.hasNext()) { final String variant = StringUtil.strip(in.next(), CharFilter.WHITESPACE_FILTER); if (variant.length() > 0) { variants.add(variant); } } myFixture.complete(type, count); checkCompletion(checkType, variants); }
Example #11
Source File: YamlCompletionContributorTest.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private void assertCompletion3rdInvocationContains(String configureByText, String... lookupStrings) { myFixture.configureByText(YAMLFileType.YML, configureByText); myFixture.complete(CompletionType.BASIC, 3); if(lookupStrings.length == 0) { fail("No lookup element given"); } List<String> lookupElements = myFixture.getLookupElementStrings(); if(lookupElements == null || lookupElements.size() == 0) { fail(String.format("failed that empty completion contains %s", Arrays.toString(lookupStrings))); } for (String s : lookupStrings) { if(!lookupElements.contains(s)) { fail(String.format("failed that completion contains %s in %s", s, lookupElements.toString())); } } }
Example #12
Source File: BuiltInSymbolCompletionContributor.java From intellij with Apache License 2.0 | 6 votes |
public BuiltInSymbolCompletionContributor() { extend( CompletionType.BASIC, psiElement() .withLanguage(BuildFileLanguage.INSTANCE) .withParent(ReferenceExpression.class) .andNot(psiComment()) .andNot(psiElement().afterLeaf(psiElement(BuildToken.fromKind(TokenKind.INT)))) .andNot(psiElement().inside(FuncallExpression.class)) .andNot(psiElement().afterLeaf(psiElement().withText("."))) .andNot(psiElement().inFile(psiFile(BuildFileWithCustomCompletion.class))), new CompletionProvider<CompletionParameters>() { @Override protected void addCompletions( CompletionParameters parameters, ProcessingContext context, CompletionResultSet result) { for (String symbol : BuiltInNamesProvider.GLOBALS) { result.addElement(LookupElementBuilder.create(symbol)); } } }); }
Example #13
Source File: XmlEndpointSmartCompletionTestIT.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testXmlMultilineTestData() { myFixture.configureByText("CamelRoute.xml", getXmlMultilineTestData()); myFixture.complete(CompletionType.BASIC, 1); List<String> strings = myFixture.getLookupElementStrings(); assertEquals("There is many options", 8, strings.size()); assertThat(strings, not(containsInAnyOrder( "timer:trigger?repeatCount=10&", "&fixedRate=false", "&daemon=false", "&period=10"))); myFixture.type('\n'); String xmlInsertAfterQuestionMarkTestData = getXmlMultilineTestData().replace("<caret>", "&bridgeErrorHandler="); myFixture.checkResult(xmlInsertAfterQuestionMarkTestData); }
Example #14
Source File: KeywordsCompletionTest.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 5 votes |
public void testKeywords() throws Exception { myFixture.configureByText("test.cyp", "<caret>"); myFixture.complete(CompletionType.BASIC); List<String> strings = myFixture.getLookupElementStrings(); assertThat(strings) .containsAll(CypherKeywords.KEYWORDS); }
Example #15
Source File: NamespaceCollectorTest.java From intellij-xquery with Apache License 2.0 | 5 votes |
public void testVariableNamespaceCompletion() { myFixture.configureByFiles("VariableNamespaceNameCompletion.xq"); myFixture.complete(CompletionType.BASIC, 1); List<String> strings = myFixture.getLookupElementStrings(); List<String> referenceBasedEntries = findAll(strings, new MatchingStringCondition("xxx")); assertEquals(0, referenceBasedEntries.size()); }
Example #16
Source File: XmlEndpointSmartCompletionTestIT.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testXmlMultilineTest2Data() { myFixture.configureByText("CamelRoute.xml", getXmlMultilineTest2Data()); myFixture.complete(CompletionType.BASIC, 1); List<String> strings = myFixture.getLookupElementStrings(); assertEquals("There is many options", 8, strings.size()); assertThat(strings, not(containsInAnyOrder( "timer:trigger?repeatCount=10", "&fixedRate=false", "&daemon=false", "&period=10"))); myFixture.type('\n'); String xmlInsertAfterQuestionMarkTestData = getXmlMultilineTest2Data().replace("<caret>", "&bridgeErrorHandler="); myFixture.checkResult(xmlInsertAfterQuestionMarkTestData); }
Example #17
Source File: CamelXmlReferenceContributor.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public CamelXmlReferenceContributor() { addCompletionExtension(new BeanReferenceCompletionExtension()); addCompletionExtension(new BlueprintPropertyNameCompletionExtension()); addCompletionExtension(new CamelEndpointNameCompletionExtension()); addCompletionExtension(new CamelEndpointSmartCompletionExtension(true)); extend(CompletionType.BASIC, psiElement().and(psiElement().inside(PsiFile.class).inFile(matchFileType("xml"))), new EndpointCompletion(getCamelCompletionExtensions()) ); }
Example #18
Source File: JavaCamelBeanReferenceSmartCompletionTestIT.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testJavaBeanTestDataCompletionWithCaretInsideMultipleMethodRef() { myFixture.configureByFiles("CompleteJavaBeanRoute5TestData.java", "CompleteJavaBeanMultipleMethodTestData.java", "CompleteJavaBeanSuperClassTestData.java", "CompleteJavaBeanMethodPropertyTestData.properties"); myFixture.complete(CompletionType.BASIC, 1); List<String> strings = myFixture.getLookupElementStrings(); assertEquals(3, strings.size()); assertThat(strings, Matchers.hasItems("multipleMethodsWithAnotherName", "multipleMethodsWithSameName", "multipleMethodsWithSameName")); }
Example #19
Source File: MuleElementsCompletionContributor.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
public MuleElementsCompletionContributor() { extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_NAME) .afterSibling(psiElement(XmlTokenType.XML_START_TAG_START)).withSuperParent(2, or( xmlTag().withLocalName(MuleConfigConstants.FLOW_TAG_NAME), xmlTag().withLocalName(MuleConfigConstants.WHEN_TAG_NAME), xmlTag().withLocalName(MuleConfigConstants.OTHERWISE_TAG_NAME), xmlTag().withLocalName(MuleConfigConstants.FOREACH_TAG_NAME), xmlTag().withLocalName(MuleConfigConstants.CHAIN_TAG_NAME), xmlTag().withLocalName(MuleConfigConstants.ENRICHER), xmlTag().withLocalName(MuleConfigConstants.SUB_FLOW_TAG_NAME)) ), new MuleElementCompletionProvider()); }
Example #20
Source File: CommandNameCompletionProvider.java From BashSupport with Apache License 2.0 | 5 votes |
@Override void addTo(CompletionContributor contributor) { BashPsiPattern internal = new BashPsiPattern().withParent(BashInternalCommand.class); BashPsiPattern generic = new BashPsiPattern().withParent(BashGenericCommand.class); ElementPattern<PsiElement> internalOrGeneric = StandardPatterns.or(internal, generic); BashPsiPattern pattern = new BashPsiPattern().withParent(internalOrGeneric); contributor.extend(CompletionType.BASIC, pattern, this); }
Example #21
Source File: JavaEndpointSmartCompletionValueTestIT.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testDefaultValue() { myFixture.configureByFiles("CompleteJavaEndpointValueDefaultTestData.java"); myFixture.complete(CompletionType.BASIC, 1); List<String> strings = myFixture.getLookupElementStrings(); assertEquals(1, strings.size()); assertThat(strings, Matchers.contains("file:inbox?delay=500")); }
Example #22
Source File: PropertyEndpointSmartCompletionTestIT.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testInTheMiddleUnresolvedOptionsCompletion() { myFixture.configureByText("TestData.properties", getInTheMiddleUnresolvedOptionsTestData()); myFixture.complete(CompletionType.BASIC, 1); List<String> strings = myFixture.getLookupElementStrings(); assertThat(strings, Matchers.not(Matchers.contains("timer:trigger?repeatCount=10"))); assertThat(strings, Matchers.contains("timer:trigger?repeatCount=10&exceptionHandler", "timer:trigger?repeatCount=10&exchangePattern")); assertTrue("Expect exactly 2 options", strings.size() == 2); myFixture.type('\n'); String result = getInTheMiddleUnresolvedOptionsTestData().replace("<caret>", "ceptionHandler="); myFixture.checkResult(result); }
Example #23
Source File: IncludeCompletionTest.java From reasonml-idea-plugin with MIT License | 5 votes |
public void testIncludeEOF() { myFixture.configureByText("A.re", "let x = 1;"); myFixture.configureByText("B.re", "include A;\nlet y = 2;\n<caret>"); myFixture.complete(CompletionType.BASIC, 1); List<String> strings = myFixture.getLookupElementStrings(); assertSize(10, strings); assertSameElements(strings, "exception", "external", "include", "let", "module", "open", "type", "A", "y", "x"); }
Example #24
Source File: JavaPropertyPlaceholdersSmartCompletionTestIT.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testWithExcludeFileWithPath() { ServiceManager.getService(CamelPreferenceService.class).setExcludePropertyFiles(Collections.singletonList("**/src/CompleteExclude*")); myFixture.configureByFiles("CompleteYmlPropertyTestData.java", "CompleteJavaPropertyTestData.properties", "CompleteExcludePropertyTestData.properties"); myFixture.complete(CompletionType.BASIC, 1); List<String> strings = myFixture.getLookupElementStrings(); assertTrue(strings.containsAll(Arrays.asList("ftp.client}}", "ftp.server}}"))); assertEquals(2, strings.size()); }
Example #25
Source File: BuckCompletionContributor.java From Buck-IntelliJ-Plugin with Apache License 2.0 | 5 votes |
public BuckCompletionContributor() { // Auto completion for basic rule names extend( CompletionType.BASIC, PlatformPatterns.psiElement(BuckTypes.IDENTIFIER).withLanguage(BuckLanguage.INSTANCE), BuckKeywordsCompletionProvider.INSTANCE); }
Example #26
Source File: FreeCompletionTest.java From reasonml-idea-plugin with MIT License | 5 votes |
public void testRml_letPrivateFromInside() { configureCode("A.re" , "let x%private = 1; <caret>"); myFixture.complete(CompletionType.BASIC, 1); List<String> elements = myFixture.getLookupElementStrings(); assertContainsElements(elements, "x"); }
Example #27
Source File: FreeCompletionTest.java From reasonml-idea-plugin with MIT License | 5 votes |
public void testRml_letPrivateFromOutside() { configureCode("A.re" , "let x%private = 1;"); configureCode("B.re" , "open A; <caret>"); myFixture.complete(CompletionType.BASIC, 1); List<String> elements = myFixture.getLookupElementStrings(); assertDoesntContain(elements, "x"); }
Example #28
Source File: AnnotationLightCodeInsightFixtureTestCase.java From idea-php-generics-plugin with MIT License | 5 votes |
@Override public void run() { CommandProcessor.getInstance().executeCommand(getProject(), () -> { final CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(CompletionType.BASIC) { @Override protected void completionFinished(final CompletionProgressIndicator indicator, boolean hasModifiers) { // find our lookup element final LookupElement lookupElement = ContainerUtil.find(indicator.getLookup().getItems(), insert::match); if(lookupElement == null) { fail("No matching lookup element found"); } // overwrite behavior and force completion + insertHandler CommandProcessor.getInstance().executeCommand(indicator.getProject(), new Runnable() { @Override public void run() { //indicator.setMergeCommand(); Currently method has package level access indicator.getLookup().finishLookup(Lookup.AUTO_INSERT_SELECT_CHAR, lookupElement); } }, "Autocompletion", null); } }; Editor editor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(getEditor(), getFile()); handler.invokeCompletion(getProject(), editor); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); }, null, null); }
Example #29
Source File: JavaEndpointSmartCompletionValueTestIT.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testUnresolvedValueWithPreTestCompletion() { myFixture.configureByText("JavaCaretInMiddleOptionsTestData.java", getJavaUnresolvedValueWithPreTestData()); myFixture.complete(CompletionType.BASIC, 1); List<String> strings = myFixture.getLookupElementStrings(); assertFalse(strings.containsAll(Collections.singletonList("timer:trigger?repeatCount=10"))); assertThat(strings, Matchers.containsInAnyOrder( "timer:trigger?exchangePattern=InOut", "timer:trigger?exchangePattern=InOnly", "timer:trigger?exchangePattern=InOptionalOut", "timer:trigger?exchangePattern=OutIn", "timer:trigger?exchangePattern=RobustInOnly", "timer:trigger?exchangePattern=OutOptionalIn")); assertEquals(6, strings.size()); }
Example #30
Source File: YamlPropertyPlaceholdersSmartCompletionTestIT.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testCompletion() { myFixture.configureByFiles("CompleteYmlPropertyTestData.java", "CompleteYmlPropertyTestData.yml"); myFixture.complete(CompletionType.BASIC, 1); List<String> strings = myFixture.getLookupElementStrings(); assertTrue(strings.containsAll(Arrays.asList("example.generateOrderPeriod}}", "example.processOrderPeriod}}", "mysql.service.database}}", "mysql.service.host}}", "mysql.service.port}}", "spring.datasource.password}}", "spring.datasource.url}}", "spring.datasource.username}}", "spring.jpa.hibernate.ddl-auto}}", "spring.jpa.show-sql}}"))); assertEquals(10, strings.size()); }