TypeFox / monaco-languageclient

Repo hosts npm packages for monaco-languageclient, vscode-ws-jsonrpc, monaco-editor-wrapper, @typefox/monaco-editor-react and monaco-languageclient-examples
https://www.npmjs.com/package/monaco-languageclient
MIT License
1.07k stars 180 forks source link

[6.0.0-next.6] ViewDescriptorService missing #778

Closed cdietrich closed 2 weeks ago

cdietrich commented 3 weeks ago

hi, where/how do i configure

ViewDescriptorService.getViewContainersByLocation is not supported. You are using a feature without registering the corresponding service override.
    at ViewDescriptorService.unsupported5 (missing-services.js:220:15)
    at getDefaultViewContainer (views.js:309:35)
    at initLayoutState (views.js:317:103)
    at UniqueContainer.value (views.js:333:5)
    at Emitter._deliver (event.js:677:22)
    at Emitter._deliverQueue (event.js:686:18)
    at Emitter.fire (event.js:703:18)
    at lifecycle.js:55:32
    at _InstantiationService.invokeFunction (instantiationService.js:77:20)
    at startup (lifecycle.js:50:31)
cdietrich commented 3 weeks ago

the naive

import getLayoutServiceOverride from "@codingame/monaco-vscode-layout-service-override" userServices: { ...., ...getLayoutServiceOverride(), }

does not seem to work

CGNonofr commented 3 weeks ago

Do you have more context? what are you trying to do?

Also the layout service override has nothing to do with the ViewDescriptorService

cdietrich commented 3 weeks ago

i just try to update our editor classic config to the newest preview config

import getConfigurationServiceOverride from "@codingame/monaco-vscode-configuration-service-override"
import getEditorServiceOverride from "@codingame/monaco-vscode-editor-service-override"
import getKeybindingsServiceOverride from "@codingame/monaco-vscode-keybindings-service-override"
import type { languages } from "monaco-editor"
import type { WrapperConfig } from "monaco-editor-wrapper"
import { MonacoEditorLanguageClientWrapper } from "monaco-editor-wrapper"
import { useOpenEditorStub } from "monaco-editor-wrapper/vscode/services"
import { useWorkerFactory } from "monaco-editor-wrapper/workerFactory"
import type { Logger } from "monaco-languageclient/tools"

const setupConfigClassic = (
  url: string,
  languageId: string,
  text: string,
  fileExt: string,
  htmlElement: HTMLElement,
  monarch?: languages.IMonarchLanguage
): WrapperConfig => {
  const loadLangiumWorker = () => {
    console.log(`Langium worker URL: ${url}`)
    return new Worker(new URL(url, import.meta.url), {
      type: "module",
      name: "Our Language Server Worker",
    })
  }
  const langiumWorker = loadLangiumWorker()
  return {
    vscodeApiConfig: {
      userServices: {
        ...getConfigurationServiceOverride(),
        ...getEditorServiceOverride(useOpenEditorStub),
        ...getKeybindingsServiceOverride(),
      },
    },
    editorAppConfig: {
      $type: "classic",
      codeResources: {
        main: {
          text,
          fileExt,
          enforceLanguageId: languageId,
        },
      },
      htmlContainer: htmlElement,
      useDiffEditor: false,
      languageDef: {
        monarchLanguage: monarch,
        languageExtensionConfig: {
          id: languageId,
          extensions: [`.${fileExt}`],
        },
      },
      editorOptions: {
        "semanticHighlighting.enabled": true,
        theme: "vs-dark",
      },
      monacoWorkerFactory: (logger?: Logger) => {
        useWorkerFactory({
          logger,
          workerOverrides: {
            ignoreMapping: true,
            workerLoaders: {
              TextEditorWorker: () => {
                return new Worker(new URL("../libs/monaco-editor-workers/editorWorker-es.js", import.meta.url), {
                  type: "module",
                })
              },
            },
          },
        })
      },
    },
    languageClientConfigs: {
      our: {
        languageId,
        connection: {
          options: {
            $type: "WorkerDirect",
            worker: langiumWorker,
          },
        },
      },
    },
  }
}

