Autocomplete API with multiple insertions

I’m writing a custom autocomplete extension, but my completions have multiple text insertions.
E.g. if I type def add( and the parentheses auto-close to def add(<cursor>), I’d have completions for a,b at the cursor location, and :\n return a+b at offset 2 from the cursor.

The Autocomplete module doesn’t seem to support this. How hard would it be to add multi-insert completions to it?

A custom apply function could do this. Or, if you want to allow quick cursor skipping to other parts of the completion, a snippet.

I want the whole completion to be rendered before application as well though - would snippets do this?

Ah sorry to be clear, I also want the completions to render inline (I don’t think a custom apply function achieves this, but snippets still might)

That’s not something @codemirror/autocomplete will do for you (though it’s possible to implement something like that using the functions that query the currently selected completion).

gotcha. My current plan is to make it from scratch with a state field (for the current completion), view plugin (for rendering) and command (for acceptance). Does that seem reasonable, or is there some part of the API that would make this more straightforward?

I don’t think you need that additional state field—you can read the selected completion from the autocompletion state.

It’s easier to call a custom autocomplete provider from the autocompletion state than maintain it in a separate state field?

I assumed you’d want a tooltip like the existing autocomplete, plus a type-ahead display of the text. If you want something that doesn’t have the tooltip, you probably don’t need to use the regular autocompletion extension.

Ok, thanks. (I actively want to not have a tooltip, so sounds like a state field is the way to go.)