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

Theme not loading and worker not being created #687

Closed
Mw3y opened this issue Jun 24, 2024 · 17 comments
Closed

Theme not loading and worker not being created #687

Mw3y opened this issue Jun 24, 2024 · 17 comments

Comments

@Mw3y
Copy link

Mw3y commented Jun 24, 2024

Hello,

While trying to use the wrapper with nuxt.js, I've encountered an issue:

image

The theme is not loaded and the worker isn't being created.

Here's my code:

<script lang="ts" setup>
  import {
    MonacoEditorLanguageClientWrapper,
    type UserConfig,
  } from "monaco-editor-wrapper"

  import "@codingame/monaco-vscode-python-default-extension"

  const props = withDefaults(
    defineProps<{
      userConfig: UserConfig
      modelValue?: string
    }>(),
    {
      modelValue: (_) => "",
    }
  )

  const emit = defineEmits<{
    (e: "update:modelValue", changes: string): void
    (e: "load", wrapper: MonacoEditorLanguageClientWrapper): void
    (e: "error", error: any): void
  }>()

  const monacoEditorRef = ref<HTMLDivElement>()
  const wrapper = new MonacoEditorLanguageClientWrapper()

  // Initialize the monaco editor
  await wrapper.init(props.userConfig)
  // Start the monaco editor
  onMounted(async () => {
    if (monacoEditorRef.value) {
      await wrapper.start(monacoEditorRef.value)
      // Initial sync with the v-model value
      wrapper.getEditor()?.setValue(props.modelValue)
      // Propagate a text change to the v-model
      handleTextChange()
    }
  })

  watch(
    () => props.modelValue,
    (_) => {
      const textModels = wrapper.getTextModels()
      if (textModels?.text?.getValue() !== props.modelValue) {
        textModels?.text?.setValue(props.modelValue)
      }
    }
  )

  function handleTextChange() {
    const textModels = wrapper.getTextModels()
    if (textModels?.text) {
      textModels.text.onDidChangeContent(() => {
        console.log(textModels?.text?.getValue())
        emit("update:modelValue", textModels.text?.getValue() ?? "")
      })
    }
  }

  onUnmounted(() => wrapper.dispose())
</script>

<template>
  <div ref="monacoEditorRef" style="height: 100vh" />
</template>
@CGNonofr
Copy link
Collaborator

does nuxt.js support the new URL(..., import.meta.url) syntax?

@Mw3y
Copy link
Author

Mw3y commented Jun 24, 2024

does nuxt.js support the new URL(..., import.meta.url) syntax?

I don't think so... I tried using @codingame/esbuild-import-meta-url-plugin but it still doesn't work.

@kaisalmen
Copy link
Collaborator

kaisalmen commented Jun 25, 2024

Hi @Mw3y does this repo and the examples work successful in your environment? My other suggestion is to reduce complexity: First start without a framework and just do a simple hello world with HTML/JS and see that it works. Then try to wrap it in vue compoent, then try nuxt...

We want to add a vue verify example (see #416), but nobody volunteered for it, yet. 🙂

@Mw3y
Copy link
Author

Mw3y commented Jun 25, 2024

Hey @kaisalmen,

Using a normal vite + vue environment works well! I managed to get the editor running, sadly without any color highlighting (I don't know why). The issue is with nuxt.js specifically, but it's not that important for now... My ultimate goal is to add c++, java and python language servers to an app with code exercises for students.

Concerning the vue example, I could make it but I need to understand the library a bit more before 😅.

@kaisalmen
Copy link
Collaborator

kaisalmen commented Jun 25, 2024

Hey @Mw3y if you are interested take a look at the Angular example:
https://github.com/TypeFox/monaco-languageclient/blob/main/verify/angular/src/app/app.component.ts

In all verification examples we use the json client and server. The vite example with HTML+JS is probably the easiest:
https://github.com/TypeFox/monaco-languageclient/tree/main/verify/vite
and could also be a template for a vue example.

@Mw3y
Copy link
Author

Mw3y commented Jun 25, 2024

Thanks!

@Mw3y
Copy link
Author

Mw3y commented Jun 27, 2024

Hey @kaisalmen,

I've managed to make a web worker running a jedi language server for python. It has a method which takes a language server request object and sends a response.

I'm having trouble into connecting it to the monaco wrapper. How make a 'bridge' between the worker and the wrapper without a websocket?
I tried using vscode-languageclient/browser without success...

@kaisalmen
Copy link
Collaborator

@Mw3y
Copy link
Author

Mw3y commented Jun 28, 2024

Hey @kaisalmen,

I'm still having some trouble making it work... I'm now trying to use your build of pyright for the web.
I don't really now what would be the problem. Still no completion from the language server and no syntax highlighting.

Here's my code: https://haste.androz2091.fr/setevanomi.xml

NB: I used https://github.com/mitmedialab/monaco-workspace-import-error a lot to try to understand what's happening.

Logs:
image

@kaisalmen
Copy link
Collaborator

@Mw3y try to import import '@codingame/monaco-vscode-python-default-extension';. That is the need for syntax higlighting.

If the languageclient still does not show any code completion you have to see what the reader and writer does (add log statements there).

Apart from that I don't see anything being wrong with your config.

@Mw3y
Copy link
Author

Mw3y commented Jun 29, 2024

Thanks! Can't believe I forgot that...

@Mw3y
Copy link
Author

Mw3y commented Jun 30, 2024

Hey @kaisalmen,

I'm now trying to use the clangd web assembly build but I'm having this error:
image

which comes from

clangd.FS.writeFile('/workspace/main.cpp', '')
clangd.FS.writeFile(
  `/workspace/.clangd`,
  JSON.stringify({ CompileFlags: { Add: flags } })
)

I don't really know how to fix it...

I used the code provided at https://github.com/TypeFox/clangd-in-browser
Here's the code:

@kaisalmen
Copy link
Collaborator

Hi @Mw3y I don't know. Does the directory exists? Have you considered asking the maintainer of https://github.com/Guyutongxue/clangd-in-browser ?
We forked the project to perform the upgrade to the latest major version the libraries from this repo.

@Mw3y
Copy link
Author

Mw3y commented Jul 2, 2024

Alright, I'll contact him. I don't really know how the vscode filesystem works. I'll dig deeper. Thanks!

@CGNonofr
Copy link
Collaborator

CGNonofr commented Jul 2, 2024

I don't know how clangd-in-browser works, but note that VSCode implemented the WASI api (including filesystem backed on the virtual VSCode filesystem) in the extension host via an experimental extension (https://www.npmjs.com/package/@vscode/wasm-wasi / https://marketplace.visualstudio.com/items?itemName=ms-vscode.wasm-wasi-core)

@Mw3y
Copy link
Author

Mw3y commented Jul 2, 2024

Thank you for your suggestion but the issue was that the folder I was trying to use was not created by default.
More details here: guyutongxue/clangd-in-browser#7 (comment)

@kaisalmen
Copy link
Collaborator

@Mw3y good news and thanks for reporting back. I think this issue is now resolved. If you agree, please close it.

@Mw3y Mw3y closed this as completed Jul 3, 2024
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

3 participants