diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-08-18 12:58:02 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-18 12:58:02 +0100 |
commit | 2252a65f238cac0ebf0c4c56d9b475fa0460d758 (patch) | |
tree | cd9f08481a2f5bad16c16c2232c79c780f004623 /crates | |
parent | 5dfb1e054aa5ab0636e6a0ff5e2bbf297a24869a (diff) | |
parent | e8e1eb4263d5bcf109550432143dd54de9f64946 (diff) |
Merge #5687
5687: Fix document symbols order r=matklad a=magurotuna
Resolves #5655
And adds tests for `handle_document_symbol`, both with `hierarchical_symbols` enabled and with it disabled.
Previously document symbols were displayed in reverse order in sublime text with its LSP plugin, but this patch fixes it like this:
![image](https://user-images.githubusercontent.com/23649474/89709020-fbccce00-d9b6-11ea-83b0-c88dc9f7977f.png)
Co-authored-by: Yusuke Tanaka <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 15 |
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 { |