export const executeClassic = async (
  htmlElement: HTMLElement,
  url: string,
  languageId: string,
  text: string,
  fileExt: string,
  monarch?: languages.IMonarchLanguage
): Promise<void> => {
  const userConfig = setupConfigClassic(url, languageId, text, fileExt, htmlElement, monarch)
  const wrapper = new MonacoEditorLanguageClientWrapper()
  await wrapper.initAndStart(userConfig)
}
cdietrich commented 3 weeks ago

and this gives the error in the first comment.

cdietrich commented 3 weeks ago

the build in example in this repo does not seem to use

getEditorServiceOverride(useOpenEditorStub)

kaisalmen commented 3 weeks ago

viewsConfig is not mandatory in the config. If it is not specified the editor service is used. You don't need to specify getEditorServiceOverride(useOpenEditorStub) yourself, but it should also not break things. habe you updated all monaco-vscode-api packages to 10.1.4?

cdietrich commented 3 weeks ago

Yes we use 10.1.4 everywhere. Removing it (the override) solves the problem but we carried it over from a year old example or so

kaisalmen commented 2 weeks ago

@cdietrich we should mention breaking changes more explicitly in the CHANGELOG or have an upgrade guide (but that is additional maintenance effort). I go with adjusting the CHANGELOG first. 🙂

CGNonofr commented 2 weeks ago

I'm not sure I follow here, what breaking change are we talking about?

kaisalmen commented 2 weeks ago

@CGNonofr generally speaking. From v8 -> v9 or V5 -> v6 (in case of the wrapper)

pbrostean commented 1 week ago

@kaisalmen Unfortunately I get the same error in both next.6 and next.7 . I don't use a service override for the editor so I can't apply this fix.


import { WrapperConfig } from "monaco-editor-wrapper";
import { LogLevel } from "vscode/services";
import {
  BrowserMessageReader,
  BrowserMessageWriter,
} from "vscode-languageclient/browser.js";
import { useWorkerFactory } from "monaco-editor-wrapper/workerFactory";
import testWorker from "./browserServerMain?worker&inline";
import textEditorWorker from "monaco-editor/esm/vs/editor/editor.worker.js?worker&inline";
import textMateWorker from "@codingame/monaco-vscode-textmate-service-override/worker?worker&inline";

export const createWrapperConfig = (
  code: string,
): WrapperConfig => {
  const worker = new testWorker();
  const channel = new MessageChannel();
  worker.postMessage({ port: channel.port2 }, [channel.port2]);
  const reader = new BrowserMessageReader(channel.port1);
  const writer = new BrowserMessageWriter(channel.port1);

  return {
    id: "test",
    logLevel: LogLevel.Info,
    vscodeApiConfig: {
      enableExtHostWorker: false,
    },
    editorAppConfig: {
      $type: "extended",
      htmlContainer: document.getElementById("monaco-editor-root") as HTMLElement,
      monacoWorkerFactory: (logger) => {
        useWorkerFactory({
          workerOverrides: {
            ignoreMapping: true,
            workerLoaders: {
              TextEditorWorker: () =>
                new textEditorWorker(),
              TextMateWorker: () =>
                new textMateWorker(),
            },
          },
          logger,
        });
      },
      codeResources: {
        main: { text: code, fileExt: "test" },
        original: { text: code, fileExt: "test" },
      },
      extensions: [
        {
          config: {
            name: "test",
            version: "1.0.0",
            engines: { vscode: "*" },
            contributes: {
              languages: [
                {
                  id: "test",
                  extensions: [".test"],
                  aliases: ["test"],
                  configuration: "./test-configuration.json",
                },
              ],
              grammars: [
                {
                  language: "test",
                  scopeName: "source.test",
                  path: "./test-grammar.json",
                },
              ],
              themes: [
                {
                  id: "Test Dark",
                  label: "Dark (Test)",
                  uiTheme: "vs-dark",
                  path: "./colorthemes/test-dark.json",
                },
                {
                  id: "Test Light",
                  label: "Light (Test)",
                  uiTheme: "vs",
                  path: "./colorthemes/test-light.json",
                },
              ],
            },
          },
          filesOrContents: new Map([
            [
              "/test-configuration.json",
              new URL("./language-configuration.json", import.meta.url),
            ],
            [
              "/test-grammar.json",
              new URL(
                "./syntaxes/test.tmLanguage.json",
                import.meta.url
              ),
            ],
            [
              "/colorthemes/test-dark.json",
              new URL("./themes/test-dark.json", import.meta.url),
            ],
            [
              "/colorthemes/test-light.json",
              new URL("./themes/test-light.json", import.meta.url),
            ],
          ]),
        },
      ],
    },
    languageClientConfigs: {
      "test-language-client": {
        name: "test",
        connection: {
          options: {
            $type: "WorkerDirect",
            worker,
            messagePort: channel.port1,
          },
          messageTransports: { reader, writer },
        },
        clientOptions: {
        }
      },
    },
  };
};
kaisalmen commented 1 week ago

