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

Add support for sub heading in extension views #9909

Merged

Conversation

aaronrhodes
Copy link
Contributor

@aaronrhodes aaronrhodes commented Aug 16, 2021

What it does

Adds the description field to TreeView from the vscode API.

resolves #9903

How to test

Add a plugin that utilises the TreeView description field.

There is a modified version of the vscode tree-view-sample available in the following repo:

https://github.com/aaronrhodes/vscode-extension-samples

build, and copy or symlink this example into the plugins directory and select a file using the "file explorer" panel in the explorer tab.

Screenshot 2021-08-16 at 11 03 57

Review checklist

Reminder for reviewers

Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution, the changes look good to me so far. The description property does its job.

FYI the title of your PR is a bit misleading, as you're adding support for the description property for views contributed by extensions, not only for outlines.

I have a few remarks before approving.

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

I noticed a couple of things:

  • the commit message needs to be updated, we mention outline-view but I believe we mean all view-container-parts.
  • the description is only visible if the view-container-part is currently expanded in vscode - I believe we should align.

Comment on lines 19 to 28
export interface DescriptionWidget {
description: string;
onDescriptionChange: Emitter<void>;
}

export namespace DescriptionWidget {
/* eslint-disable @typescript-eslint/no-explicit-any */
export function is(arg: any): arg is DescriptionWidget {
return arg !== undefined && !!arg['onDescriptionChange'];
}
Copy link
Member

Choose a reason for hiding this comment

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

I wasn't so sure the file was necessary, and instead it could be directly added to the tree-view.
Adding it under shell/ is also a bit awkward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm now moved this file into view-container.ts as it only really applies to the container widgets

@vince-fugnitto vince-fugnitto added tree issues related to the tree (ex: tree widget) vscode issues related to VSCode compatibility labels Aug 16, 2021
@aaronrhodes aaronrhodes force-pushed the ar/add-vscode-treeview-description branch from bc50b40 to 929d152 Compare August 18, 2021 15:06
@aaronrhodes
Copy link
Contributor Author

I noticed a couple of things:

