import * as vscode from 'vscode' ; import { PackageTreeItem } from './model/PackageTreeItem' ; import { BlockchainExplorerProvider } from './BlockchainExplorerProvider' ; import { PackageRegistry } from '../registries/PackageRegistry' ; import { PackageRegistryEntry } from '../registries/PackageRegistryEntry' ; import { BlockchainTreeItem } from './model/BlockchainTreeItem' ; import { TextTreeItem } from './model/TextTreeItem' ; import { UserInputUtil } from '../commands/UserInputUtil' ; export class BlockchainPackageExplorerProvider implements BlockchainExplorerProvider { public tree : Array < BlockchainTreeItem > = [ ] ; private _onDidChangeTreeData : vscode . EventEmitter < any | undefined > = new vscode . EventEmitter < any | undefined > ( ) ; readonly onDidChangeTreeData : vscode . Event < any | undefined > = this . _onDidChangeTreeData . event ; getTreeItem ( element ) { return element ; } async getChildren ( ) { const packageArray = await PackageRegistry . instance ( ) . getAll ( ) ; this . tree = await this . createPackageTree ( packageArray ) ; return this . tree ; } async refresh ( ) { this . _onDidChangeTreeData . fire ( ) ; } private async createPackageTree ( packageRegistryEntries ) { const tree = [ ] ; if ( packageRegistryEntries . length === 0 ) { tree . push ( new TextTreeItem ( this , 'No packages found' ) ) ; } else { for ( const packageRegistryEntry of packageRegistryEntries ) { const { name , version , path : filePath } = packageRegistryEntry ; const ext = UserInputUtil . getPackageFileExtension ( filePath ) ; const nameAndVersion = version ? `${ name }@${ version }` : `${ name }` ; tree . push ( new PackageTreeItem ( this , nameAndVersion , ext , packageRegistryEntry ) ) ; } } return tree ; } }