@pbrostean does npm list confirm you use the same monaco-vscode-api packages?

pbrostean commented 1 week ago

I think I don't quite understand, which packages do you mean by monaco-vscode-api packages? npm list gives me the following:

├── @codingame/esbuild-import-meta-url-plugin@1.0.2
├── @codingame/monaco-vscode-textmate-service-override@11.0.1
├── @typefox/monaco-editor-react@6.0.0-next.7
├── @types/node@22.9.0
├── @types/react-dom@18.3.1
├── @types/react@18.3.12
├── @types/vscode@1.95.0
├── @vitejs/plugin-react@4.3.3
├── esbuild@0.21.5
├── langium-cli@3.2.0
├── langium@3.2.0
├── react-dom@18.3.1
├── react@18.3.1
├── typescript@4.9.5
├── vite-plugin-dts@4.3.0
├── vite-plugin-node-polyfills@0.22.0
├── vite@5.4.11
├── vscode-languageserver@9.0.1
└── vscode-uri@3.0.8

The project on itself runs perfectly fine in dev mode but as I bundle it and use it in another project im getting this error.

kaisalmen commented 1 week ago

@pbrostean @codingame/monaco-vscode-editor-service-override is imported dynamically. Could it be your bundle build does not considers that?

pbrostean commented 1 week ago

Im using inlineDynamicImports in my vite config, could that be the reason?

kaisalmen commented 1 week ago

Don't know. What happens if you don't use it?

pbrostean commented 1 week ago

Doesn't seem to change anything. Let me try using the editorServiceOverride manually in userServices.

pbrostean commented 1 week ago

Doesn't seem to change anything. Let me try using the editorServiceOverride manually in userServices.

Strangely enough, this only leads to the fact that I also have the error in development mode and the lsp functionalities also no longer work

kaisalmen commented 1 week ago

@pbrostean I can't reproduce this locally. Also, our vite production build does not have this problem: https://typefox.github.io/monaco-languageclient

Do you init it like this? https://github.com/TypeFox/monaco-languageclient/blob/main/packages/wrapper/src/vscode/services.ts#L53-L56

pbrostean commented 1 week ago

@kaisalmen I jused it like this:

userServices: { ...getEditorServiceOverride(useOpenEditorStub) },

Got this atleast working by now but it doesnt't do more than giving me the same error but now in dev mode aswell.

kaisalmen commented 1 week ago

@pbrostean can you share a repo?

pbrostean commented 1 week ago

Unfortunately I am not allowed to do this. I forgot to mention that the error always occurs together with another error - perhaps that will allow to draw further conclusions.

Uncaught (in promise) TypeError: o.get(...).startup is not a function
    at tie.value (...)
    at D._deliver (...)
    at D.fire (...)
    at zT.invokeFunction (...)
    at Zbi (...)
    at async yvt (...)
    at async QVi (...)
    at async ZVi (...)
    at async vTi.init (...)

Would you mind sharing your vite config?

kaisalmen commented 1 week ago

@pbrostean the vite config files are located here: https://github.com/TypeFox/monaco-languageclient/blob/main/ https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/