'How to refresh vscode.TreeDataProvider based TreeView?

the TreeView is initially populated and the TreeView instantiated. the 'refresh' button invokes the custom refresh function to gather updated data. This new information is stored in context.globalState()

The ctmInfrastructureProvider.refresh(); does not update the TreeView. I've added the event listener as well.

export class CtmInfrastructureProvider implements vscode.TreeDataProvider<number> {

    private _onDidChangeTreeData: vscode.EventEmitter<number | null> = new vscode.EventEmitter<number | null>();
    readonly onDidChangeTreeData: vscode.Event<number | null> = this._onDidChangeTreeData.event;
.
.
.
    constructor(private context: vscode.ExtensionContext) {
        let ctmInfrastructureCacheTmp: any = context.globalState.get('ctmInfrastructureCache');
        this.refresh();
    }
.
.
.
}

Here are my refresh functions:

let ctmInfrastructureRefreshEntry = vscode.commands.registerCommand(
        'ctm.infrastructure.refreshEntry',
        async () => {           
ctmInfrastructureDicsovery = discoverCtmInfrastructure();                     context.globalState.update('ctmInfrastructureCache',JSON.parse(ctmInfrastructureDicsovery));
ctmInfrastructureProvider.refresh();
        }
    );
    context.subscriptions.push(ctmInfrastructureRefreshEntry);

The TreeDataProvider refresh()

    refresh(offset?: number): void {
            this.parseTree();
    }
    private parseTree(): void {
        this.text = this.ctmInfrastructureCache;
        this.tree = json.parseTree(this.ctmInfrastructureCache);
    }

What am I missing?



Solution 1:[1]

The refresh is working if the new data is being provided by the function. Example:

    refresh(offset?: number, context?: vscode.ExtensionContext): void {
        this.ctmInfrastructureCache = "some data";
        this.parseTree();
        if (offset) {
            this._onDidChangeTreeData.fire(offset);
        } else {
            this._onDidChangeTreeData.fire(undefined);
        }

    }

Solution 2:[2]

Untested, but can you please try this:

$products = Product::
  whereIn('collection_id', $filter_collections)
->orWhereIn('category_id', $filter_categories)
->get();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Orchestrator
Solution 2 kapitan