Is there a way to change the language at the same time as changing the document?

I have this code for swapping the whole document and retaining history

      changes: {
        from: 0,
        to: view.state.doc.length,
        insert: text,

is there a way to also change the language? like for example if I know the document is going to change from markdown to javascript?

My EditorView is presently only configured for markdown, so I guess I have a second question as well – if I also add javascript, how does it know which language to use for highlighting?

See the configuration example, specifically the example at the end.

oh nice, adding

    effects: languageConf.reconfigure(docIsHTML ? html() : javascript())

and re-calling dispatch when my document changes with this works great! thanks!