Remove element from autocomplete
In my plugin I want hide some fields from auto complete.
For example, I have:
class A {
@Hide
public int a;
public int b;
}
and when I use it:
class B {
void method() {
A a = new A();
a. // in this place during the auto complete field "a" shouldn't be displayed, only b
}
}
I try with CompletionContribution but it can only add some elements to view. Or am I mistaken?
If I could give filter for contributor, or something similar, it's would be nice.
Please sign in to leave a comment.
I inherited a JavaCompletionContributor and overrided his methods and added a filter.
Hi, can you give a simple filter example how to solve this assignment? E.g. We have names list, and should remove all which contains postfix 'Exclude'
I think this is wrong solution, but I didn't come up with another.
I added new class that extend JavaCompletionContributor (registred it in plugin.xml). (I place him before original javaContributor order="last, before legacy, before default, before javaClassName, before javaLegacy")
Then I rewrite "getReferenceFilter()" and (copy paste almost all methods from original class to my class) chain: fillCompletionVariants()->addReferenceVariants()->getReferenceFilter()
In getReferenceFilter I changed TrueFilter to my custom.
I think this is a very bad way, so if you find another, I'll be glad to know about it.
Can you attach code of your contributor and filter? I want to look at them, and try to find a better solution.
My current code was changed for other problems. And it can be confusing.
In addReferenceVariants(final CompletionParameters parameters, CompletionResultSet result, final InheritorsHolder inheritors) i change call JavaCompletionContributor.getReferenceFilter(position) to custom:
Where SomeElementFilter
final public static class SomeElementFilter implements ElementFilter {
public static final ElementFilter INSTANCE = new SomeElementFilter();
private SomeElementFilter() {}
@Override
public boolean isAcceptable(Object element, @Nullable PsiElement context) {
// some other filter logic
}
}
Hi,
There is good javadoc for Completion Contributor: https://github.com/JetBrains/intellij-community/blob/master/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java.
You need to read QA about "I'd be happy to filter out 42 of them".