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

[plugin] Cache command arguments to safely pass the command over JSON-RPC #5961

Merged
merged 1 commit into from
Aug 27, 2019

Conversation

vinokurig
Copy link
Contributor

@vinokurig vinokurig commented Aug 16, 2019

What it does

How to test

  1. Clone sample plugin: https://github.com/vinokurig/Test.git and compile it

  2. Start the plugin as a Hosted Plugin

  3. Open the tree-view (list icon on the left panel):
    screenshot-localhost-3030-2019 08 16-18-01-11

  4. click the label item
    See A message from argument's field is shown.

The argument object contains a reference to itself: https://github.com/vinokurig/Test/blob/cdd7548fd1d1d3f22ba263017a80ef8a6192ac52/src/nodeDependencies.ts#L18-L20
so the command was safely converted and passed over JSON-RPC without an error.

Review checklist

Reminder for reviewers

@vinokurig vinokurig requested a review from olexii4 August 16, 2019 15:05
@vinokurig vinokurig requested a review from a team as a code owner August 16, 2019 15:05
@akosyakov akosyakov added plug-in system issues related to the plug-in system tree issues related to the tree (ex: tree widget) labels Aug 16, 2019
@vinokurig
Copy link
Contributor Author

fixes eclipse-che/che#13956

Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only commenting, because I just did a code review.

* Convert to a command that can be safely passed over JSON-RPC.
*/
toSafeCommand(command: theia.Command, disposables: DisposableCollection): theia.Command {
if (!this.isCommandRegistered) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"isSafeCommandRegistered" would make it clear it's not the command that is being converted that needs to be registered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@tsmaeder
Copy link
Contributor

@vinokurig is there an issue this PR fixes? I can't find a reference in the PR description.

@vinokurig
Copy link
Contributor Author

@tsmaeder

@vinokurig is there an issue this PR fixes? I can't find a reference in the PR description.

#5961 (comment)

@@ -34,10 +35,16 @@ export class CommandRegistryImpl implements CommandRegistryExt {
private readonly commands = new Set<string>();
private readonly handlers = new Map<string, Handler>();
private readonly argumentProcessors: ArgumentProcessor[];
private readonly commandsConverter: CommandsConverter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CommandRegistryImpl never does anything with the "commandsConverter". IMO, the converter should be owned by
"TreeViewExtImpl", not the command registry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be used by other APIs.

olexii4
olexii4 previously approved these changes Aug 19, 2019
@akosyakov
Copy link
Member

akosyakov commented Aug 20, 2019

@olexii4 Does your approve means that changes looks good and you tested that it behaves well? Please provide such comments to make it clear for other committers that PR is well reviewed already. 🙏 We included it in review guidelines for such reasons: https://github.com/theia-ide/theia/blob/master/doc/pull-requests.md#justifiying-approve

@akosyakov
Copy link
Member

@vinokurig If @tsmaeder is fine with changes and @olexii4 approve means #5961 (comment) you can proceed

@akosyakov
Copy link
Member

I cannot verify, it fails for me:

root ERROR Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:470:11)
    at ServerResponse.header (/workspace/theia/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (/workspace/theia/node_modules/express/lib/response.js:170:12)
    at /workspace/theia/packages/plugin-ext/lib/hosted/node/plugin-reader.js:112:37
    at /workspace/theia/node_modules/express/lib/response.js:430:22
    at SendStream.onend (/workspace/theia/node_modules/express/lib/response.js:1047:5)
    at SendStream.emit (events.js:189:13)
    at ReadStream.onend (/workspace/theia/node_modules/send/index.js:822:10)
    at ReadStream.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
root INFO [hosted-plugin: 1934] PLUGIN_HOST(1934): PluginManagerExtImpl/init()
root INFO [hosted-plugin: 1934] PLUGIN_HOST(1934): initializing(custom-view-samples@0.0.1 with /workspace/theia/packages/plugin-ext-vscode/lib/node/plugin-vscode-init.js)
root INFO [hosted-plugin: 1934] PLUGIN_HOST(1934): PluginManagerExtImpl/loadPlugin(/workspace/theia/plugins/Test/out/extension.js)
root ERROR Uncaught Exception:  Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
root ERROR Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:470:11)
    at ServerResponse.header (/workspace/theia/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (/workspace/theia/node_modules/express/lib/response.js:170:12)
    at /workspace/theia/packages/plugin-ext/lib/hosted/node/plugin-reader.js:112:37
    at /workspace/theia/node_modules/express/lib/response.js:430:22
    at SendStream.onend (/workspace/theia/node_modules/express/lib/response.js:1047:5)
    at SendStream.emit (events.js:189:13)
    at ReadStream.onend (/workspace/theia/node_modules/send/index.js:822:10)
    at ReadStream.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
root ERROR Uncaught Exception:  Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
root ERROR Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:470:11)
    at ServerResponse.header (/workspace/theia/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (/workspace/theia/node_modules/express/lib/response.js:170:12)
    at /workspace/theia/packages/plugin-ext/lib/hosted/node/plugin-reader.js:112:37
    at /workspace/theia/node_modules/express/lib/response.js:430:22
    at SendStream.onend (/workspace/theia/node_modules/express/lib/response.js:1047:5)
    at SendStream.emit (events.js:189:13)
    at ReadStream.onend (/workspace/theia/node_modules/send/index.js:822:10)
    at ReadStream.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)

I don't think that it is caused by this PR. It seems to be something broken with plugin systems generally now. The same issue were observed in my Monaco PR and in #5967

@akosyakov
Copy link
Member

I will do a PR promptly, found an issue.

@akosyakov
Copy link
Member

@vinokurig please review #6002, after that we can rebase your PR and test it

@vinokurig
Copy link
Contributor Author

@akosyakov Re-based the branch.
While testing I've discovered that If the tree has more than one node with nested children, the command will work only for children of currently expanded node. That's because the internal commands map refreshes on each children request:
https://github.com/theia-ide/theia/blob/191bb6d02a841fe1f448809bfa1c64f032d00edb/packages/plugin-ext/src/plugin/tree/tree-views.ts#L177
In the vscode command is registered only when the tree node is fetched so they can refresh the commands map on the refresh tree request. In Theia tree nodes are always requested by the tree, so the commands map is refreshed on the children request to not to overload the commands map. I think we need to change the behavior of the tree like in the vscode way: #6007

@akosyakov
Copy link
Member

I see, please put it the description of #6007 as well.

@akosyakov
Copy link
Member

click the label item
See A message from argument's field is shown

@vinokurig I'm trying but clicking on the label item does not do anything. Where should it appear?

@akosyakov
Copy link
Member

akosyakov commented Aug 21, 2019

It only works if i click Refresh in the view or reload the browser. It does not work for me on first start for some reasons. You can also reproduce it by removing the focus from the view (i.e. open the navigator) and then do Reset Workbench Layout command.

@vinokurig
Copy link
Contributor Author

@akosyakov

It only works if i click Refresh in the view or reload the browser. It does not work for me on first start for some reasons. You can also reproduce it by removing the focus from the view (i.e. open the navigator) and then do Reset Workbench Layout command.

Fixed, it was a bug in the tree-view-widget.tsx

@vinokurig
Copy link
Contributor Author

@akosyakov
You can check it with https://github.com/microsoft/vscode-extension-samples/tree/master/tree-view-sample as well.
The commands from the Node Dependencies tree works: the web page of the dependency is opened by clicking the tree node.
NOTE The commands works only from the latest opened parent, If you click on node from previously opened parent it won't work. Can we go with it and than fix it in the #6007 ?

@@ -141,13 +141,14 @@ export class PluginTree extends TreeImpl {
}, update);
}
if (TreeViewNode.is(node)) {
return Object.assign(node, update);
return Object.assign(node, update, { command: item.command });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinokurig command cannot be applied to composite elements? just checking

Copy link
Contributor Author

@vinokurig vinokurig Aug 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant whether it should be set on the composite according to VS Code expectations? If so it would be nice to adjust it as well. It could be done separately, but needs an issue at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised an issue with question #6025

@akosyakov akosyakov dismissed olexii4’s stale review August 23, 2019 06:41

changes should be tested to be approved and a comment should be provided about it

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check it with https://github.com/microsoft/vscode-extension-samples/tree/master/tree-view-sample as well.

I'm trying, but nothing happens:

  • I've installed an extension.
  • And then click on items in dependency tree.
  • I thought that a notification should appear for each item, but nothing is shown.
  • Refresh and reload does not help.

packages/plugin-ext/src/plugin/command-registry.ts Outdated Show resolved Hide resolved
@akosyakov
Copy link
Member

Tested it with VS Code as well, let me try again.

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've managed to get it work, fault on my side!

…-RPC

Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
@akosyakov
Copy link
Member

@vinokurig please merge, let's tackle remaining 2 issues separately

@olexii4
Copy link
Contributor

olexii4 commented Aug 26, 2019

I tested these changes inside Eclipse CHE

I built the new image "olexii4dockerid/che-theia:next"
https://github.com/eclipse/che-theia

./build.sh --build-args:GITHUB_TOKEN=${GITHUB_TOKEN},--tag:next --branch:che-13956 --git-ref:refs\\/heads\\/master

and push it to upstream.
Create a new workspace from the devfile
https://gist.githubusercontent.com/olexii4/99aa676393255e70e03f70b0cafe5bde/raw/6e838186630eb64c272d9bf698666569610d815a/devfile.yaml
Open 'my Workspace' and try open a link from the tree.

Screenshot from 2019-08-26 19-31-35

@vinokurig vinokurig merged commit 24bf9f2 into master Aug 27, 2019
@vinokurig vinokurig deleted the che-13956 branch August 27, 2019 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plug-in system issues related to the plug-in system tree issues related to the tree (ex: tree widget)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants