Modes - transform stream by fetching data from server

Hi,

I would like to create an autocompleting text area that automatically shows the latest version of some pieces of data by fetching them from the server.

If possible I would like CodeMirror to work on a version of the text containing IDs to the DB and return a highlighted ‘human readable’ version.

Starting from something like "this is the content of a record ID{}’ I would like to use a custom mode to transform it to "this is the content of a record record-content-fetched-from-server’ with the content from server highlighted.

It feels like I would need a custom mode to ‘modify the stream’ (is it possible in a token function, could I apply such modifications asynchronously )? It’s a bit like CodeMirror works on 2 documents - one contains instructions that help me highlight pieces of text in the rendered one.

In the docs I’ve found the doc.markText method are relative clearOnEnter option that seem to do part of what I need but I was wondering how much more I would need to do manually.

Thanks,
Raffaele

You don’t need to write a mode to do this (in fact, modes won’t help at all). markText is indeed the way to go. You’ll have to write the code that listens for changes and updates the editor’s marked ranges yourself.