I am working on monaco-editor to show content of local code files, which may be written in various languages, so I am wondering how to dynamically set/change language of monaco editor according to the extension of file, or the first line of file without extension (like #!/usr/bin/env python).
Seems that monaco-editor itself does not come with this feature, but the VSCode does apparently.
I want to define such a method called checkLanguage(file_path), which takes a file path and returns the string that represents the language supported by monaco-editor. If the language cannot be determined, just return plain text.
monaco.editor.setModelLanguage(model, checkLanguage(file_path))
Supported languages: https://github.com/microsoft/monaco-languages