Code-completion without applying initial lookupString

Answered

I have a use case where the heuristics for the insert of the `lookupString` of the `LookupElement` aren't being helpful (it's a completion where the completion is `${None}` and the standard heuristics are removing the whole line and replacing it with the lookupString when it's applied) so, I'd like to have a way to skip that altogether (I had to do a custom PrefixMatcher for it to appear but now, when it's applied it replaces the whole line and not just the related part).

So, is there any way to do that?

Note: in this particular case, completions are consumed from a language server, which usually specifies exactly how the document needs to be changed, so, any change from the document out of that scope is mostly detrimental and needs to be undone to apply the actual completion (I'm applying lots of workarounds due to that, but in this case Intellij is completely destroying the line and I couldn't find a good workaround, so, hopefully someone can give me a hint on how to just skip that altogether as I really couldn't find how to do that from the docs).

0
4 comments

Actually, I just noted that my custom prefix matcher makes the prefix wrong (I was passing the whole line to the prefix matcher to make the match and I hadn't made the association that this would be the amount it'd replace), so, I fixed a part of that, but my larger point still stands (there should be a way to have full control of completions regardless of the `lookupString`).

0

Sorry this got lost. Does using custom com.intellij.codeInsight.completion.InsertHandler help in your case?

0

No... `LookupElement.handleInsert` is actually already overridden (which would be the same thing) and the first thing I have to do is undo what was done based on the lookup string to then do the actual completion (and in some cases where the lookup string is automatically applied that's not even called, which is pretty bad for my use case).

0

> and the first thing I have to do is undo what was done based on the lookup string to then do the actual completion

Looks like it's an ok approach, given the currently existing API. Do you have any problems with that?

> and in some cases where the lookup string is automatically applied that's not even called

Which cases exactly?

0

Please sign in to leave a comment.