Remove unnecessary Option from functions querying buffer outline (#37935)
`None` case wasn't being used Release Notes: - N/A
This commit is contained in:
@@ -3701,9 +3701,8 @@ impl BufferSnapshot {
|
||||
///
|
||||
/// This method allows passing an optional [`SyntaxTheme`] to
|
||||
/// syntax-highlight the returned symbols.
|
||||
pub fn outline(&self, theme: Option<&SyntaxTheme>) -> Option<Outline<Anchor>> {
|
||||
self.outline_items_containing(0..self.len(), true, theme)
|
||||
.map(Outline::new)
|
||||
pub fn outline(&self, theme: Option<&SyntaxTheme>) -> Outline<Anchor> {
|
||||
Outline::new(self.outline_items_containing(0..self.len(), true, theme))
|
||||
}
|
||||
|
||||
/// Returns all the symbols that contain the given position.
|
||||
@@ -3714,20 +3713,20 @@ impl BufferSnapshot {
|
||||
&self,
|
||||
position: T,
|
||||
theme: Option<&SyntaxTheme>,
|
||||
) -> Option<Vec<OutlineItem<Anchor>>> {
|
||||
) -> Vec<OutlineItem<Anchor>> {
|
||||
let position = position.to_offset(self);
|
||||
let mut items = self.outline_items_containing(
|
||||
position.saturating_sub(1)..self.len().min(position + 1),
|
||||
false,
|
||||
theme,
|
||||
)?;
|
||||
);
|
||||
let mut prev_depth = None;
|
||||
items.retain(|item| {
|
||||
let result = prev_depth.is_none_or(|prev_depth| item.depth > prev_depth);
|
||||
prev_depth = Some(item.depth);
|
||||
result
|
||||
});
|
||||
Some(items)
|
||||
items
|
||||
}
|
||||
|
||||
pub fn outline_range_containing<T: ToOffset>(&self, range: Range<T>) -> Option<Range<Point>> {
|
||||
@@ -3777,21 +3776,19 @@ impl BufferSnapshot {
|
||||
range: Range<T>,
|
||||
include_extra_context: bool,
|
||||
theme: Option<&SyntaxTheme>,
|
||||
) -> Option<Vec<OutlineItem<Anchor>>> {
|
||||
) -> Vec<OutlineItem<Anchor>> {
|
||||
let range = range.to_offset(self);
|
||||
let mut matches = self.syntax.matches(range.clone(), &self.text, |grammar| {
|
||||
grammar.outline_config.as_ref().map(|c| &c.query)
|
||||
});
|
||||
let configs = matches
|
||||
.grammars()
|
||||
.iter()
|
||||
.map(|g| g.outline_config.as_ref().unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut items = Vec::new();
|
||||
let mut annotation_row_ranges: Vec<Range<u32>> = Vec::new();
|
||||
while let Some(mat) = matches.peek() {
|
||||
let config = &configs[mat.grammar_index];
|
||||
let config = matches.grammars()[mat.grammar_index]
|
||||
.outline_config
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
if let Some(item) =
|
||||
self.next_outline_item(config, &mat, &range, include_extra_context, theme)
|
||||
{
|
||||
@@ -3870,7 +3867,7 @@ impl BufferSnapshot {
|
||||
item_ends_stack.push(item.range.end);
|
||||
}
|
||||
|
||||
Some(anchor_items)
|
||||
anchor_items
|
||||
}
|
||||
|
||||
fn next_outline_item(
|
||||
|
||||
@@ -779,9 +779,7 @@ async fn test_outline(cx: &mut gpui::TestAppContext) {
|
||||
.unindent();
|
||||
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let outline = buffer
|
||||
.update(cx, |buffer, _| buffer.snapshot().outline(None))
|
||||
.unwrap();
|
||||
let outline = buffer.update(cx, |buffer, _| buffer.snapshot().outline(None));
|
||||
|
||||
assert_eq!(
|
||||
outline
|
||||
@@ -863,9 +861,7 @@ async fn test_outline_nodes_with_newlines(cx: &mut gpui::TestAppContext) {
|
||||
.unindent();
|
||||
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let outline = buffer
|
||||
.update(cx, |buffer, _| buffer.snapshot().outline(None))
|
||||
.unwrap();
|
||||
let outline = buffer.update(cx, |buffer, _| buffer.snapshot().outline(None));
|
||||
|
||||
assert_eq!(
|
||||
outline
|
||||
@@ -902,7 +898,7 @@ async fn test_outline_with_extra_context(cx: &mut gpui::TestAppContext) {
|
||||
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
|
||||
|
||||
// extra context nodes are included in the outline.
|
||||
let outline = snapshot.outline(None).unwrap();
|
||||
let outline = snapshot.outline(None);
|
||||
assert_eq!(
|
||||
outline
|
||||
.items
|
||||
@@ -913,7 +909,7 @@ async fn test_outline_with_extra_context(cx: &mut gpui::TestAppContext) {
|
||||
);
|
||||
|
||||
// extra context nodes do not appear in breadcrumbs.
|
||||
let symbols = snapshot.symbols_containing(3, None).unwrap();
|
||||
let symbols = snapshot.symbols_containing(3, None);
|
||||
assert_eq!(
|
||||
symbols
|
||||
.iter()
|
||||
@@ -945,9 +941,7 @@ fn test_outline_annotations(cx: &mut App) {
|
||||
.unindent();
|
||||
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let outline = buffer
|
||||
.update(cx, |buffer, _| buffer.snapshot().outline(None))
|
||||
.unwrap();
|
||||
let outline = buffer.update(cx, |buffer, _| buffer.snapshot().outline(None));
|
||||
|
||||
assert_eq!(
|
||||
outline
|
||||
@@ -1051,7 +1045,6 @@ async fn test_symbols_containing(cx: &mut gpui::TestAppContext) {
|
||||
) -> Vec<(String, Range<Point>)> {
|
||||
snapshot
|
||||
.symbols_containing(position, None)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user