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

[vscode] Support ViewBadge and tree/webview view badge property #12330

Merged
merged 1 commit into from
Mar 29, 2023

Conversation

rschnekenbu
Copy link
Contributor

What it does

Adds support for ViewBadge and badge for tree views and Webview views

Fixes #12020

Contributed on behalf of STMicroelectronics

How to test

This PR adds a badge to Tree based views and webviews contributed by extensions. Thus 2 extensions based on vscode samples are to be tested with this patch.

custom-view-samples-0.0.2.zip This one provides a tree view with 2 actions (change badge value and change tooltip value). The first one will ask for a new value, the second for a new tooltip.

tree-view-badge

calico-colors-0.0.13.zip This one slightly updates the webview view vscode extensions sample, to change the tooltip when the add color is triggered, and to remove the tooltip (set to undefined) when the clear colors is triggered.

webview-view-badge

To test, install the extensions and trigger the action:

  • 'Test View: change badge/tooltip value' to change the badge or its tooltip on the Test View
  • 'Calico Colors: Add color' to add a tooltip to the calico colors test view. The first color does not add a badge, it only shows after the second one.
  • 'Calico Colors: Clear color' to set the badge to undefined, and as indicated by the doc of ViewBadge, the badge is deleted.

Review checklist

Reminder for reviewers

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.

First reading of the code.

packages/core/src/browser/view-container.ts Outdated Show resolved Hide resolved
packages/core/src/browser/view-container.ts Outdated Show resolved Hide resolved
packages/core/src/browser/view-container.ts Outdated Show resolved Hide resolved
packages/core/src/browser/view-container.ts Show resolved Hide resolved
}
set badge(badge: ViewBadge | undefined) {
this._badge = badge;
this.proxy.$setBadge(this.treeViewId, this._badge);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a potential problem: the badge object is created by the plugin. It could contain arbitrary structures, which might no be serializable via our rpc algorithm (this has happened before 🤷) We need to copy the values like

this.proxy.$setBadge(this.treeViewId, {value: badge.value, tooltip: badge.tooltip});

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 is adressed in the new version, with a slight change due to badge being potentially undefined:
this.proxy.$setBadge(this.treeViewId, badge ? { value: badge.value, tooltip: badge.tooltip } : undefined);

There may be a shorter syntax I am not aware of.

@@ -138,6 +150,38 @@ export class PluginViewWidget extends Panel implements StatefulWidget, Descripti
this.onDidChangeDescriptionEmitter.fire();
}

