ChooseItemAction and changing default completion characters

I already ask this as part of another question but got no answer. I believe that this is of interest because in not all languages it is usefull to
complete for instance with Ctrl+. like it is in Java.
When the autocompletion is finished by pressing Ctrl+Enter, Ctrl+. or whatever, this event is catched in ChooseItemAction.execute().
In this function it is then decided which completion character was pressed. For my Mathematica plugin I require that lookup suggestions can be completed
with "[".

Can someone tell me whether it is possible to change the completion characters?

If it is of help, I can surely put my current code on GitHub. I wanted to put it there anyway, but I don't like to publish half-baked stuff.

Many thanks in advance.

1 comment

I think I found a solution which works. You can implement a com.intellij.codeInsight.lookup.CharFilter which can catch the event when an [ is inserted. In this implementation you can call trigger to finish the lookup. Don't forget to register the CharFilter in your plugin.xml with something like

<lookup.charFilter id="BracketCharFilter" implementation="de.halirutan.mathematica.codeInsight.completion.BracketCharFilter"/>

A very simple form looks like this

public class BracketCharFilter extends CharFilter {
    @Nullable
    @Override
    public Result acceptChar(char c, int prefixLength, Lookup lookup) {
        if(c == '[') {
            final LookupImpl lookup1 = (LookupImpl) LookupManager.getActiveLookup(lookup.getEditor());
            FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_CONTROL_ENTER);
            lookup1.finishLookup(c,lookup.getCurrentItem());
            return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
        }
        return Result.ADD_TO_PREFIX;
    }
}



Now you can catch the [ event in your implementation of InsertHandler<LookupElement> and of course you need to specify this custom made InsertHandler to each LookupElementBuilder with LookupElementBuilder.create(name).withInsertHandler(customMadeInsertHandler).

0

Please sign in to leave a comment.