zikaari / monaco-editor-textmate

MIT License
122 stars 16 forks source link

Cannot set tokens provider for unknown language #8

Closed dev-drprasad closed 5 years ago

dev-drprasad commented 5 years ago

According to document, i excluded languages from MonacoEditorWebpackPlugin. But looks like TMGrammers are not loaded for that languages and i am getting following error

Uncaught (in promise) Error: Cannot set tokens provider for unknown language javascript
    at Object.setTokensProvider (standaloneLanguages.js:231)
    at _callee$ (index.js:77)
    at tryCatch (runtime.js:45)
    at Generator.invoke [as _invoke] (runtime.js:264)
    at Generator.prototype.<computed> [as next] (runtime.js:98)
    at asyncGeneratorStep (asyncToGenerator.js:3)
    at _next (asyncToGenerator.js:25)

Code

async function liftOff(monaco) {
  const registry = new Registry({
    getGrammarDefinition: async scopeName => {
      console.log("scopeName :", scopeName);
      return {
        format: "json",
        content: await (await fetch(`/grammers/${scopeName}.tmLanguage.json`)).text(),
      };
    },
  });

  // map of monaco "language id's" to TextMate scopeNames
  const grammars = new Map();
  grammars.set("python", "source.python");
  grammars.set("javascript", "source.js");

  await wireTmGrammars(monaco, registry, grammars);
}

How i am changing language ?

monaco.editor.setModelLanguage(editorRef.current.getModel(), "javascript");
ozonep commented 5 years ago

I have the same issue. I even forked WebPack plugin to use modified monaco editor without "monaco-languages" built-in. With that setup I do not get error but there's no syntax highlighting at all. No built-in, no textmate... :(

dev-drprasad commented 5 years ago

@ozonep I think we need to register custom languages first before wiring TMGrammers. Try:

monaco.languages.register({ id: "languageName" });
zikaari commented 5 years ago

@ozonep @dev-drprasad did it work for you guys after calling monaco.languages.register?

I was about to say the same thing tbh (haven't checked this myself though)

dev-drprasad commented 5 years ago

@NeekSandhu it worked for me.