@@ -81,9 +81,10 @@ function! fern#internal#node#children(node, provider, token, ...) abort
8181 if a: node .status is # s: STATUS_NONE
8282 return s: Promise .reject (' leaf node does not have children' )
8383 elseif has_key (a: node .concealed, ' __cache_children' ) && options .cache
84+ " Return a fresh copy of cached children so that status won't be cached
8485 return s: AsyncLambda .map (
8586 \ a: node .concealed.__cache_children,
86- \ { v - > extend ( v , { ' status ' : v .status > 0 } ) },
87+ \ { v - > deepcopy ( v ) },
8788 \)
8889 elseif has_key (a: node .concealed, ' __promise_children' )
8990 return a: node .concealed.__promise_children
@@ -121,7 +122,7 @@ function! fern#internal#node#expand(node, nodes, provider, comparator, token) ab
121122 \. finally ({ - > Profile (' children' ) })
122123 \. then ({ v - > s: sort (v , a: comparator .compare) })
123124 \. finally ({ - > Profile (' sort' ) })
124- \. then ({ v - > s: extend (a: node .__key, a: nodes , v ) })
125+ \. then ({ v - > s: extend (a: node .__key, copy ( a: nodes) , v ) })
125126 \. finally ({ - > Profile (' extend' ) })
126127 \. finally ({ - > Done () })
127128 \. finally ({ - > Profile () })
@@ -203,7 +204,12 @@ function! fern#internal#node#reveal(key, nodes, provider, comparator, token) abo
203204 return s: Promise .resolve (a: nodes )
204205 endif
205206 let l: Profile = fern#profile#start (' fern#internal#node#reveal' )
206- return s: expand_recursively (0 , a: key , a: nodes , a: provider , a: comparator , a: token )
207+ let node = fern#internal#node#find (a: key [:0 ], a: nodes )
208+ if node is # v: null || node.status is # s: STATUS_NONE
209+ return s: Promise .resolve (a: nodes )
210+ endif
211+ return fern#internal#node#collapse (node, a: nodes , a: provider , a: comparator , a: token )
212+ \. then ({ ns - > s: expand_recursively (0 , a: key , ns, a: provider , a: comparator , a: token ) })
207213 \. finally ({ - > Profile () })
208214endfunction
209215
@@ -236,14 +242,13 @@ function! s:extend(key, nodes, new_nodes) abort
236242endfunction
237243
238244function ! s: expand_recursively (index , key , nodes, provider, comparator, token) abort
245+ if a: index >= len (a: key )
246+ return s: Promise .resolve (a: nodes )
247+ endif
239248 let node = fern#internal#node#find (a: key [:a: index ], a: nodes )
240249 if node is # v: null || node.status is # s: STATUS_NONE
241250 return s: Promise .resolve (a: nodes )
242251 endif
243252 return fern#internal#node#expand (node, a: nodes , a: provider , a: comparator , a: token )
244- \. then ({ ns - > s: Lambda .if (
245- \ a: index < len (a: key ) - 1 ,
246- \ { - > s: expand_recursively (a: index + 1 , a: key , ns, a: provider , a: comparator , a: token ) },
247- \ { - > ns },
248- \ )})
253+ \. then ({ ns - > s: expand_recursively (a: index + 1 , a: key , ns, a: provider , a: comparator , a: token ) })
249254endfunction
0 commit comments