import * as path from "path" ; import { Uri } from "vscode" ; import { DataNode } from "../dataNode" ; import { ExplorerNode } from "../explorerNode" ; import { Trie , TrieNode } from "./Trie" ; class ExplorerNodeCache { private mutableNodeCache : Trie < DataNode > = new Trie ( ) ; public getDataNode ( uri ) { return this . mutableNodeCache . find ( uri . fsPath ) ?. value ; } param uri public findBestMatchNodeByUri ( uri ) { const parentDir = path . dirname ( uri . fsPath ) ; const ancestor = this . mutableNodeCache . findFirstAncestorNodeWithData ( parentDir ) ; return ancestor ?. value ; } public saveNode ( node ) { if ( node instanceof DataNode && node . uri ) { this . mutableNodeCache . insert ( node ) ; } } public saveNodes ( nodes ) { for ( const node of nodes ) { this . saveNode ( node ) ; } } public removeNodeChildren ( node ? ) { if ( ! node ) { this . removeChildren ( this . mutableNodeCache . root ) ; return ; } if ( ! ( node instanceof DataNode ) || ! node . uri ) { return ; } const trieNode = this . mutableNodeCache . find ( Uri . parse ( node . uri ) . fsPath ) ; if ( trieNode ) { this . removeChildren ( trieNode ) ; } } private removeChildren ( trieNode ) { trieNode . children = { } ; if ( trieNode . value ?. nodeData ?. children ) { trieNode . value . nodeData . children = undefined ; } } } export const explorerNodeCache = new ExplorerNodeCache ( ) ;