I'd like to add completions based on IJ's variable completions. For example, I'd like to take the top 3 variables that IJ suggests and add new completions based on those. In order to do that, I need to get the top 3 variables that IJ suggests.
I'm calling runRemainingContributors from my completions contributor and collect all VariableLookupItem elements. My problem is, this list is still not ordered the way the user will see it, so I thought I'd call the LookupArranger, sort it and then get the top 3. Something like this:
final LookupArranger lookupArranger = ((LookupImpl) activeLookup).getArranger();
final CompletionLookupArranger dummyArranger = (CompletionLookupArranger)lookupArranger.createEmptyCopy();
.filter(completionResult -> completionResult.getLookupElement().as(VariableLookupItem.class) != null)
final List<LookupElement> sortedVariableLookupElements = dummyArranger.arrangeItems().getFirst();
This all seem to work fine in IJ 2019.3 but in IJ ~2020 completions are running asynchronously and there's the MLSorter which requires to run on the UI thread (why should a sorter care about its running thread?).
Any way to get around this? Maybe I should take a completely different approach?