aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-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 067259e24..9944757ad 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -273,19 +273,24 @@ pub(crate) fn handle_document_symbol(
273 parents.push((doc_symbol, symbol.parent)); 273 parents.push((doc_symbol, symbol.parent));
274 } 274 }
275 let mut document_symbols = Vec::new(); 275 let mut document_symbols = Vec::new();
276 // Constructs `document_symbols` from `parents`, in order from the end.
276 while let Some((node, parent)) = parents.pop() { 277 while let Some((node, parent)) = parents.pop() {
277 match parent { 278 match parent {
278 None => document_symbols.push(node), 279 None => document_symbols.push(node),
279 Some(i) => { 280 Some(i) => {
280 let children = &mut parents[i].0.children; 281 parents[i].0.children.get_or_insert_with(Vec::new).push(node);
281 if children.is_none() {
282 *children = Some(Vec::new());
283 }
284 children.as_mut().unwrap().push(node);
285 } 282 }
286 } 283 }
287 } 284 }
288 285
286 fn reverse(symbols: &mut Vec<DocumentSymbol>) {
287 for sym in symbols.iter_mut() {
288 sym.children.as_mut().map(|c| reverse(c));
289 }
290 symbols.reverse();
291 }
292 reverse(&mut document_symbols);
293
289 let res = if snap.config.client_caps.hierarchical_symbols { 294 let res = if snap.config.client_caps.hierarchical_symbols {
290 document_symbols.into() 295 document_symbols.into()
291 } else { 296 } else {