aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-18 13:32:32 +0100
committerGitHub <[email protected]>2020-08-18 13:32:32 +0100
commita3947129c5dc60cf051260c364833946f92e3350 (patch)
treea69f4c1574f8f3ff97d21b4877f6530c979efce3 /crates
parentb8dfc331abbfce6aad0c248c91c57bd9890a668f (diff)
parent0d201638d9c7710795fa24765f7b761432cd5622 (diff)
Merge #5794
5794: Simplify building a symbol hierarchy r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
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 4f77b1b4d..6510e8ccc 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()