Skip to content
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

Allow extensions to contribute dynamic submenus #110218

Open
gjsjohnmurray opened this issue Nov 9, 2020 · 10 comments
Open

Allow extensions to contribute dynamic submenus #110218

gjsjohnmurray opened this issue Nov 9, 2020 · 10 comments
Assignees
Labels
feature-request Request for new features or functionality menus Menu items and widget issues
Milestone

Comments

@gjsjohnmurray
Copy link
Contributor

Currently an extension's menu and submenu contributions can only be statically defined in its package.json. At runtime the extension can use context keys it creates via the setContext command together with when clauses to hide its contributed items dynamically. But there are use-cases where the actual items cannot be predefined, and we have to resort to a QuickPick. IMO this results in a poor UX and some accessibility issues because the list of choices does not appear alongside the context menu action which triggered it.

I see two ways of solving this.

A) Allow submenu contents to be computed when the parent menu entry is selected (or perhaps merely focused).

I outlined this in #9827 (comment)

B) Add a setSubmenuContents equivalent to the existing setContext command.

Using this approach an extension would run the new command, specifying the id of one of the submenus it had defined in its settings.json, plus a second command argument containing the new definition of the submenu.

@gjsjohnmurray
Copy link
Contributor Author

ping @DanTup @eamodio who may be interested, based on other issues I have reviewed.

@jrieken jrieken added this to the Backlog Candidates milestone Nov 9, 2020
@jrieken jrieken added feature-request Request for new features or functionality menus Menu items and widget issues labels Nov 9, 2020
@gjsjohnmurray
Copy link
Contributor Author

Also pinging @Blaiski @larshp @gautier-lefebvre @erythana @yubaoquan @joaomoreno in case you want to 👍 this issue to try and get it into Backlog. Remember, do that on the original issue above, not on this comment.

@DanTup
Copy link
Contributor

DanTup commented Nov 9, 2020

Is this the same as #27536? There are definitely many places I'd like dynamic menus (though not just sub-menus - for example on custom tree nodes). One argument against them in the past was making context menus slow (by doing async work), though I think in all my cases I could provide the commands up-front, just not statically (for example at the time I provide a tree node).

@xiaosu12138
Copy link

Another +1 from me too. I need to contribute dynamic submenus include menu title according to my setting.json in VS Code

@michaeljones
Copy link

I have a scenario of adding a submenu to a tree view item. view/item/context entries for the tree view item can use the viewItem as additional content to enable or disable certain entries. When creating a submenu from the tree view item, it seems like the viewItem is not available in when expressions on items in the submenu. Is that true? If so, could that be addressed? I could make a separate ticket.

@MaxKless
Copy link

@gjsjohnmurray are there any news on this?
It's been in the backlog for 2 years... I'd be happy to try and contribute this but would love some feedback first to make sure i'm not wasting my time.

@gjsjohnmurray
Copy link
Contributor Author

@MaxKless I am not aware of any news. I am a contributor but not a member of the core team, but my hunch is they would want to do this themselves if it ever happens.

@entlicher

This comment was marked as off-topic.

@MrYZhou
Copy link

MrYZhou commented Jul 28, 2024

image

I implemented a button by configuring contribution points, and it functions properly.
image

But the configuration of my button is quite unique. There are quite a few possibilities. I must and can only make judgments in the code. So I have no way now. Because the official API does not have any places to support it. What shall I do? I don't need particularly complex functions. Just like
The custom method like 'vscode. window. create Status Bar Item' is very good

@yiliang114
Copy link
Contributor

The current menus cannot be contributed dynamically. I first have to know all the menus lists and then display them conditionally through when. There are actually many scenarios where the list of menus I need to render is obtained through the asynchronous interface, and the implementation I don't know exactly how many and which menus need to be registered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality menus Menu items and widget issues
Projects
None yet
Development

No branches or pull requests

10 participants