Post processing fuzzily matched autocomplete options

I’m happy with the fuzzy matching that @codemirror/autocomplete implements internally. After the fuzzy matching has sorted and filtered out options, I’d like to append a load more option at the very end to on-demand load more options. I figured out that in Completion.apply I can trigger the list of options to be updated once they have been fetched with startCompletion. My issue now is that I’d like to avoid re-implementing the fuzzy matching logic the library already has but the library also not exposing it nor providing a hook to customize the options post fuzzy matching.

Happy Easter!

Edit: I realized I have another sort criteria: I’d like to put exact apply text matches first.

I don’t think this is something that is possible with @codemirror/autocomplete. How are you updating the list of options? That already doesn’t sound like a thing the package supports.

Triggering startCompletion while the options are already open apparently causes the completion source to be run again, so I’d use that. The state is outside the editor and just accessed in the completion source, which is fine for my use case.

Wouldn’t that also apply the filtering then?

Yes, that’s what I want. I’m starting with 200 common options that are bundled into the app and will satisfy most users. Few users may want to select a different option (among 8k total). I don’t want to bundle all of them in the app so I’m chunking them based on their first letter. When you select load more it would expand the options to be filtered to the additional options for the current input.

Right, but what is not working then? Re-running completion with your source rigged to produce more options will put the options into the regular completion flow, and cause them to be filtered and ranked as normal.

The load more option itself gets filtered out because it doesn’t match the text. I want to display it irrespective of the filtering that applies to the other options.

And then I’d also like to fine-tune the fuzzy sorting so that exact apply text matches are first (my options are labeled ${description} (${applyText}) so searching for the apply text does match but I’d like to prioritize exact apply text matches over exact description matches.

Both of this would be easily possible if I could modify the options post filtering and sorting (which could be done either by providing a hook and keeping the fuzzy matcher an implementation detail or by exposing it so that I could use it with filter: false).

Yeah, that sounds like it is outside of what this package supports.

Right. I could see if I find a nice way to extend it to support this? Or do you think this is out of scope?

You may be able to pass in your always-present thing via a separate completion source, with filter: false to make sure it shows up . Fine-tuning the completion matching is out of scope for this package.