Skip to content

Custom view onDidChangeTreeData event doesn't refresh label #78222

Closed

Description

@ejizba

Issue Type: Bug

Repro steps:

  1. Clone ej/treeBug2 branch from this repo (Or see below sample code): https://github.com/EricJizbaMSFT/helloworldext/tree/ej/treeBug2
  2. F5 the extension and open the custom view with the beaker icon
  3. Right click on '0' node and select "incrementAndRefresh"
    Screen Shot 2019-07-30 at 2 34 31 PM

Expected:

The label now shows 1. (This is what happens on VS Code stable v1.36.1)

Actual:

The label still shows 0. However, if I right click "refreshWholeTree" it will update correctly.

More details

This bug was originally for the azure functions extension (see microsoft/vscode-azurefunctions#1375), but I tried to create a simple example. It seems like the label is no longer updated when you pass an object to _onDidChangeTreeData.fire that has an id.

Sample code:

'use strict';

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
    const tree = new HelloWorldTree();
    context.subscriptions.push(vscode.commands.registerCommand('extension.incrementAndRefresh', async (node: Node) => {
        node.counter += 1;
        tree._onDidChangeTreeData.fire(node);
    }));

    context.subscriptions.push(vscode.commands.registerCommand('extension.refreshWholeTree', async (node: Node) => {
        tree._onDidChangeTreeData.fire();
    }));

    context.subscriptions.push(vscode.window.registerTreeDataProvider('helloworldtree1', tree));
}

export function deactivate() {
}

class HelloWorldTree implements vscode.TreeDataProvider<Node> {
    _onDidChangeTreeData: vscode.EventEmitter<Node> = new vscode.EventEmitter<Node>();
    onDidChangeTreeData: vscode.Event<Node> = this._onDidChangeTreeData.event;

    node1: Node = new Node('1');

    getTreeItem(element: Node): vscode.TreeItem {
        return element;
    }

    async getChildren(element?: Node | undefined): Promise<Node[]> {
        return [this.node1];
    }
}

class Node implements vscode.TreeItem {
    public counter: number = 0;

    constructor(public id: string) { }

    get label(): string {
        return this.counter.toString();
    }
}

VS Code version: Code - Insiders 1.37.0-insider (cf03ea3, 2019-07-30T07:10:53.695Z)
OS version: Darwin x64 18.7.0

System Info
Item Value
CPUs Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz (12 x 2600)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: enabled
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_deferred_display_list: disabled_off
skia_renderer: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 3, 2, 2
Memory (System) 16.00GB (4.08GB free)
Process Argv .
Screen Reader no
VM 0%
Extensions (13)
Extension Author (truncated) Version
azurerm-vscode-tools ms- 0.6.1
vscode-azureappservice ms- 0.15.0
python ms- 2019.6.24221
remote-containers ms- 0.67.0
remote-ssh ms- 0.44.2
remote-ssh-edit ms- 0.44.2
remote-ssh-explorer ms- 0.44.2
azure-account ms- 0.8.4
csharp ms- 1.21.0
vscode-typescript-tslint-plugin ms- 1.2.2
java red 0.47.0
sort-lines Tyr 1.8.0
vscode-java-debug vsc 0.20.0

Activity

  1. alexr00 commented on Jul 31, 2019

    @alexr00
    Member

    Thank you for the easy to use sample! I could repro with the version you're on. This is fixed with 3b6c226.

  2. added this to the July 2019 milestone on Jul 31, 2019
  3. added
    bug
    tree-views
    on Jul 31, 2019
  4. ejizba commented on Jul 31, 2019

    @ejizba
    Author

    Looks good now, thanks!

  5. locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugtree-viewsverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions