com.intellij.codeInsight.completion.CompletionContributor Java Examples

The following examples show how to use com.intellij.codeInsight.completion.CompletionContributor. 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: CSharpLinqCompletionContributor.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
static void extend(CompletionContributor contributor)
{
	contributor.extend(CompletionType.BASIC, CSharpPatterns.expressionStart(), new CompletionProvider()
	{
		@RequiredReadAction
		@Override
		public void addCompletions(@Nonnull CompletionParameters parameters, ProcessingContext context, @Nonnull CompletionResultSet result)
		{
			PsiElement position = parameters.getPosition();
			if(!CSharpModuleUtil.findLanguageVersion(position).isAtLeast(CSharpLanguageVersion._3_0))
			{
				return;
			}
			CSharpReferenceExpressionEx parent = (CSharpReferenceExpressionEx) position.getParent();
			if(parent.getQualifier() != null || parent.kind() != CSharpReferenceExpression.ResolveToKind.ANY_MEMBER)
			{
				return;
			}

			CSharpCompletionUtil.elementToLookup(result, CSharpSoftTokens.FROM_KEYWORD, null, null);
		}
	});
}
 
Example #2
Source File: CommandNameCompletionProvider.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@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 #3
Source File: TypedHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isAutoPopup(@Nonnull Editor editor, @Nonnull PsiFile file, char charTyped) {
  final int offset = editor.getCaretModel().getOffset() - 1;
  if (offset >= 0) {
    final PsiElement element = file.findElementAt(offset);
    if (element != null) {
      for (CompletionContributor contributor : CompletionContributor.forLanguageHonorDumbness(element.getLanguage(), file.getProject())) {
        if (contributor.invokeAutoPopup(element, charTyped)) {
          LOG.debug(contributor + " requested completion autopopup when typing '" + charTyped + "'");
          return true;
        }
      }
    }
  }
  return false;
}
 
Example #4
Source File: ReplacingConsumerTest.java    From litho with Apache License 2.0 4 votes vote down vote up
TestCompletionResultSet() {
  super(
      Mockito.mock(PrefixMatcher.class),
      Mockito.mock(Consumer.class),
      Mockito.mock(CompletionContributor.class));
}
 
Example #5
Source File: BashKeywordCompletionProvider.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
void addTo(CompletionContributor contributor) {
    contributor.extend(CompletionType.BASIC, KEYWORD_PATTERN, this);
}
 
Example #6
Source File: ShebangPathCompletionProvider.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
@Override
void addTo(CompletionContributor contributor) {
    contributor.extend(CompletionType.BASIC, new BashPsiPattern().inside(BashShebang.class), this);
}
 
Example #7
Source File: VariableNameCompletionProvider.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
@Override
void addTo(CompletionContributor contributor) {
    BashPsiPattern insideVar = new BashPsiPattern().withParent(BashVar.class);

    contributor.extend(CompletionType.BASIC, insideVar, this);
}
 
Example #8
Source File: DynamicPathCompletionProvider.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
@Override
void addTo(CompletionContributor contributor) {
    contributor.extend(CompletionType.BASIC, new BashPsiPattern().withParent(BashWord.class), this);
}
 
Example #9
Source File: CSharpMemberAddByCompletionContributor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
static void extend(CompletionContributor contributor)
{
	contributor.extend(CompletionType.BASIC, CSharpPatterns.fieldStart(), new CompletionProvider()
	{
		@RequiredReadAction
		@Override
		public void addCompletions(@Nonnull CompletionParameters parameters, ProcessingContext context, @Nonnull CompletionResultSet result)
		{
			CSharpFieldDeclaration currentElement = PsiTreeUtil.getParentOfType(parameters.getPosition(), CSharpFieldDeclaration.class);
			assert currentElement != null;

			DotNetModifierList modifierList = currentElement.getModifierList();
			if(modifierList != null)
			{
				int textLength = modifierList.getTextLength();
				if(textLength > 0)
				{
					return;
				}
			}

			PsiElement nextSibling = UsefulPsiTreeUtil.getNextSiblingSkippingWhiteSpacesAndComments(currentElement);
			TextRange textRange = nextSibling == null ? null : new TextRange(currentElement.getTextRange().getStartOffset(), nextSibling.getTextRange().getStartOffset());
			if(textRange != null && !StringUtil.containsLineBreak(textRange.subSequence(currentElement.getContainingFile().getText())))
			{
				return;
			}

			CSharpTypeDeclaration typeDeclaration = PsiTreeUtil.getParentOfType(parameters.getPosition(), CSharpTypeDeclaration.class);

			if(typeDeclaration == null)
			{
				return;
			}

			Consumer<LookupElement> delegate = lookupElement ->
			{
				if(lookupElement != null)
				{
					CSharpCompletionSorting.force(lookupElement, CSharpCompletionSorting.KindSorter.Type.overrideMember);
					result.consume(lookupElement);
				}
			};

			for(CSharpMemberAddByCompletionContributor completionContributor : EP_NAME.getExtensions())
			{
				completionContributor.processCompletion(parameters, context, delegate, typeDeclaration);
			}
		}
	});
}