CodeCompletion not working with prefixes
Hi, I'm getting this error while trying to get the completion list:
Method threw 'com.intellij.openapi.progress.ProcessCanceledException' exception.
I'm adding my own code completion contributor for some XML files, and it's working fine.
This error only happens when I'm requesting the completion list after something like "<t"
If I request the list in a white space it works as expeced.
If I request the list after "<" it works but it tries to insert a new "<".
Do you know what could be the cause of this behavior?
I'm adding a string like "<sometag></sometag>" with the LookupElement.
So I was expecting if I write "<s" and press Ctrl+Space then have the autocomplete for "<sometag></sometag>"
My results are calculated correctly and my completion method is finishing without throwing any error.
I've tried adding "_result.stophere();" but it stills throwing the error (I don't see the error in the IDE, I'm seeing only debugging, the IDE just doesn't show any completion list)
This is my code for the LookupElement:
String name = entry.getKey();
LookupElement element = LookupElementBuilder.create(entry.getValue()) // entry.getValue() == "<sometag></sometag>"
//LookupElement element = LookupElementBuilder.create("I was thinking in using this string inside my weigher", entry.getValue())
.setPresentableText(name)
.setIcon(myIcon)
.setInsertHandler(QUOTE_EATER);
_result.addElement(element);
If I execute the code before (LookupElementBuilder without Object), the behavior is a bit different.
I'm not getting the list when I request it after "<s" but when I request it after "<" it's not adding another "<" instantly (without selecting any item in the completion list)
But If I choose the item from the completion list (with enter, click or tab, it doesn't matter) it inserts something like: "<<sometag></sometag>" (note the duplicated "<")
Please tell me what I'm doing wrong, I don't know how to solve this :(
Thanks !!
请先登录再写评论。
I think I found something:
I guess we need to make the prefix filtering by ourself (and then Idea is doing it again...)
If I do this:
Then I'm getting the completion list when I have something like "<s"
But I don't get how this works.
Also, the completion is not nice, because after selecting the item in the list, I get again "<s<sometag></sometag>"
I think this is because the "prefix" is not getting the initial "<", that is, if I write "<" and press Ctrl+Space the prefix is null, and if write "<s" and press ctrl+space the prefix is "s".
Can you help me to understand this and to do it in the right way?
Because I think I could "hack" these things, and even make some "fixes" in my INSERT_HANDLER, but I think I'm taking the wrong and then hard way.
I'm sure there's a better solution for this, am I right?
I assume you tried the hint given in javadoc for com.intellij.codeInsight.completion.CompletionContributor ?
This is what I'm doing right now:
And it works, but I don't know, I feel I'm doing this wrong.
Can you help me to go in the right direction?
Thanks !