private static boolean shouldPerformWordCompletion(CompletionParameters parameters) { final PsiElement insertedElement = parameters.getPosition(); final boolean dumb = DumbService.getInstance(insertedElement.getProject()).isDumb(); if (dumb) { return true; } if (parameters.getInvocationCount() == 0) { return false; } final PsiFile file = insertedElement.getContainingFile(); final CompletionData data = CompletionUtil.getCompletionDataByElement(insertedElement, file); if (data != null) { Set<CompletionVariant> toAdd = new HashSet<CompletionVariant>(); data.addKeywordVariants(toAdd, insertedElement, file); for (CompletionVariant completionVariant : toAdd) { if (completionVariant.hasKeywordCompletions()) { return false; } } } final int startOffset = parameters.getOffset(); final PsiReference reference = file.findReferenceAt(startOffset); if (reference != null) { return false; } final PsiElement element = file.findElementAt(startOffset - 1); ASTNode textContainer = element != null ? element.getNode() : null; while (textContainer != null) { final IElementType elementType = textContainer.getElementType(); if (LanguageWordCompletion.INSTANCE.isEnabledIn(elementType) || elementType == PlainTextTokenTypes.PLAIN_TEXT) { return true; } textContainer = textContainer.getTreeParent(); } return false; }
private static boolean shouldPerformWordCompletion(CompletionParameters parameters) { final PsiElement insertedElement = parameters.getPosition(); final boolean dumb = DumbService.getInstance(insertedElement.getProject()).isDumb(); if (dumb) { return true; } if (parameters.getInvocationCount() == 0) { return false; } final PsiFile file = insertedElement.getContainingFile(); final CompletionData data = CompletionUtil.getCompletionDataByElement(insertedElement, file); if (data != null && !(data instanceof SyntaxTableCompletionData)) { Set<CompletionVariant> toAdd = new HashSet<CompletionVariant>(); data.addKeywordVariants(toAdd, insertedElement, file); for (CompletionVariant completionVariant : toAdd) { if (completionVariant.hasKeywordCompletions()) { return false; } } } final int startOffset = parameters.getOffset(); final PsiReference reference = file.findReferenceAt(startOffset); if (reference != null) { return false; } final PsiElement element = file.findElementAt(startOffset - 1); ASTNode textContainer = element != null ? element.getNode() : null; while (textContainer != null) { final IElementType elementType = textContainer.getElementType(); if (LanguageWordCompletion.INSTANCE.isEnabledIn(elementType) || elementType == PlainTextTokenTypes.PLAIN_TEXT) { return true; } textContainer = textContainer.getTreeParent(); } return false; }
private static boolean shouldPerformWordCompletion(CompletionParameters parameters) { final PsiElement insertedElement = parameters.getPosition(); final boolean dumb = DumbService.getInstance(insertedElement.getProject()).isDumb(); if (dumb) { return true; } if (parameters.getInvocationCount() == 0) { return false; } final PsiFile file = insertedElement.getContainingFile(); final CompletionData data = CompletionUtil.getCompletionDataByElement(insertedElement, file); if (data != null) { Set<CompletionVariant> toAdd = new HashSet<>(); data.addKeywordVariants(toAdd, insertedElement, file); for (CompletionVariant completionVariant : toAdd) { if (completionVariant.hasKeywordCompletions()) { return false; } } } final int startOffset = parameters.getOffset(); final PsiReference reference = file.findReferenceAt(startOffset); if (reference != null) { return false; } final PsiElement element = file.findElementAt(startOffset - 1); ASTNode textContainer = element != null ? element.getNode() : null; while (textContainer != null) { final IElementType elementType = textContainer.getElementType(); if (LanguageWordCompletion.INSTANCE.isEnabledIn(textContainer) || elementType == PlainTextTokenTypes.PLAIN_TEXT) { return true; } textContainer = textContainer.getTreeParent(); } return false; }