How to force reload the mode?

I have an application (playground for my programming language https://gaiman.js.org/). I use CodeMirror 5 as input to type my language (with a few other editors). Now I want to add another CM instance to be able to edit my language mode and load a new version after each change.

So what I need is to reload the mode and refresh the CM that holds my code. How can I do that?

I’ve tried to use this code:

     state.editors.cm.on('change', debounce(async () => {
         state.cm = state.editors.cm.getValue();
         await set(CODEMIRROR_FILE, state.cm);
         await $.getScript(`./__idb__/${CODEMIRROR_FILE}`);
         state.editors.input.refresh();
     }));

set is adding the file to the KeyValue store based on IndexedDB and I use a service worker to be able to have static file with new data.

It seems that you can use:

         state.editors.input.setOption('mode', 'text');
         state.editors.input.setOption('mode', 'gaiman');