Add OutlineItem::depth so that we can render a tree in the outline view

This commit is contained in:
Antonio Scandurra 2022-01-13 11:35:43 +01:00
parent 63a401ac5d
commit ef596c64f8
2 changed files with 11 additions and 1 deletions

View File

@ -1853,8 +1853,9 @@ impl BufferSnapshot {
let context_capture_ix = grammar.outline_query.capture_index_for_name("context")?;
let name_capture_ix = grammar.outline_query.capture_index_for_name("name")?;
let mut stack: Vec<Range<usize>> = Default::default();
let mut id = 0;
let mut items = matches
let items = matches
.filter_map(|mat| {
let item_node = mat.nodes_for_capture_index(item_capture_ix).next()?;
let mut name_node = Some(mat.nodes_for_capture_index(name_capture_ix).next()?);
@ -1899,8 +1900,16 @@ impl BufferSnapshot {
text.extend(self.text_for_range(range));
}
while stack.last().map_or(false, |prev_range| {
!prev_range.contains(&range.start) || !prev_range.contains(&range.end)
}) {
stack.pop();
}
stack.push(range.clone());
Some(OutlineItem {
id,
depth: stack.len() - 1,
range,
text,
name_range_in_text,

View File

@ -6,6 +6,7 @@ pub struct Outline(pub Vec<OutlineItem>);
#[derive(Debug)]
pub struct OutlineItem {
pub id: usize,
pub depth: usize,
pub range: Range<usize>,
pub text: String,
pub name_range_in_text: Range<usize>,