get badge(): number | undefined {
if (this._badge === undefined) {
for (const w of this.widgets) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This algorithm seems strange. Other places seem to assume that the "wrapped" widget is this.widgets[0]. Why is the algorithm for badge different from descritption?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is indeed more coherent here with this.widget[0].
This is adressed in the new version.

this.assertNotDisposed();
if (this._badge !== badge) {
this._badge = badge;
this.proxy.$setBadge(this.handle, badge);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

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 has been adressed also in the new version, with same adaptation due to badge being potentially undefined.

@tsmaeder
Copy link
Contributor

The "Calico Colors" example does not work reliably for me in electron, Invoking the action the first time, I see this in the back end log:

2023-03-23T10:02:55.325Z root ERROR [hosted-plugin: 22876] Promise rejection not handled in one second: Error: No webview found , reason: Error: No webview found
2023-03-23T10:02:55.325Z root ERROR [hosted-plugin: 22876] With stack trace: Error: No webview found
    at WebviewViewsExtImpl.getWebviewView (C:\Users\thomas\code\EclipseSource\theia\packages\plugin-ext\lib\plugin\webview-views.js:75:19)
    at WebviewViewsExtImpl.$onDidChangeWebviewViewVisibility (C:\Users\thomas\code\EclipseSource\theia\packages\plugin-ext\lib\plugin\webview-views.js:62:34)
    at RpcInvocationHandler.onNotification (C:\Users\thomas\code\EclipseSource\theia\packages\plugin-ext\lib\common\proxy-handler.js:94:28)
    at C:\Users\thomas\code\EclipseSource\theia\packages\plugin-ext\lib\common\proxy-handler.js:87:43
    at C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\event.js:103:69
    at CallbackList.invoke (C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\event.js:109:26)
    at Emitter.fire (C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\event.js:224:29)
    at RpcProtocol.handleNotify (C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\message-rpc\rpc-protocol.js:188:36)
    at RpcProtocol.handleMessage (C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\message-rpc\rpc-protocol.js:68:26)
    at C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\message-rpc\rpc-protocol.js:47:66

Sometimes, the update of the badge via "add color" or "clear colors" works, though.

@tsmaeder
Copy link
Contributor

@rschnekenbu it's usually a good idea to keep changes due to feedback in separate commits until we're ready to merge: it allows reviewers to see the latest changes, instead of having to re-review the whole thing.

@rschnekenbu
Copy link
Contributor Author

@rschnekenbu it's usually a good idea to keep changes due to feedback in separate commits until we're ready to merge: it allows reviewers to see the latest changes, instead of having to re-review the whole thing.

@tsmaeder, thanks for advice! I will add commit on top of the reviewed one starting from now.

@rschnekenbu
Copy link
Contributor Author

rschnekenbu commented Mar 27, 2023

The "Calico Colors" example does not work reliably for me in electron, Invoking the action the first time, I see this in the back end log:

2023-03-23T10:02:55.325Z root ERROR [hosted-plugin: 22876] Promise rejection not handled in one second: Error: No webview found , reason: Error: No webview found
2023-03-23T10:02:55.325Z root ERROR [hosted-plugin: 22876] With stack trace: Error: No webview found
    at WebviewViewsExtImpl.getWebviewView (C:\Users\thomas\code\EclipseSource\theia\packages\plugin-ext\lib\plugin\webview-views.js:75:19)
    at WebviewViewsExtImpl.$onDidChangeWebviewViewVisibility (C:\Users\thomas\code\EclipseSource\theia\packages\plugin-ext\lib\plugin\webview-views.js:62:34)
    at RpcInvocationHandler.onNotification (C:\Users\thomas\code\EclipseSource\theia\packages\plugin-ext\lib\common\proxy-handler.js:94:28)
    at C:\Users\thomas\code\EclipseSource\theia\packages\plugin-ext\lib\common\proxy-handler.js:87:43
    at C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\event.js:103:69
    at CallbackList.invoke (C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\event.js:109:26)
    at Emitter.fire (C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\event.js:224:29)
    at RpcProtocol.handleNotify (C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\message-rpc\rpc-protocol.js:188:36)
    at RpcProtocol.handleMessage (C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\message-rpc\rpc-protocol.js:68:26)
    at C:\Users\thomas\code\EclipseSource\theia\packages\core\lib\common\message-rpc\rpc-protocol.js:47:66

I sometimes get also the same issue, depending if the view is already selected or not in the tool. I have the same kind of issue on master, and I prefered not to spend too much time on debugging the vscode samples. There may be a test to add on the extension itself.

Sometimes, the update of the badge via "add color" or "clear colors" works, though.

Is this working only sometimes or does it works always after the second action? I could not have any issue while testing once the second action has been triggered, the first one failing with the view visibility.

I also have now an issue since rebasing on latest master (basically since pr #12326 was merged). The split icon terminal appears on all views, especially the calico color one. And the badges are hidden as soon as an action is in the toolbar. I had to patch the split command registration in order to get the badge working.

@rschnekenbu rschnekenbu requested review from tsmaeder and removed request for msujew March 27, 2023 20:51
@tsmaeder
Copy link
Contributor

Besides the "Split Terminal"-Problems above, the changes work fine for me.

@tsmaeder
Copy link
Contributor

@rschnekenbu this one needs a rebase, as well.

Extend BadgeWidget with tooltip support
Provide support for badge on tree based views and webview views

Contributed on behalf of STMicroelectronics

Signed-off-by: Remi SCHNEKENBURGER <rschnekenburger@eclipsesource.com>
@rschnekenbu
Copy link
Contributor Author

@tsmaeder, as expected, the license check is failing, as for #12358. As the PR does not influence dependencies, is this still possible to approve the PR and merge it?

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.

Looks good to me, now.

@tsmaeder
Copy link
Contributor

@rschnekenbu I guess I could: the licensing issues are not caused by this PR and they won't be fixed by it. The important thing re: licensing are releases, anyway, as far as I understand.

@tsmaeder tsmaeder merged commit 11ade90 into eclipse-theia:master Mar 29, 2023
@vince-fugnitto vince-fugnitto added this to the 1.36.0 milestone Mar 30, 2023
@vince-fugnitto vince-fugnitto added the vscode issues related to VSCode compatibility label Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[vscode] Support ViewBadge
3 participants