how to completion with title(not contents)? (LookupElementBuilder)
已回答
If I write AddNewLookupElement code like this.
Autocomplete options are completed by content, not title
title = "name"
contents="Hello world"
LookupElement element = LookupElementBuilder
.create(contents)
.withPresentableText(title)
resultSet.addElement(element);
How do autocomplete options work with title rather than contents?
I don't know how to do. pls help me
请先登录再写评论。
What do you want to achieve? Passing in "contents" as String to completion variants - what should that be? Maybe you want com.intellij.codeInsight.lookup.LookupElementBuilder#create(java.lang.String) passing in "title" only?
Yann Cebron
I want to pass "title" to create,
But in code, complete with "contents"
I think you should look at it as “I want to show and complete one text string but insert another text string” then it makes sense in the IDE API way.
You will need to provide your own
InsertHandler. I use one with a few options to manipulate the document text after insert, including replacing the inserted text with completely different text.Then use
LookupElementDecoratorstatic methodwithInsertHandler()to wrap your lookup element and use your insert handler.Vladimir Schneider
wow.. Thanks you for your kindenss i'll try it soon!
And where can i find
These are libraries that I use in my plugins but have not made them available simply because they are currently in high state of flux and I do not want to support them in this state. So I will not release them until they settle to a more stable condition.
The two functions ifElse and minLimit are simple. ifElse is used to return 1 of two values depending on the boolean true/false state. Here it is used select between space only string if isSpaceOnlyCompletion is true and completion char + space otherwise.
minLimit is an alias for Math.max(). Here it is used to ensure that startOffset is >= 0. You can use Math.max(0, value) as a substitute. I tend to always mess up when needing a min limit and wind up using Math.min() instead of max so created an alias that eliminates the frequent error.
Vladimir Schneider
Finally I succeed! Thanks for your help!
Thank you very much!