module author Amir Marcel, Christopher Johnson, Corey Van Splinter, Sean Arseneault
 *  date description import * as vscode from 'vscode' ; import * as path from 'path' ; let masterDataObject ; export default class ReverbTreeProvider implements vscode . TreeDataProvider < RouteItem | PathItem | RootItem > { tree : any ; constructor ( private workspaceRoot , workspaceObj ) { masterDataObject = workspaceObj ; } getTreeItem ( element ) { return element ; } getChildren ( element ? ) { if ( ! this . workspaceRoot ) { vscode . window . showInformationMessage ( 'No path in empty workspace' ) ; return Promise . resolve ( [ ] ) ; } if ( masterDataObject === undefined ) { vscode . window . showInformationMessage ( 'No route data exists' ) ; return Promise . resolve ( [ ] ) ; } if ( element ?. contextValue === 'pathItem' ) { return Promise . resolve ( this . getRoutes ( element ) ) ; } if ( element ?. contextValue === 'rootItem' ) { return Promise . resolve ( this . getPaths ( ) ) ; } return Promise . resolve ( [ new RootItem ( `${ vscode . workspace . workspaceFolders ! [ 0 ] . name }/` , this . workspaceRoot , vscode . TreeItemCollapsibleState . Expanded ) , ] ) ; } private getRoutes ( { filePath , serverPath , href } ) { if ( masterDataObject === undefined ) return ; const output = [ ] ; for ( const item in masterDataObject . domains [ serverPath ] . paths [ filePath ] ) { const route = masterDataObject . domains [ serverPath ] . paths [ filePath ] [ item ] ; const name = `${ route . pathname }` ; const uri = href ; const { method } = route ; console . log ( route ) ; const { range } = route ; output . push ( new RouteItem ( name , filePath , method , uri , range , vscode . TreeItemCollapsibleState . None ) ) ; } return output ; } private getPaths ( ) { if ( masterDataObject === undefined ) return ; const output = [ ] ; const dirName = vscode . workspace . workspaceFolders ! [ 0 ] . name ; const cache = { } ; for ( const domain in masterDataObject . domains ) { for ( const itemPath in masterDataObject . domains [ domain ] . urls ) { const { filePath } = masterDataObject . domains [ domain ] . urls [ itemPath ] ; const { serverPath } = masterDataObject . domains [ domain ] . urls [ itemPath ] ; const { href } = masterDataObject . domains [ domain ] . urls [ itemPath ] ; const substr = filePath . slice ( Math . max ( 0 , filePath . indexOf ( dirName ) + dirName . length + 1 ) ) ; if ( ! cache [ substr ] ) { output . push ( new PathItem ( substr , filePath , serverPath , href , vscode . TreeItemCollapsibleState . Collapsed ) ) ; cache [ substr ] = true ; } } } return output ; } } class PathItem extends vscode . TreeItem { constructor ( public readonly label , public readonly filePath , public readonly serverPath , public readonly href , public readonly collapsibleState ) { super ( label , collapsibleState ) ; this . tooltip = this . label ; this . description = '' ; } iconPath = { light : path . join ( __filename , '..' , '..' , 'resources' , 'light' , 'folder.svg' ) , dark : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'http.svg' ) , } ; contextValue = 'pathItem' ; } class RouteItem extends vscode . TreeItem { constructor ( public readonly label , public readonly filePath , public readonly method , public readonly uri , public readonly range , public readonly collapsibleState ) { super ( label , collapsibleState ) ; this . tooltip = `${ this . method }: ${ this . uri }` ; this . description = '' ; } methodLabeler ( x ) { switch ( true ) { case x === 'get' : return { light : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'GET.svg' ) , dark : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'GET.svg' ) , } ; case x === 'put' : return { light : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'PUT.svg' ) , dark : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'PUT.svg' ) , } ; case x === 'post' : return { light : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'POST.svg' ) , dark : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'POST.svg' ) , } ; case x === 'delete' : return { light : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'DELETE.svg' ) , dark : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'DELETE.svg' ) , } ; default : return { light : path . join ( __filename , '..' , '..' , 'resources' , 'light' , 'folder.svg' ) , dark : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'http.svg' ) , } ; } } iconPath = this . methodLabeler ( this . method ) ; contextValue = 'routeItem' ; } class RootItem extends vscode . TreeItem { constructor ( public readonly label , public readonly uri , public readonly collapsibleState ) { super ( label , collapsibleState ) ; this . tooltip = this . label ; this . description = '' ; } iconPath = { light : path . join ( __filename , '..' , '..' , 'resources' , 'light' , 'folder.svg' ) , dark : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'folder.svg' ) , } ; contextValue = 'rootItem' ; }