CodinGame / monaco-vscode-api

VSCode public API plugged on the monaco editor
MIT License
224 stars 30 forks source link

Missing `initialize` from `vscode/extensions` #283

Closed char0n closed 9 months ago

char0n commented 9 months ago

Hi @CGNonofr,

It seems that following import now longer works:

import { initialize } from 'vscode/extensions'

initialize is no longer part of that file. Affected version is @codingame/monaco-vscode-api@=1.83.15.

char0n commented 9 months ago

Looking at https://github.com/CodinGame/monaco-vscode-api/commit/a295d70ecda03f990fa2ea769973092bc8fa115d it seems it's been removed.

char0n commented 9 months ago

This documentation https://github.com/CodinGame/monaco-vscode-api#vscode-api-usage doesn't seem to be aligned with the actual code.

char0n commented 9 months ago

I figured I need to use:

import 'vscode/localExtensionHost';`

But it seems, that things will starts working only after I perform some action (like opening a command palette):

https://github.com/CodinGame/monaco-vscode-api/assets/193286/6317e9ff-0c93-427a-b7d3-47df01b39a23

char0n commented 9 months ago

I did dig deeper and the issue is with monaco service initialization. The simplest code to reproduce:

import {  initialize as initializeMonacoServices } from 'vscode/services';
import 'vscode/localExtensionHost';

console.dir('initializing');
await initializeMonacoServices({});
console.dir('initialized');

initialized is never printed and the promise returned from initializeMonacoServices never resolves. Any idea what would be the problem?


Following seems to work; I'm performing some random service action which allows initialization to fall through (resolve).

import {  initialize as initializeMonacoServices,   StandaloneServices, IQuickInputService, } from 'vscode/services';
import 'vscode/localExtensionHost';

console.dir('initializing');
setTimeout(() => {
  StandaloneServices.get(IQuickInputService).quickAccess.show('>', {
    itemActivation: 0,
  });
}, 0);
await initializeMonacoServices({});
console.dir('initialized');
CGNonofr commented 9 months ago

Working on way to improve the changelog

This documentation https://github.com/CodinGame/monaco-vscode-api#vscode-api-usage doesn't seem to be aligned with the actual code.

Right, will fix

initialized is never printed and the promise returned from initializeMonacoServices never resolves. Any idea what would be the problem?

No idea, I'm interested if you find the cause of it

char0n commented 9 months ago

No idea, I'm interested if you find the cause of it

I fails in vscode/lifecycle.js in

async function startup(instantiationService) {

specifically in:

    await instantiationService.invokeFunction(async (accessor) => {
        await Promise.all(( serviceInitializePostParticipants.map(participant => participant(accessor))));
    });

This will never resolve. If I remove this code, everything works as expected.

The serviceInitializePostParticipants list contains following single item:

image

CGNonofr commented 9 months ago

It'll be fixed soon in #285

in the meantime, you can add this workaround:

import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions'
import { registerServiceInitializeParticipant } from 'vscode/lifecycle'

registerServiceInitializeParticipant(accessor => accessor.get(IExtensionService))
char0n commented 9 months ago
import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions'
import { registerServiceInitializeParticipant } from 'vscode/lifecycle'

registerServiceInitializeParticipant(accessor => accessor.get(IExtensionService))

I can confirm, the workaround works. Thanks!