import { Command , commands , DocumentSymbol , SymbolInformation , SymbolKind , TextDocument , ThemeIcon , Uri , workspace } from "vscode" ; import { createUuid , sendOperationEnd , sendOperationStart } from "vscode-extension-telemetry-wrapper" ; import { Commands } from "../commands" ; import { Explorer } from "../constants" ; import { INodeData , TypeKind } from "../java/nodeData" ; import { Settings } from "../settings" ; import { isTest } from "../utility" ; import { DataNode } from "./dataNode" ; import { DocumentSymbolNode } from "./documentSymbolNode" ; import { ExplorerNode } from "./explorerNode" ; export class PrimaryTypeNode extends DataNode { public static K_TYPE_KIND = "TypeKind" ; constructor ( nodeData , parent , protected _rootNode ? ) { super ( nodeData , parent ) ; } protected async loadData ( ) { if ( ! this . hasChildren ( ) || ! this . nodeData . uri ) { return undefined ; } return workspace . openTextDocument ( Uri . parse ( this . nodeData . uri ) ) . then ( ( doc ) => { return this . getSymbols ( doc ) ; } ) ; } protected createChildNodeList ( ) { const result = [ ] ; if ( this . nodeData . children && this . nodeData . children . length ) { for ( const child of this . nodeData . children ) { const documentSymbol = child as DocumentSymbol ; if ( documentSymbol . kind === SymbolKind . Package ) { continue ; } if ( documentSymbol . name === this . nodeData . name ) { for ( const childSymbol of documentSymbol . children ) { result . push ( new DocumentSymbolNode ( childSymbol , this ) ) ; } } } } return result ; } protected get iconPath ( ) : string | ThemeIcon { switch ( this . nodeData . metaData ?. [ PrimaryTypeNode . K_TYPE_KIND ] ) { case TypeKind . Enum : return new ThemeIcon ( "symbol-enum" ) ; case TypeKind . Interface : return new ThemeIcon ( "symbol-interface" ) ; default : return new ThemeIcon ( "symbol-class" ) ; } } protected hasChildren ( ) { return Settings . showMembers ( ) ; } private async getSymbols ( document ) { let error ; const operationId = createUuid ( ) ; const startAt = Date . now ( ) ; sendOperationStart ( operationId , "vscode.executeDocumentSymbolProvider" ) ; try { return await commands . executeCommand < SymbolInformation [ ] > ( "vscode.executeDocumentSymbolProvider" , document . uri ) ; } catch ( err ) { error = err ; throw err ; } finally { const duration = Date . now ( ) - startAt ; sendOperationEnd ( operationId , "vscode.executeDocumentSymbolProvider" , duration , error ) ; } } protected get command ( ) : Command { return { title : "Open source file content" , command : Commands . VSCODE_OPEN , arguments : [ Uri . parse ( this . uri || "" ) , { preserveFocus : true } ] , } ; } protected get contextValue ( ) : string { let contextValue = Explorer . ContextValueType . Type ; const type = this . nodeData . metaData ?. [ PrimaryTypeNode . K_TYPE_KIND ] ; if ( type === TypeKind . Enum ) { contextValue += "+enum" ; } else if ( type === TypeKind . Interface ) { contextValue += "+interface" ; } else { contextValue += "+class" ; } if ( isTest ( this . _rootNode ?. nodeData ) ) { contextValue += "+test" ; } return contextValue ; } }