Insert Lookup string from AutoCompletion list

Answered

I am doing auto-completion for normal text. But I have some problems with the lookup string insertion.

For example, when I input "This is", and my auco-completion provider gives a list ["This is A"], then I choose it. But the result text becomes "This is This is A". That's not what I want. I just want to insert the rest part of the matched sentence. What should I do to fix this problem?

3 comments

Please show the code that populates the completion items

 

0

The IDE deletes the matched prefix part and inserts the lookup string instead. It looks like in your case the matched prefix is empty, so there's nothing to delete. By default, the prefix is calculated as some identifier before caret, while you need whitespaces to be included here as well. Your completion contributor can lengthen the prefix by feeding the suggestions into CompletionResultSet.withPrefix(longerPrefix), where longerPrefix is calculated from the file text and completion offset in any way you wish.

0

Thanks for you guys' quick reply. Actually I debugged it and the prefix is indeed empty. Previously I did not override the fillCompletionVariants function. I did not know the whitespaces will affect the prefix calculation and matching. I just changed the code to implement my own fillCompletionVariants and the problem is fixed.

Thank you again!

0

Please sign in to leave a comment.