@@ -106,6 +106,19 @@ function! fern#internal#node#children(node, provider, token, ...) abort
106106 return p
107107endfunction
108108
109+ function ! fern#internal#node#descendants (node, provider, token, ... ) abort
110+ let options = extend ({
111+ \ ' cache' : 1 ,
112+ \} , a: 0 ? a: 1 : {})
113+ if a: node .status is # s: STATUS_NONE
114+ return s: Promise .resolve ([])
115+ endif
116+ return fern#internal#node#children (a: node , a: provider , a: token , options )
117+ \. then (s: Lambda .map_f ({ n - > fern#internal#node#descendants (n , a: provider , a: token , options ).then ({ ns - > extend ([n ], ns) }) }))
118+ \. then ({ ps - > s: Promise .all (ps ) })
119+ \. then (s: Lambda .reduce_f ({ a , ns - > extend (a , ns) }, []))
120+ endfunction
121+
109122function ! fern#internal#node#expand (node, nodes, provider, comparator, token) abort
110123 if a: node .status is # s: STATUS_NONE
111124 return s: Promise .reject (' cannot expand leaf node' )
@@ -132,6 +145,36 @@ function! fern#internal#node#expand(node, nodes, provider, comparator, token) ab
132145 return p
133146endfunction
134147
148+ function ! fern#internal#node#expand_tree (node, nodes, provider, comparator, token) abort
149+ if a: node .status is # s: STATUS_NONE
150+ return s: Promise .reject (' cannot expand leaf node' )
151+ elseif a: node .status is # s: STATUS_EXPANDED
152+ " Collpase first to avoid duplication
153+ return fern#internal#node#collapse (a: node , a: nodes , a: provider , a: comparator , a: token )
154+ \. then ({ ns - > fern#internal#node#expand_tree (a: node , ns, a: provider , a: comparator , a: token ) })
155+ elseif has_key (a: node .concealed, ' __promise_expand' )
156+ return a: node .concealed.__promise_expand
157+ elseif has_key (a: node , ' concealed.__promise_collapse' )
158+ return a: node .concealed.__promise_collapse
159+ endif
160+ let l: Profile = fern#profile#start (' fern#internal#node#expand_tree' )
161+ let l: Done = fern#internal#node#process (a: node )
162+ let p = fern#internal#node#descendants (a: node , a: provider , a: token )
163+ \. finally ({ - > Profile (' descendants' ) })
164+ \. then ({ v - > s: sort (v , a: comparator .compare) })
165+ \. finally ({ - > Profile (' sort' ) })
166+ \. then (s: Lambda .map_f ({ n - > n .status isnot # s: STATUS_NONE ? extend (n , {' status' : s: STATUS_EXPANDED }) : n }))
167+ \. finally ({ - > Profile (' expand' ) })
168+ \. then ({ v - > s: extend (a: node .__key, copy (a: nodes ), v ) })
169+ \. finally ({ - > Profile (' extend' ) })
170+ \. finally ({ - > Done () })
171+ \. finally ({ - > Profile () })
172+ call p .then ({ - > s: Lambda .let (a: node , ' status' , s: STATUS_EXPANDED ) })
173+ let a: node .concealed.__promise_expand = p
174+ \. finally ({ - > s: Lambda .unlet (a: node .concealed, ' __promise_expand' ) })
175+ return p
176+ endfunction
177+
135178function ! fern#internal#node#collapse (node, nodes, provider, comparator, token) abort
136179 if a: node .status is # s: STATUS_NONE
137180 return s: Promise .reject (' cannot collapse leaf node' )
0 commit comments