eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
19.87k stars 2.48k forks source link

[plug-in] Exception when plugin add own commands in menus #3344

Open evidolob opened 5 years ago

evidolob commented 5 years ago

Exception:

Uncaught (in promise) Error: A command with id 'cSpell.addWordToUserDictionary' does not exist.
    at ActionMenuNode.get [as label] (menu.ts:232)
    at ActionMenuNode.get [as sortString] (menu.ts:246)
    at menu.ts:179
    at Array.sort (<anonymous>)
    at CompositeMenuNode.../../packages/core/lib/common/menu.js.CompositeMenuNode.addNode (menu.ts:178)
    at MenuModelRegistry.../../packages/core/lib/common/menu.js.MenuModelRegistry.registerMenuAction (menu.ts:64)
    at menus-contribution-handler.ts:48
    at Array.forEach (<anonymous>)
    at _loop_1 (menus-contribution-handler.ts:46)
    at MenusContributionPointHandler.push.../../packages/plugin-ext/lib/main/browser/menus/menus-contribution-handler.js.MenusContributionPointHandler.handle (menus-contribution-handler.ts:38)

We add menu items before plugin able to register commands, so I see two options to solve this:

  1. We move command register to package.json file, in commands contribution section(like in VSCode), we keep in plugin code only command handler registration.
  2. We remove menu contribution point from package.json, and configure menu only from plugin code, using new plugin API for menu, after plugin register commands.
azatsarynnyy commented 5 years ago

In my opinion, the 1'st option sounds nice since it provides better compliance with VSCode

azatsarynnyy commented 5 years ago

Once this issue is fixed we should get rid of that workaround https://github.com/theia-ide/theia/blob/d4e3b5ec6c0ea30b4e7941e8fc497d07fa05ed3c/packages/plugin-ext/src/main/browser/menus/menus-contribution-handler.ts#L53-L58 and enable the tests here https://github.com/theia-ide/theia/blob/d4e3b5ec6c0ea30b4e7941e8fc497d07fa05ed3c/packages/plugin-ext/src/main/browser/menus/menus-contribution-handler.spec.ts#L77

akosyakov commented 4 years ago

I don't think it is related to VS Code extension support, but pure Theia plugins only.

@evidolob @azatsarynnyy Is it still relevant?

azatsarynnyy commented 4 years ago

I guess it should be already fixed by https://github.com/eclipse-theia/theia/issues/3994