Skip to content

Conversation

JadenSimon
Copy link
Contributor

Problem

While prototyping features, I kept running into the situation where I wanted to update how a node was rendered independently of the node's children. The current implementation does not easily support this use-case, forcing us to propagate events up to a parent node to get the desired behavior.

Solution

Fully generalize the TreeNode interface. It was already very close to the general solution, it just needed a few tweaks to get it there. Of course, implementing this correctly with a tree data provider required more substantial changes which tests were added for.

I wouldn't recommend that all tree node implementations use this pattern because it can quickly spiral out of control from a maintainability point of view. Still, I'd rather have the proper solution readily available than a bunch of one-off bespoke solutions.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@JadenSimon JadenSimon requested a review from a team as a code owner July 28, 2022 23:27
* Any new or existing code needs to account for this additional layer as the shim
* would be passed in as-is.
*/
export class TreeShim extends AWSTreeNodeBase {
Copy link
Contributor Author

@JadenSimon JadenSimon Jul 28, 2022

Choose a reason for hiding this comment

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

The shim was updated to support this new functionality. It's not a perfect recreation because TreeNode can handle async rendering of the node itself while the shim would show Loading... on initialization.

id: 'placeholder',
resource: message,
treeItem: new vscode.TreeItem(message, vscode.TreeItemCollapsibleState.None),
getTreeItem: () => new vscode.TreeItem(message, vscode.TreeItemCollapsibleState.None),
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 don't like turning otherwise constant things into functions but it was kind of necessary for this functionality.
It makes things harder to test and reason about :/

const recordExpandCdkOnce = once(telemetry.recordCdkAppExpanded)
view.onDidExpandElement(e => {
if (e.element.resource instanceof AppNode) {
if (e.element.resource instanceof CdkRootNode) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Metric was being recorded when the child node expanded rather than the parent (my bad).

Copy link
Contributor

@justinmk3 justinmk3 left a comment

Choose a reason for hiding this comment

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

great!

@JadenSimon JadenSimon merged commit d8acc5b into master Aug 5, 2022
@JadenSimon JadenSimon deleted the sijaden/more-node-decoupling branch August 5, 2022 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants