'use strict' ; import * as vscode from 'vscode' ; import { ReferencesModel , TreeNode , NodeType } from './referencesModel' ; import { ReferenceType , getReferenceTagString , getReferenceItemIconPath } from './references' ; import * as nls from 'vscode-nls' ; nls . config ( { messageFormat : nls . MessageFormat . bundle , bundleFormat : nls . BundleFormat . standalone } ) ( ) ; const localize = nls . loadMessageBundle ( ) ; export class ReferencesTreeDataProvider implements vscode . TreeDataProvider < TreeNode > { private referencesModel : ReferencesModel | undefined ; private readonly _onDidChangeTreeData = new vscode . EventEmitter < void > ( ) ; readonly onDidChangeTreeData : vscode . Event < void > ; constructor ( ) { this . onDidChangeTreeData = this . _onDidChangeTreeData . event ; } refresh ( ) { if ( this . referencesModel ) { vscode . commands . executeCommand ( 'setContext' , 'refView.isGroupedByFile' , this . referencesModel . groupByFile ) ; this . _onDidChangeTreeData . fire ( ) ; } } setModel ( model ) { this . referencesModel = model ; vscode . commands . executeCommand ( 'setContext' , 'refView.isGroupedByFile' , this . referencesModel . groupByFile ) ; this . _onDidChangeTreeData . fire ( ) ; } clear ( ) { this . referencesModel = undefined ; this . _onDidChangeTreeData . fire ( ) ; } getTreeItem ( element ) { if ( this . referencesModel === undefined ) { throw new Error ( "Undefined RefrencesModel in getTreeItem()" ) ; } switch ( element . node ) { case NodeType . referenceType : if ( element . referenceType === undefined ) { throw new Error ( "Undefined referenceType in getTreeItem()" ) ; } const label = getReferenceTagString ( element . referenceType , this . referencesModel . isCanceled , true ) ; const resultRefType = new vscode . TreeItem ( label , vscode . TreeItemCollapsibleState . Expanded ) ; return resultRefType ; case NodeType . file : case NodeType . fileWithPendingRef : if ( element . fileUri === undefined ) { throw new Error ( "Undefined fileUri in getTreeItem()" ) ; } const resultFile = new vscode . TreeItem ( element . fileUri ) ; resultFile . collapsibleState = vscode . TreeItemCollapsibleState . Expanded ; resultFile . iconPath = vscode . ThemeIcon . File ; resultFile . description = true ; if ( element . node === NodeType . fileWithPendingRef ) { resultFile . command = { title : localize ( "goto.reference" , "Go to reference" ) , command : 'C_Cpp.ShowReferenceItem' , arguments : [ element ] } ; const tag = getReferenceTagString ( ReferenceType . ConfirmationInProgress , this . referencesModel . isCanceled ) ; resultFile . tooltip = `[${ tag }]\n${ element . filename }` ; resultFile . collapsibleState = vscode . TreeItemCollapsibleState . None ; } return resultFile ; case NodeType . reference : if ( element . referenceText === undefined ) { throw new Error ( "Undefined referenceText in getTreeItem()" ) ; } if ( element . referenceType === undefined ) { throw new Error ( "Undefined referenceType in getTreeItem()" ) ; } const resultRef = new vscode . TreeItem ( element . referenceText , vscode . TreeItemCollapsibleState . None ) ; resultRef . iconPath = getReferenceItemIconPath ( element . referenceType , this . referencesModel . isCanceled ) ; const tag = getReferenceTagString ( element . referenceType , this . referencesModel . isCanceled ) ; resultRef . tooltip = `[${ tag }]\n${ element . referenceText }` ; resultRef . command = { title : localize ( "goto.reference" , "Go to reference" ) , command : 'C_Cpp.ShowReferenceItem' , arguments : [ element ] } ; return resultRef ; } throw new Error ( "Invalid NoteType in getTreeItem()" ) ; } getChildren ( element ? ) { if ( ! this . referencesModel ) { return undefined ; } if ( element instanceof TreeNode ) { if ( element . node === NodeType . file ) { let type ; if ( ! this . referencesModel . groupByFile ) { type = element . referenceType ; } return this . referencesModel . getReferenceNodes ( element . filename , type ) ; } if ( element . node === NodeType . referenceType ) { return this . referencesModel . getFileNodes ( element . referenceType ) ; } } if ( this . referencesModel . groupByFile ) { return this . referencesModel . getFileNodes ( ) ; } else { return this . referencesModel . getReferenceTypeNodes ( ) ; } } }