CodinGame / monaco-vscode-api

VSCode public API plugged on the monaco editor
MIT License
226 stars 31 forks source link

`setAsDefaultApi` does not seem to work #442

Closed abentkamp closed 3 months ago

abentkamp commented 4 months ago

Here is a minimal example of what I am attempting:


import { initialize as initializeMonacoService} from 'vscode/services'
import { ExtensionHostKind, registerExtension } from 'vscode/extensions'
import getModelServiceOverride from '@codingame/monaco-vscode-model-service-override'
import getExtensionServiceOverride from '@codingame/monaco-vscode-extensions-service-override'
import 'vscode/localExtensionHost'
import { workspace } from 'vscode'

await initializeMonacoService({
  ...getModelServiceOverride(),
  ...getExtensionServiceOverride()
})

await registerExtension({
  name: 'monacotest2',
  publisher: 'hhu-adam',
  version: '1.0.0',
  engines: {
    vscode: '*'
  },
}, ExtensionHostKind.LocalProcess).setAsDefaultApi()

workspace.getConfiguration(undefined);

Accessing workspace on the last line yields:

Uncaught Error: Default api is not ready yet, do not forget to import 'vscode/localExtensionHost' and wait for services initialization

What am I doing wrong?

I understand that I can call const vscode = await getApi() on the result of registerExtension and then use vscode.workspace instead of workspace. However, I would like to reuse code from an existing VSCode extension, which will just call workspace.

CGNonofr commented 4 months ago

Can you please provide a full reproduction repo?

CGNonofr commented 4 months ago

I've just tried your exact code without issue, so I see only one possible reason: your bundler is for some reason duplicating some code (due to deps optimization or something) what do you use?

abentkamp commented 3 months ago

Sorry for being so slow to respond. I am using vite. I will attempt to set up a reproduction repo, maybe I can eliminate the code duplication on the way.

abentkamp commented 3 months ago

Thanks a lot! I guess I had two versions of vscode in the project because I also had npm installed the VSCode extension I'd like to use.