1use smol_str::SmolStr;
2use text_size::TextRange;
3
4use crate::DocumentAst;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct NamespaceSymbol {
8 pub name: SmolStr,
9 pub range: TextRange,
10}
11
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub struct TaskSymbol {
14 pub name: SmolStr,
15 pub range: TextRange,
16}
17
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct SymbolIndex {
20 pub namespaces: Vec<NamespaceSymbol>,
21 pub tasks: Vec<TaskSymbol>,
22}
23
24pub(crate) fn build_symbol_index(document: &DocumentAst) -> SymbolIndex {
25 let mut symbols = SymbolIndex::default();
26
27 for namespace in &document.namespaces {
28 symbols.namespaces.push(NamespaceSymbol {
29 name: namespace.name.clone(),
30 range: namespace.range,
31 });
32 }
33
34 for task in &document.tasks {
35 symbols.tasks.push(TaskSymbol {
36 name: task.qualified_name(),
37 range: task.range,
38 });
39 }
40
41 symbols
42}