mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 05:15:00 +00:00
Add OutlineItem::depth so that we can render a tree in the outline view
This commit is contained in:
parent
63a401ac5d
commit
ef596c64f8
2 changed files with 11 additions and 1 deletions
|
@ -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,
|
||||
|
|
|
@ -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>,
|
||||
|
|
Loading…
Reference in a new issue