CodinGame / monaco-vscode-api

VSCode public API plugged on the monaco editor
MIT License
251 stars 33 forks source link

[Rel. 7.0.0] Broken Extension Override #461

Closed candiedoperation closed 4 months ago

candiedoperation commented 4 months ago

The Problem in a Nutshell

First time initialization of VS Code Services with the Language Services Override extension fails with: this._fileService.onWillActivateFileSystemProvider is not a function. However, this issue doesn't persist when I downgrade to Version 6.0.3. Furthermore, I made sure that all of the packages are on the same version (either 7.0.0 or 6.0.3).

Other breaking extensions are listed in the last section of this issue.

Stack Trace

Uncaught TypeError: this._fileService.onWillActivateFileSystemProvider is not a function
    AbstractExtensionService2 abstractExtensionService.js:101
    ExtensionService2 extensionService.js:42
    ExtensionServiceOverride2 extensions.js:213
    _createInstance instantiationService.js:120
    _createServiceInstance instantiationService.js:224
    _createServiceInstanceWithOwner instantiationService.js:213
    _createAndCacheServiceInstance instantiationService.js:203
    _safeCreateAndCacheServiceInstance instantiationService.js:161
    _getOrCreateServiceInstance instantiationService.js:148
    get instantiationService.js:70
    startup lifecycle.js:38
    invokeFunction instantiationService.js:77
    startup lifecycle.js:36
    initialize2 services.js:211
    setup LSPSetup.ts:67
    <anonymous> LSPSetup.ts:90
    abstractExtensionService.js:101:41

Sample Code (Initialization)

await (async function setup() {
    const workerLoaders: Partial<Record<string, WorkerLoader>> = {
        editorWorkerService: () => new (toCrossOriginWorker(EditorWorker))(),
        textMateWorker: () => new (toCrossOriginWorker(TextMateWorker))(),
    }

    window.MonacoEnvironment = {
        getWorker: function (moduleId, label) {
            const workerFactory = workerLoaders[label]
            if (workerFactory != null) {
                return workerFactory()
            }
            throw new Error(`Unimplemented worker ${label} (${moduleId})`)
        }
    }

    /* Initialize Module */
    await initializeMonacoServices({
        ...getTextmateServiceOverride(),
        ...getThemesServiceOverride(),
        ...getKeybindingsServiceOverride(),
        ...getLanguageServiceOverride()
    });
})();

Sample Code (Usage)

let editor = monaco.editor.create(
      editorContainer.current!,
      {
          theme: 'Default Dark+',
          automaticLayout: true,
          scrollBeyondLastLine: false,
          model: null,
          lightbulb: { enabled: monaco.editor.ShowLightbulbIconMode.OnCode }
      }
  );

Relevant Parts of package.json

  "dependencies": {
    "@codingame/esbuild-import-meta-url-plugin": "^1.0.2",
    "@codingame/monaco-vscode-configuration-service-override": "^7.0.0",
    "@codingame/monaco-vscode-cpp-default-extension": "^7.0.0",
    "@codingame/monaco-vscode-editor-service-override": "^7.0.0",
    "@codingame/monaco-vscode-keybindings-service-override": "^7.0.0",
    "@codingame/monaco-vscode-textmate-service-override": "^7.0.0",
    "@codingame/monaco-vscode-theme-defaults-default-extension": "^7.0.0",
    "@codingame/monaco-vscode-theme-service-override": "^7.0.0",
    "monaco-editor": "npm:@codingame/monaco-vscode-editor-api@^7.0.0",
    "monaco-languageclient": "^8.6.0",
    "vscode": "npm:@codingame/monaco-vscode-api@^7.0.0",
    "vscode-languageclient": "^9.0.1"
  },
  "devDependencies": {
    "@types/vscode": "^1.91.0",
    ... file truncated

Vite Configuration

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import importMetaUrlPlugin from '@codingame/esbuild-import-meta-url-plugin'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react(), nodePolyfills()],
  optimizeDeps: {
    esbuildOptions: {
      plugins: [importMetaUrlPlugin]
    }
  }
})

Final Observations

  1. Downgrading all of the modules to v6.0.3 fixes the issues and everything works perfectly.
  2. Taking off the Language Services Override prevents the fatal error but errors for other modules continue (example):
    Uncaught (in promise) Error: Unable to load extension-file://vscode.theme-defaults/themes/dark_plus.json: Unable to read file 'extension-file://vscode.theme-defaults/themes/dark_plus.json' (Error: Unable to resolve nonexistent file 'extension-file://vscode.theme-defaults/themes/dark_plus.json')
    internalSetColorTheme workbenchThemeService.js:375
    setColorTheme workbenchThemeService.js:346
    current async.js:163
    promise callback*queue async.js:163
    setColorTheme workbenchThemeService.js:345
    setTheme theme.js:16
    setTimeout handler*setTheme/< theme.js:15
    promise callback*setTheme theme.js:14
    StandaloneEditor2 standaloneCodeEditor.js:166
    <anonymous> injection.js:11
    ConfiguredStandaloneEditor monaco.js:73
    _createInstance instantiationService.js:120
    createInstance instantiationService.js:94
    createConfiguredEditor monaco.js:261
    ... output truncated to relevant parts
CGNonofr commented 4 months ago

I made sure that all of the packages are on the same version (either 7.0.0 or 6.0.3).

monaco-languageclient wasn't updated to use the v7, so I doubt you don't have duplicated dependencies.

What is the result of npm list vscode?

