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

Monaco Editor test client #5

Open
vbar opened this issue Feb 4, 2022 · 0 comments
Open

Monaco Editor test client #5

vbar opened this issue Feb 4, 2022 · 0 comments

Comments

@vbar
Copy link
Collaborator

vbar commented Feb 4, 2022

For testing the container (especially Language Server performance), if would be useful to wrap the Monaco Editor Language Client in a non-interactive, command-line test client, which would just open a source file and handle the initial LSP communication, IOW wrap

    <Editor
      className="hooks-editor"
      keepCurrentModel
      defaultLanguage={snap.files?.[snap.active]?.language}
      language={snap.files?.[snap.active]?.language}
      path={`file:///work/c/${snap.files?.[snap.active]?.name}`}
      defaultValue={snap.files?.[snap.active]?.content}
      beforeMount={monaco => {
        if (!snap.editorCtx) {
          snap.files.forEach(file =>
            monaco.editor.createModel(
              file.content,
              file.language,
              monaco.Uri.parse(`file:///work/c/${file.name}`)
            )
          );
        }

        // create the web socket
        if (!subscriptionRef.current) {
          monaco.languages.register({
            id: "c",
            extensions: [".c", ".h"],
            aliases: ["C", "c", "H", "h"],
            mimetypes: ["text/plain"],
          });
          MonacoServices.install(monaco);
          const webSocket = createWebSocket(
            process.env.NEXT_PUBLIC_LANGUAGE_SERVER_API_ENDPOINT || ""
          );
          subscriptionRef.current = webSocket;
          // listen when the web socket is opened
          listen({
            webSocket: webSocket as WebSocket,
            onConnection: connection => {
              // create and start the language client
              const languageClient = createLanguageClient(connection);
              const disposable = languageClient.start();
              connection.onClose(() => {
                try {
                  // disposable.stop();
                  disposable.dispose();
                } catch (err) {
                  console.log("err", err);
                }
              });
            },
          });
        }

in a standalone script, possibly using Jest (see https://medium.com/hired-engineering/setting-up-monaco-with-jest-e1e4c963ac ).

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