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 <yusuktan@maguro.dev>
This commit is contained in:
bors[bot] 2020-08-18 11:58:02 +00:00 committed by GitHub
commit 2252a65f23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -272,19 +272,24 @@ pub(crate) fn handle_document_symbol(
parents.push((doc_symbol, symbol.parent));
}
let mut document_symbols = Vec::new();
// Constructs `document_symbols` from `parents`, in order from the end.
while let Some((node, parent)) = parents.pop() {
match parent {
None => document_symbols.push(node),
Some(i) => {
let children = &mut parents[i].0.children;
if children.is_none() {
*children = Some(Vec::new());
}
children.as_mut().unwrap().push(node);
parents[i].0.children.get_or_insert_with(Vec::new).push(node);
}
}
}
fn reverse(symbols: &mut Vec<DocumentSymbol>) {
for sym in symbols.iter_mut() {
sym.children.as_mut().map(|c| reverse(c));
}
symbols.reverse();
}
reverse(&mut document_symbols);
let res = if snap.config.client_caps.hierarchical_symbols {
document_symbols.into()
} else {