From 2b828c68e8acda628d6e3a36827d1ffd9c9aaec6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Aug 2018 11:20:09 +0300 Subject: separete structure from symbols --- crates/server/src/conv.rs | 1 + crates/server/src/main_loop/handlers.rs | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) (limited to 'crates/server') diff --git a/crates/server/src/conv.rs b/crates/server/src/conv.rs index 3aa255e6a..3ddce5fb3 100644 --- a/crates/server/src/conv.rs +++ b/crates/server/src/conv.rs @@ -36,6 +36,7 @@ impl Conv for SyntaxKind { SyntaxKind::TYPE_DEF => SymbolKind::TypeParameter, SyntaxKind::STATIC_DEF => SymbolKind::Constant, SyntaxKind::CONST_DEF => SymbolKind::Constant, + SyntaxKind::IMPL_ITEM => SymbolKind::Object, _ => SymbolKind::Variable, } } diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index bfdfcb51e..8789ef0d2 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs @@ -48,29 +48,34 @@ pub fn handle_document_symbol( let file = world.file_syntax(&path)?; let line_index = world.file_line_index(&path)?; - let mut res: Vec = Vec::new(); + let mut parents: Vec<(DocumentSymbol, Option)> = Vec::new(); - for symbol in libeditor::file_symbols(&file) { - let name = symbol.name.to_string(); + for symbol in libeditor::file_structure(&file) { let doc_symbol = DocumentSymbol { - name: name.clone(), - detail: Some(name), + name: symbol.label, + detail: Some("".to_string()), kind: symbol.kind.conv(), deprecated: None, range: symbol.node_range.conv_with(&line_index), - selection_range: symbol.name_range.conv_with(&line_index), + selection_range: symbol.navigation_range.conv_with(&line_index), children: None, }; - if let Some(idx) = symbol.parent { - let children = &mut res[idx].children; - if children.is_none() { - *children = Some(Vec::new()); + parents.push((doc_symbol, symbol.parent)); + } + let mut res = Vec::new(); + while let Some((node, parent)) = parents.pop() { + match parent { + None => res.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); } - children.as_mut().unwrap().push(doc_symbol); - } else { - res.push(doc_symbol); } } + Ok(Some(req::DocumentSymbolResponse::Nested(res))) } -- cgit v1.2.3