implement Parinfer with snippets

Hello everyone,

I’m currently making an editor for the scheme language with codemirror 6.
I added some snippets (thank you codemirror 6 for this wonderfull feature) and now I would like to implement parinfer (parinfer - npm).
Everything (separatelly) is working pretty well, but as parinfer is changing my text at every key press,
the snippet tooltip disappears quickly, and if I accept the snippet then parinfer is messing with selections… well, the combination of both features for the moment is not good. One feature is killing the other.

There is a way to check in the state of my editor if we are filling a snippet while typing?
I could put a condition to do something like :
if (user is filling a snippet) then don’t apply parinfer

Some of you have an idea?

Thank you very much


Would it be possible to use diffing to only change the parts of the text that parinfer actually touched? Replacing the entire document on every keystroke is going to break a lot of other stuff, such as the undo history, and… well pretty much every other plugin that keeps document-related state.

Thank you very much for your quick answer.
And yes I know that my implementation of parinfer is really not the best, I can feel that replacing all the text it’s not really optimized…
Then I tried undo/redo is still working, and parinfer do the job also on large files, it’s wobbly, not fast as it could be, but it’s working.

For the moment basically (and it should change one day when I will optimize the system) I check like this :

document.getElementById(this.editorId).addEventListener('keyup', (key)=>{
  const tooltip = this.view.state.values[4].open ? true : false
  const snippet = this.view.state.values[6].ranges ? true : false
  if (tooltip || snippet) return
  (then parinfer replace all the text and move the cursor)

It’s only now that I understand that making an editor is a difficult thing for a junior as I am…
So I hope one day someone (maybe the parinfer author?) will do the perfect implementation of this wonderfull plugin.