1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// #[cfg(feature = "lsp")]
// use crate::utils::lsp_info::Range;
// use crate::{nodes::ASTKind, utils::LSPMetaInfo, ASTNode};
// use std::fmt::{Debug, Display};
//
// #[derive(Debug)]
// pub struct TOC {
// pub level: usize,
// pub detail: String,
// #[cfg(feature = "lsp")]
// pub range: Range,
// pub children: Vec<TOC>,
// }
//
// impl Default for TOC {
// fn default() -> Self {
// Self { level: 0, detail: String::from("ROOT"), range: Default::default(), children: vec![] }
// }
// }
//
// impl TOC {
// fn last_at_level(&mut self, depth: usize) -> &mut TOC {
// if depth == 0 || self.children.len() == 0 { self } else { self.children.last_mut().unwrap().last_at_level(depth - 1) }
// }
// }
//
// impl ASTNode<LSPMetaInfo> {
// pub fn toc(&self, max_depth: usize) -> TOC {
// let mut root = TOC::default();
// let mut toc_ignore = false;
// if let ASTKind::Statements(terms) = &self.kind {
// for term in terms {
// match &self.kind {
// ASTKind::Header(header) => {
// let level = header.level;
// if toc_ignore {
// toc_ignore = false;
// continue;
// }
// if level > max_depth {
// continue;
// }
// let parent = root.last_at_level(level - 1);
// let new = TOC {
// level,
// detail: unimplemented!(),
// #[cfg(feature = "lsp")]
// range: term.range,
// children: vec![],
// };
// parent.children.push(new);
// }
// ASTKind::Command(cmd) => {
// if cmd.is("toc_ignore") {
// toc_ignore = true
// }
// }
// _ => (),
// }
// }
// }
// return root;
// }
// }
//
// pub fn join_ast_list<M>(list: &[ASTNode<M>]) -> String
// where
// ASTNode<M>: Display,
// {
// let mut out = String::new();
// for i in list {
// out.push_str(&i.to_string())
// }
// return out;
// }