aboutsummaryrefslogtreecommitdiff
path: root/crates/server
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-14 09:20:09 +0100
committerAleksey Kladov <[email protected]>2018-08-14 09:20:09 +0100
commit2b828c68e8acda628d6e3a36827d1ffd9c9aaec6 (patch)
treee63ec3bb469eaaf996bbc45c038e66395c04ed23 /crates/server
parent49ab44102496ac8c4a05b00c584adecf583f4d87 (diff)
separete structure from symbols
Diffstat (limited to 'crates/server')
-rw-r--r--crates/server/src/conv.rs1
-rw-r--r--crates/server/src/main_loop/handlers.rs31
2 files changed, 19 insertions, 13 deletions
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 {
36 SyntaxKind::TYPE_DEF => SymbolKind::TypeParameter, 36 SyntaxKind::TYPE_DEF => SymbolKind::TypeParameter,
37 SyntaxKind::STATIC_DEF => SymbolKind::Constant, 37 SyntaxKind::STATIC_DEF => SymbolKind::Constant,
38 SyntaxKind::CONST_DEF => SymbolKind::Constant, 38 SyntaxKind::CONST_DEF => SymbolKind::Constant,
39 SyntaxKind::IMPL_ITEM => SymbolKind::Object,
39 _ => SymbolKind::Variable, 40 _ => SymbolKind::Variable,
40 } 41 }
41 } 42 }
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(
48 let file = world.file_syntax(&path)?; 48 let file = world.file_syntax(&path)?;
49 let line_index = world.file_line_index(&path)?; 49 let line_index = world.file_line_index(&path)?;
50 50
51 let mut res: Vec<DocumentSymbol> = Vec::new(); 51 let mut parents: Vec<(DocumentSymbol, Option<usize>)> = Vec::new();
52 52
53 for symbol in libeditor::file_symbols(&file) { 53 for symbol in libeditor::file_structure(&file) {
54 let name = symbol.name.to_string();
55 let doc_symbol = DocumentSymbol { 54 let doc_symbol = DocumentSymbol {
56 name: name.clone(), 55 name: symbol.label,
57 detail: Some(name), 56 detail: Some("".to_string()),
58 kind: symbol.kind.conv(), 57 kind: symbol.kind.conv(),
59 deprecated: None, 58 deprecated: None,
60 range: symbol.node_range.conv_with(&line_index), 59 range: symbol.node_range.conv_with(&line_index),
61 selection_range: symbol.name_range.conv_with(&line_index), 60 selection_range: symbol.navigation_range.conv_with(&line_index),
62 children: None, 61 children: None,
63 }; 62 };
64 if let Some(idx) = symbol.parent { 63 parents.push((doc_symbol, symbol.parent));
65 let children = &mut res[idx].children; 64 }
66 if children.is_none() { 65 let mut res = Vec::new();
67 *children = Some(Vec::new()); 66 while let Some((node, parent)) = parents.pop() {
67 match parent {
68 None => res.push(node),
69 Some(i) => {
70 let children = &mut parents[i].0.children;
71 if children.is_none() {
72 *children = Some(Vec::new());
73 }
74 children.as_mut().unwrap().push(node);
68 } 75 }
69 children.as_mut().unwrap().push(doc_symbol);
70 } else {
71 res.push(doc_symbol);
72 } 76 }
73 } 77 }
78
74 Ok(Some(req::DocumentSymbolResponse::Nested(res))) 79 Ok(Some(req::DocumentSymbolResponse::Nested(res)))
75} 80}
76 81