aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/handlers.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index e05ffc768..096127b0c 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -272,19 +272,24 @@ pub(crate) fn handle_document_symbol(
272 parents.push((doc_symbol, symbol.parent)); 272 parents.push((doc_symbol, symbol.parent));
273 } 273 }
274 let mut document_symbols = Vec::new(); 274 let mut document_symbols = Vec::new();
275 // Constructs `document_symbols` from `parents`, in order from the end.
275 while let Some((node, parent)) = parents.pop() { 276 while let Some((node, parent)) = parents.pop() {
276 match parent { 277 match parent {
277 None => document_symbols.push(node), 278 None => document_symbols.push(node),
278 Some(i) => { 279 Some(i) => {
279 let children = &mut parents[i].0.children; 280 parents[i].0.children.get_or_insert_with(Vec::new).push(node);
280 if children.is_none() {
281 *children = Some(Vec::new());
282 }
283 children.as_mut().unwrap().push(node);
284 } 281 }
285 } 282 }
286 } 283 }
287 284
285 fn reverse(symbols: &mut Vec<DocumentSymbol>) {
286 for sym in symbols.iter_mut() {
287 sym.children.as_mut().map(|c| reverse(c));
288 }
289 symbols.reverse();
290 }
291 reverse(&mut document_symbols);
292
288 let res = if snap.config.client_caps.hierarchical_symbols { 293 let res = if snap.config.client_caps.hierarchical_symbols {
289 document_symbols.into() 294 document_symbols.into()
290 } else { 295 } else {