candiedoperation commented 4 months ago
Project...
├─┬ @codingame/monaco-vscode-configuration-service-override@7.0.0
│ ├─┬ @codingame/monaco-vscode-files-service-override@7.0.0
│ │ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
│ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
├─┬ @codingame/monaco-vscode-cpp-default-extension@7.0.0
│ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
├─┬ @codingame/monaco-vscode-editor-service-override@7.0.0
│ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
├─┬ @codingame/monaco-vscode-keybindings-service-override@7.0.0
│ ├─┬ @codingame/monaco-vscode-files-service-override@7.0.0
│ │ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
│ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
├─┬ @codingame/monaco-vscode-textmate-service-override@7.0.0
│ ├─┬ @codingame/monaco-vscode-files-service-override@7.0.0
│ │ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
│ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
├─┬ @codingame/monaco-vscode-theme-defaults-default-extension@7.0.0
│ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
├─┬ @codingame/monaco-vscode-theme-service-override@7.0.0
│ ├─┬ @codingame/monaco-vscode-files-service-override@7.0.0
│ │ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
│ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
├─┬ monaco-editor@npm:@codingame/monaco-vscode-editor-api@7.0.0
│ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
├─┬ monaco-languageclient@8.6.0
│ ├─┬ @codingame/monaco-vscode-extensions-service-override@6.0.3
│ │ ├─┬ @codingame/monaco-vscode-files-service-override@6.0.3
│ │ │ └─┬ vscode@npm:@codingame/monaco-vscode-api@6.0.3
│ │ │   ├─┬ @codingame/monaco-vscode-base-service-override@6.0.3
│ │ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │ │   ├─┬ @codingame/monaco-vscode-environment-service-override@6.0.3
│ │ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │ │   ├─┬ @codingame/monaco-vscode-host-service-override@6.0.3
│ │ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │ │   ├─┬ @codingame/monaco-vscode-layout-service-override@6.0.3
│ │ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │ │   └─┬ @codingame/monaco-vscode-quickaccess-service-override@6.0.3
│ │ │     └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │ └─┬ vscode@npm:@codingame/monaco-vscode-api@6.0.3
│ │   ├─┬ @codingame/monaco-vscode-base-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-environment-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-host-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-layout-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   └─┬ @codingame/monaco-vscode-quickaccess-service-override@6.0.3
│ │     └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ ├─┬ @codingame/monaco-vscode-languages-service-override@6.0.3
│ │ └─┬ vscode@npm:@codingame/monaco-vscode-api@6.0.3
│ │   ├─┬ @codingame/monaco-vscode-base-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-environment-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-host-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-layout-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   └─┬ @codingame/monaco-vscode-quickaccess-service-override@6.0.3
│ │     └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ ├─┬ @codingame/monaco-vscode-localization-service-override@6.0.3
│ │ └─┬ vscode@npm:@codingame/monaco-vscode-api@6.0.3
│ │   ├─┬ @codingame/monaco-vscode-base-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-environment-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-host-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-layout-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   └─┬ @codingame/monaco-vscode-quickaccess-service-override@6.0.3
│ │     └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ ├─┬ @codingame/monaco-vscode-model-service-override@6.0.3
│ │ └─┬ vscode@npm:@codingame/monaco-vscode-api@6.0.3
│ │   ├─┬ @codingame/monaco-vscode-base-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-environment-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-host-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   ├─┬ @codingame/monaco-vscode-layout-service-override@6.0.3
│ │   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ │   └─┬ @codingame/monaco-vscode-quickaccess-service-override@6.0.3
│ │     └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ ├─┬ monaco-editor@npm:@codingame/monaco-vscode-editor-api@6.0.3
│ │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│ └─┬ vscode@npm:@codingame/monaco-vscode-api@6.0.3
│   ├─┬ @codingame/monaco-vscode-base-service-override@6.0.3
│   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│   ├─┬ @codingame/monaco-vscode-environment-service-override@6.0.3
│   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│   ├─┬ @codingame/monaco-vscode-host-service-override@6.0.3
│   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│   ├─┬ @codingame/monaco-vscode-layout-service-override@6.0.3
│   │ └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
│   └─┬ @codingame/monaco-vscode-quickaccess-service-override@6.0.3
│     └── vscode@npm:@codingame/monaco-vscode-api@6.0.3 deduped
└─┬ vscode@npm:@codingame/monaco-vscode-api@7.0.0
  ├─┬ @codingame/monaco-vscode-base-service-override@7.0.0
  │ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
  ├─┬ @codingame/monaco-vscode-environment-service-override@7.0.0
  │ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
  ├─┬ @codingame/monaco-vscode-extensions-service-override@7.0.0
  │ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
  ├─┬ @codingame/monaco-vscode-files-service-override@7.0.0
  │ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
  ├─┬ @codingame/monaco-vscode-host-service-override@7.0.0
  │ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
  ├─┬ @codingame/monaco-vscode-layout-service-override@7.0.0
  │ └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
  └─┬ @codingame/monaco-vscode-quickaccess-service-override@7.0.0
    └── vscode@npm:@codingame/monaco-vscode-api@7.0.0 deduped
candiedoperation commented 4 months ago

I think it caused dependency duplication and I didn't think about it! I was wondering if there was some way to use the vscode-languageclient directly instead of using monaco-languageclient. I couldn't find any docs to integrate it using this API. Do you have any thoughts? Thanks a lot for the help :partying_face:

CGNonofr commented 4 months ago

monaco-languageclient can help but it's not mandatory and vscode-languageclient can be used directly. There's nothing specific to that library, you can refer to the offical languageclient documentation.

This library allows to run a VSCode (web) extension which is using vscode-languageclient, either by loading a vsix file, declaring it by hands in the code or even run it in the main thread (with the local extension host, which is probably the simpler way if you need to start/stop dynamically language clients).

candiedoperation commented 4 months ago

Yeah that makes sense to me! Thanks a lot!