-
Notifications
You must be signed in to change notification settings - Fork 30k
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
pass selected tree item context to view/title commands #42903
Comments
I would expand on this to also provide the treeview instance as well as the selected node. I have some generic commands (refresh, close, etc) that I use across a few views, and right now I am required to create new commands for each view (causing a command explosion in I would also love if the treeview was also returned on itself even when executing a command on a node (so that way the node doesn't have to carry around its parent if access is needed). Overall I keep coming back to this request: #25716 having more/structured context for how commands were invoked makes them much easier to deal with |
@eamodio Could you do something like this? I use an internal command to proxy to functions I want to invoke so I don't have to register every action as a command. Here is an example snippet of something I use... let disposable = vscode.commands.registerCommand('dakara-internal.oncommand', (onCommand:Function, ...params) => onCommand.apply(this, params))
function showLine(lineNumber:number) {
vscode.commands.executeCommand("revealLine", {lineNumber})
}
export function makeTreeItemFromSelection(line: vscode.TextLine) {
return {
label: (line.lineNumber + 1) + ` ${Glyph.TRI_DOT_VERTICAL} ` + line.text,
command: {title: 'reveal', command: 'dakara-internal.oncommand', arguments: [showLine, line.lineNumber]},
}
}``` |
I would like to re-raise this. I keep hitting this issue more and more often (causing an explosion of unnecessary commands). For example in GitLens, I've been adding a bunch of new views, and each of these views have many overlapping commands in the Where as if the |
This will be really helpful in removing a lot of redundant commands. For example, I have multiple treeviews and they render some help text in the |
Do you have details on how it broke? Strictly speaking commands should be fit to be called with any argument (since any extension and any keybinding can invoke a command, happens rarely tho). The plan is to build on this assumption and not make this a opt-in change. However, after the last sync we have been discussing to call these commands with just the model objects: |
I think this matches what is currently done for context menu commands on tree items, right? |
The command that is broken is creating an Azure resource. Here is a link to the issue with a video: microsoft/vscode-azureresourcegroups#363 To understand why this change is problematic for us, let me share a snippet of our code:
Ignoring the context that we inject into all of our commands, the new
This assumption will still break us as we currently only handle expected tree items being focused since the previous entry point must have been the context menu command (where we will know which tree items we allow to be focused for the specific commands), but this solution would be highly preferable to the current implementation. |
The release of this feature will be moved to the September iteration to give extensions enough time to adapt. |
@nturinski Have you had a chance to make the changes needed in VS Code Extensions for Azure? We merged this change back into main so it's been in VS Code Insiders for about 2 weeks now. |
Hi @alexr00 According to our investigation, it seems like the new changes don't break us. Thanks for considering us! 😄 |
Great to hear! Closing this issue so that it gets added to our testing for September. |
Verifying:
The arguments should behave the same as for commands in the context menu. |
How to get them ? doesn't work:
|
@irvnriir are you using Insiders for this? If not you'll need to wait until 1.72 ships, probably by the end of next week, |
Am I doing it wrong?
All I get is |
Make sure you register the view/title command to a contributed |
Oh, I see it, thanks |
I would like to have the selected context passed to view commands so that I can act on the selected node in the tree. for example, let's say I want to have a command in the Docker explorer Navigation area (next to where it says "DOCKER" on the sash) that runs the selected image in the tree.
I would register my command:
vscode.commands.registerCommand('vscode-docker.explorer.run', (context?: any, selectedContext?: any[]) => dockerExplorerProvider.run(context, selectedContext));
And then in my command I can get the selected node(s) from the tree
The text was updated successfully, but these errors were encountered: