autoLoadMode

i’m using vue with code-mirror and changing the languange dinamicalley according to the file extention

i have this code on mounted:
let mime = CodeMirror.findModeByExtension(this.code.codeLanguage).mime
this.$refs.cmEditor.cminstance.setOption(‘mode’, mime)

it’s working well for me, but i saw on the docs you also need:
CodeMirror.autoLoadMode(this.$refs.cmEditor.cminstance, mime)

so:

  1. do i really need the autoLoadMode? because it’s working fine for me atm.
  2. the autoLoadMode function work for me on every languange except sql, if i put sql in it’s writing "no such directory …/mode/sql/x-sql.js/sql/x-sql/.js for some weird reason, is there a way to solve it?

Unless you are loading all the modes ahead of time, I don’t see how this could work without autoLoadMode, since the code that defines the mode won’t be available.

I don’t see anything that should cause the failure to load the sql mode (and it doesn’t seem to happen in the demo), but if you can reproduce it in a minimal script I can take a look.

yes it was because i imported all modes ahead.
now i removed it and wrote the following code:

let info = CodeMirror.findModeByExtension(this.code.codeLanguage)
let mode = info.mode
let mime = info.mime
this.$refs.cmEditor.cminstance.setOption('mode', mime)
CodeMirror.autoLoadMode(this.$refs.cmEditor.cminstance, mode)

but it return exception “Cannot find module …mode/vue/vue.js”
or any other module as well