-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor PluginMenuContributionHandler #11290
Refactor PluginMenuContributionHandler #11290
Conversation
e132261
to
5bdff25
Compare
f426440
to
942bafe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks quite good, at least all menu contribution points mentioned in the testing steps seem to work as expected with the provided test extension.
By the way, while installing Gitlens as a test for this, I noticed that webviews don't display for me in web environments for some reason. I always get a 404 not found error while loading them, even fairly old versions of Theia (tested with 1.26.0, 1.25.0 and 1.20.0). Can you reproduce this issue @colin-grant-work? I didn't want to open a separate issue for this, if it only related to my environment.
packages/plugin-ext/src/main/browser/menus/plugin-menu-command-adapter.ts
Outdated
Show resolved
Hide resolved
@injectable() | ||
export class CodeEditorWidgetUtil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: I'm usually all in for keeping the code extensible for downstream users. However, I don't believe that it'd be necessary in this case. How about a CodeEditorWidget
namespace instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd agree, but this class already existed in this form - I just moved it out of the menus-contribution-handler
file. Happy to deprecate / remove in favor of a namespace, though.
packages/plugin-ext/src/main/browser/menus/plugin-menu-command-adapter.ts
Show resolved
Hide resolved
@msujew, thanks for taking a look. I'm currently working on a more thorough refactor to support submenu registration better without forcing all plugin items into a single group, since that isn't the behavior intended by VSCode. I'll address your comments - and remove all of my random console logs :-) - as I work through that. |
d2d9c26
to
50b2334
Compare
@planger, would you mind taking a look at the Playwright failures here? The failures have to do with menus, and the PR has to do with menus, so it seems likely that the changes have caused the failures, but I took a bit of a look and couldn't figure out where things are going wrong: the menus that the tests claim to be looking for are present, and the PR doesn't change any of the HTML rendering that they hook onto, as far as I can tell. |
@colin-grant-work Sure, I'm happy to have a look! I'm currently on vacation though (including next week), but can look into it right after. Is that soon enough? If it can't wait I'll ask someone in our team to have a look. |
74696f0
to
198a462
Compare
@planger, I was able to track down the problem. My code had added trailing separators to menus, and Phosphor was automatically hiding those using a |
@colin-grant-work Great, thanks for making the page object more resilient! |
- Adds support for `when` contexts in submenus - Adds support for treating menu contributions as toolbar contributions
- As a consequence of this approach, all plugin-contributed commands will be grouped together
TODO: Since the submenus can occur at different levels (navigator, other groups) We have to handle that. May not need to loop through everything, but we have to loop through some things.
198a462
to
37088c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 I confirmed the latest changes work well.
What it does
Fixes #11264 by introducing support for
when
clauses in submenu contributions.Also refactors the
PluginMenuContributionHandler
and allows for straightforward contribution of menu items to tabbar toolbars.The refactor was not strictly necessary to allow
when
clauses in submenus but was motivated by the complexity of thePluginMenuHandler
class, which had scattered in it (1) knowledge about matching contribution points to menus, (2) elaborate additional machinery for building a tree to handle all of the places a given submenu might occur, (3) knowledge of how to transform the arguments passed in various contexts to the arguments expected by plugins, and (4) knowledge about how to manage toolbar items contributed from menus. Completely missing from that implementation were (1) handling oficon
fields of submenus and (2) the ability to contribute a submenu to a titlebar's `navigation' group and get an item that opens that menu.In place of that monolith, I've implemented a system that divides those responsibilities in the following ways.
MenuCommandAdapterRegistry
system that can delegate toMenuCommandAdapters
to execute specific commands, and aPluginMenuCommandAdapter
to handle the argument transformations for particular contexts.MenuContributionHandler
to the toolbar system, I've added the ability to add an entire menu to the tabbar system.In addition, I've added:
icon
s from submenu contributionsMenuCommandAdapter
systemwhen
contexts.MenuCommandAdapter
systemSome remaining troublesome bits:
BrowserMenuFactory
andElectronMainMenuFactory
.instanceof
checks forCompositeMenuNode
andActionMenuNode
, both of which diverged quite a bit from theMenuNode
interface. That makes the system (including downstream customizations) pretty fragile, because it can't easily accept anything not in the class hierarchy of those two kinds. I've tried to expand the interface ofMenuNode
to include many of the fields present on those implementations and then rely less oninstanceof
checksmore
context menu, e.g.), and my code mostly adds special cases on top.How to test
We support these menu contribution points:
Details on their location can be found here (though not as nicely alphabetized :-)).
Appears in: <contribution point>
.'SENTINEL FOR THE ARGS WE GET FOR', contributionPoint, '\n', ...args
master
..ts
files should include aTest Submenu
; other files should not.beaker-stop
icon should appear for.ts
files only. Clicking on that item should reveal a menu with the labelAppears in: menu-contribution-test.submenu
.Review checklist
Reminder for reviewers