  • the commit message needs to be updated, we mention outline-view but I believe we mean all view-container-parts.
  • the description is only visible if the view-container-part is currently expanded in vscode - I believe we should align.

thanks for the feedback! Have updated the commit message and the subheading now hides and shows when the panel is collapsed/expanded respectively.

@aaronrhodes aaronrhodes force-pushed the ar/add-vscode-treeview-description branch from 929d152 to 4466fc2 Compare August 18, 2021 16:02
Comment on lines 883 to 887
if (DescriptionWidget.is(this.wrapped) && !this.collapsed) {
subHeading.innerText = !!this.wrapped.description ? this.wrapped.description : '';
} else {
subHeading.innerText = '';
}
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: We can simplify this

Suggested change
if (DescriptionWidget.is(this.wrapped) && !this.collapsed) {
subHeading.innerText = !!this.wrapped.description ? this.wrapped.description : '';
} else {
subHeading.innerText = '';
}
subHeading.innerText = DescriptionWidget.is(this.wrapped) && !this.collapsed && this.wrapped.description || '';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -47,6 +47,17 @@ export class ViewContainerIdentifier {
progressLocationId?: string;
}

export interface DescriptionWidget {
description: string;
onDescriptionChange: Emitter<void>;
Copy link
Member

Choose a reason for hiding this comment

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

Given our coding guidelines, the event name should be renamed to something like:

Suggested change
onDescriptionChange: Emitter<void>;
onDidChangeDescription: Emitter<void>;

Comment on lines 687 to 688
protected readonly onSubHeadingChangedEmitter = new Emitter<void>();
readonly onSubHeadingChanged = this.onSubHeadingChangedEmitter.event;
Copy link
Member

Choose a reason for hiding this comment

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

Similarly to the above comment, the event name should be renamed:

Suggested change
protected readonly onSubHeadingChangedEmitter = new Emitter<void>();
readonly onSubHeadingChanged = this.onSubHeadingChangedEmitter.event;
protected readonly onDidChangeSubHeadingEmitter = new Emitter<void>();
readonly onDidChangeSubHeading = this.onDidChangeSubHeadingEmitter.event;

I understand we have onTitleChanged but I believe that example is legacy, perhaps before we put in place the guideline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -699,6 +712,12 @@ export class ViewContainerPart extends BaseWidget {
this.wrapped.title.changed.connect(fireTitleChanged);
this.toDispose.push(Disposable.create(() => this.wrapped.title.changed.disconnect(fireTitleChanged)));

if (DescriptionWidget.is(this.wrapped)) {
const fireSubHeadingChanged = () => this.onSubHeadingChangedEmitter.fire(undefined);
const sub = (this.wrapped as DescriptionWidget)?.onDescriptionChange.event(fireSubHeadingChanged);
Copy link
Member

Choose a reason for hiding this comment

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

Update to a more meaningful name than sub?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed as it was only really used for debug anyway

flex: 1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
padding-left: 12px;
Copy link
Member

Choose a reason for hiding this comment

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

We should compute this value I believe rather than hardcoding.
Example:

padding-left: var(--theia-ui-padding);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion, thanks!

@aaronrhodes aaronrhodes changed the title Add support for sub heading in outline view Add support for sub heading in extension views Aug 19, 2021
@aaronrhodes aaronrhodes force-pushed the ar/add-vscode-treeview-description branch from 4466fc2 to 37ef12f Compare August 19, 2021 14:10
Comment on lines 687 to 688
protected readonly onDidSubHeadingChangedEmitter = new Emitter<void>();
readonly onDidSubHeadingChanged = this.onDidSubHeadingChangedEmitter.event;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think onDidChangeSubHeading(Emitter) would conform more closely to the guidelines on event naming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No probs, have updated all of these references!

Comment on lines 715 to 717
if (DescriptionWidget.is(this.wrapped)) {
const fireSubHeadingChanged = () => this.onDidSubHeadingChangedEmitter.fire(undefined);
this.toDispose.push((this.wrapped as DescriptionWidget)?.onDidDescriptionChange.event(fireSubHeadingChanged));
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you've performed a type check already, you shouldn't need the as cast or the ?. conditional accessor.

Why the change in terminology here from onDidChangeDescription to onDidChangeSubHeading? I think I'd prefer that we use the description-type names throughout and leave the fact that they're rendered as a subheading as an implementation detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -50,6 +52,8 @@ export class PluginViewWidget extends Panel implements StatefulWidget {
this.node.style.height = '100%';
}

public onDidDescriptionChange: Emitter<void> = new Emitter<void>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public onDidDescriptionChange: Emitter<void> = new Emitter<void>();
onDidChangeDescription: Emitter<void> = new Emitter<void>();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 +

Signed-off-by: Aaron Rhodes <aaron.rhodes@arm.com>
@aaronrhodes aaronrhodes force-pushed the ar/add-vscode-treeview-description branch from 37ef12f to d880c0e Compare August 26, 2021 14:47
@aaronrhodes
Copy link
Contributor Author

thanks @colin-grant-work - have addressed feedback

Copy link
Contributor

@colin-grant-work colin-grant-work left a comment

Choose a reason for hiding this comment

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

This is working well for me. I was surprised to find that if the ViewContainerPart is the only widget in its ViewContainer, the title bar is not updated:

Only child:

image

With sibling:

image

But it looks like that's the same behavior as in VSCode:

Only child:
image

With sibling:
image

In other contexts, I've remarked that it would be nice to extend Phosphor's Title to handle additional fields not foreseen by Phosphor (pinning, descriptions). There are also two existing fields that we currently treat as more or less interchangeable: label and caption. Arguably, caption could be used for description, but we'd have to check all existing code to ensure we're not relying on caption and label being interchangeable. Unfortunately, extending the Title wouldn't be trivial, as it's assigned in a somewhat eccentric way in Phosphor. I think this PR achieves its objectives effectively given the means available, but I wanted to remark on some of the problem areas that it touches for future reference.

@paul-marechal paul-marechal added this to the 1.18.0 milestone Aug 26, 2021
@westbury westbury merged commit 7442150 into eclipse-theia:master Aug 31, 2021
@westbury westbury deleted the ar/add-vscode-treeview-description branch August 31, 2021 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tree issues related to the tree (ex: tree widget) vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement vscode TreeView description
6 participants