mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
separete structure from symbols
This commit is contained in:
parent
49ab441024
commit
2b828c68e8
9 changed files with 131 additions and 39 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<DocumentSymbol> = Vec::new();
|
||||
let mut parents: Vec<(DocumentSymbol, Option<usize>)> = 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)))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue