import * as vscode from 'vscode' ; import { ERROR_MESSAGE_COMMAND } from './extension' ; /**
 * Test tree view as shown in treeview sample extension available at
 * https://github.com/microsoft/vscode-extension-samples/tree/master/tree-view-sample
 */ export class TreeView { constructor ( context ) { const view = vscode . window . createTreeView ( 'testView' , { treeDataProvider : dataProvider ( ) , showCollapseAll : true } ) ; context . subscriptions . push ( view ) ; } } type Tree = { [ key ] : Tree | undefined | null ; } ; const tree = { 'a' : { 'aa' : { 'aaa' : { 'aaaa' : { 'aaaaa' : { 'aaaaaa' : undefined , } } } } , 'ab' : undefined , } , 'b' : { 'ba' : undefined , 'bb' : undefined } , 'c' : null , 'd' : { 'da' : undefined , 'db' : undefined } } ; let nodes = { } ; function dataProvider ( ) { return { getChildren : ( element ? ) : { key : string ; } [ ] => { return getChildren ( element ?. key ) . map ( ( key ) => getNode ( key ) ) ; } , getTreeItem : ( element ) : vscode . TreeItem => { const treeItem = getTreeItem ( element . key ) ; treeItem . id = element . key ; if ( element . key === "d" ) { treeItem . command = { title : "show an error" , command : ERROR_MESSAGE_COMMAND } ; } return treeItem ; } , getParent : ( { key } ) : { key : string ; } => { const parentKey = key . substring ( 0 , key . length - 1 ) ; return new Key ( parentKey ) ; } } ; } function getChildren ( key ) { if ( ! key ) { return Object . keys ( tree ) ; } let treeElement = getTreeElement ( key ) ; if ( treeElement ) { return Object . keys ( treeElement ) ; } return [ ] ; } function getTreeItem ( key ) { const treeElement = getTreeElement ( key ) ; let collapsibleState ; if ( treeElement === undefined ) { collapsibleState = vscode . TreeItemCollapsibleState . None ; } else { collapsibleState = vscode . TreeItemCollapsibleState . Collapsed ; } return { label : key , tooltip : `Tooltip for ${ key }` , description : `Description for ${ key }` , collapsibleState } ; } function getTreeElement ( element ) { let parent = tree ; for ( let i = 0 ; i < element . length ; i ++ ) { parent = parent [ element . substring ( 0 , i + 1 ) ] ; if ( parent === null || parent === undefined ) { return parent ; } } return parent ; } function getNode ( key ) { if ( ! nodes [ key ] ) { nodes [ key ] = new Key ( key ) ; } return nodes [ key ] ; } class Key { constructor ( readonly key ) { } }