aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/handlers.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index f8159d0f4..33e60b500 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -271,24 +271,24 @@ pub(crate) fn handle_document_symbol(
271 }; 271 };
272 parents.push((doc_symbol, symbol.parent)); 272 parents.push((doc_symbol, symbol.parent));
273 } 273 }
274 let mut document_symbols = Vec::new();
275 // Constructs `document_symbols` from `parents`, in order from the end.
276 while let Some((node, parent)) = parents.pop() {
277 match parent {
278 None => document_symbols.push(node),
279 Some(i) => {
280 parents[i].0.children.get_or_insert_with(Vec::new).push(node);
281 }
282 }
283 }
284 274
285 fn reverse(symbols: &mut Vec<DocumentSymbol>) { 275 // Builds hierarchy from a flat list, in reverse order (so that indices
286 for sym in symbols.iter_mut() { 276 // makes sense)
287 sym.children.as_mut().map(|c| reverse(c)); 277 let document_symbols = {
278 let mut acc = Vec::new();
279 while let Some((mut node, parent_idx)) = parents.pop() {
280 if let Some(children) = &mut node.children {
281 children.reverse();
282 }
283 let parent = match parent_idx {
284 None => &mut acc,
285 Some(i) => parents[i].0.children.get_or_insert_with(Vec::new),
286 };
287 parent.push(node);
288 } 288 }
289 symbols.reverse(); 289 acc.reverse();
290 } 290 acc
291 reverse(&mut document_symbols); 291 };
292 292
293 let res = if snap.config.client_caps.hierarchical_symbols { 293 let res = if snap.config.client_caps.hierarchical_symbols {
294 document_symbols.into() 294 document_symbols.into()