eclipse-theia/theia

Commands invoked from TreeView context menu do not pass the object to the command handler

Closed this issue · 3 comments

Description

In VS Code, if a command is run from right-clicking an item in a TreeView, the object that provided that TreeItem is passed to the command handler. vs code doc
My extension uses this feature in almost every command, such as this command.
The handlers are registered in this file.
From the OpenInBrowserCmd (first link), you see that I expect the resource passed to be Project | Connection, as these are the two types of objects that are displayed in my TreeView. This works great in VS Code.

But in Theia, the resource passed is instead a string roughly outlining the item's position and indices in the tree. This will cause extensions' commands like mine to fail to work in Theia because they rely on that context.

I plan to refactor my extension to use the TreeView selection events to infer the currently selected project/connection. But I expect mine is not the only extension to use this behaviour from VS Code, so Theia should implement this feature to allow more extensions to work with minimal friction.

Reproduction Steps

You need Microclimate installed to use the extension, so hopefully the description above is enough.

  1. Clone https://github.com/microclimate-dev2ops/microclimate-vscode-tools
  2. cd microclimate-vscode-tools/dev && vsce package
  3. Copy the vsix into $theia_clone/plugins
  4. Run the browser example
  5. Open the Microclimate tree and right-click run Open in Browser
  6. Observe that the command doesn't work, and the output prints the unexpected object.

OS and Theia version:
macOS
Latest theia (built from master)

@tetchel you can also look into fixing it in Theia then you don't have to adjust your extension. PRs are welcomed

I took a look into fixing this, I think it is a symptom of the rpc-protocol stringification, like #4975. The object's non-enumerable properties (namely, its functions) are lost somewhere along the way.

See https://github.com/tetchel/theia-tree-bug

Function are not capable to survive serialization/deserialization: instead of sending a tree element back as an arg, we should send its id, retrieve the original object and pass it as an argument.

It is not related to circular references.