Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this library support usage of a custom language's server worker? #622

Open
Lemour-sudo opened this issue May 21, 2024 Discussed in #594 · 0 comments
Open

Does this library support usage of a custom language's server worker? #622

Lemour-sudo opened this issue May 21, 2024 Discussed in #594 · 0 comments

Comments

@Lemour-sudo
Copy link

Lemour-sudo commented May 21, 2024

Discussed in #594

Originally posted by Lemour-sudo March 12, 2024
I see that we can use getWorkerUrl to run a custom worker.

However, I am not sure how to link this to the Editor component as the language property in the component is said to be for supported certain languages: https://github.com/microsoft/monaco-editor/tree/main/src/basic-languages
Is it possible to just have a custom language's server worker (e.g monaco-languageclient) integrated with this library's editor instead of relying on the hardcoded keywords and tokens?

Moreover, the label argument being passed to getWorker does not detect a custom registered language id. In the code snippet below, the logged label is just "editorWorkerService" instead of the registered "lingo" language id. Is this how it is meant to be used?

This is the snippet I have running using Vite:

import { useEffect } from "react";

import { loader } from "@monaco-editor/react";
import Editor, { useMonaco } from "@monaco-editor/react";
import editorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";

const languageId = "lingo";

export function App() {
  const monaco = useMonaco();

  useEffect(() => {
    if (monaco) {
      monaco.languages.register({ id: languageId });

      self.MonacoEnvironment = {
        getWorker(_, label) {
          console.log("label:", label);
          return new editorWorker();
        },
      };

      loader.config({ monaco });
    }
  }, [monaco]);

  return (
    <Editor
      height="90vh"
      defaultValue="// some comment"
      language={languageId}
    />
  );
}

```</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant