Simplify some cases that use return None to use ?

pull/574/head
Blaž Hrastnik 3 years ago
parent de5e5863aa
commit d14ca05d6b

@ -194,10 +194,7 @@ fn get_highest_syntax_node_at_bytepos(syntax: &Syntax, pos: usize) -> Option<Nod
let tree = syntax.tree(); let tree = syntax.tree();
// named_descendant // named_descendant
let mut node = match tree.root_node().descendant_for_byte_range(pos, pos) { let mut node = tree.root_node().descendant_for_byte_range(pos, pos)?;
Some(node) => node,
None => return None,
};
while let Some(parent) = node.parent() { while let Some(parent) = node.parent() {
if parent.start_byte() == node.start_byte() { if parent.start_byte() == node.start_byte() {

@ -165,10 +165,7 @@ fn get_breakpoint_at_current_line(editor: &mut Editor) -> Option<(usize, Breakpo
let text = doc.text().slice(..); let text = doc.text().slice(..);
let line = doc.selection(view.id).primary().cursor_line(text); let line = doc.selection(view.id).primary().cursor_line(text);
let path = match doc.path() { let path = doc.path()?;
Some(path) => path,
None => return None,
};
editor.breakpoints.get(path).and_then(|breakpoints| { editor.breakpoints.get(path).and_then(|breakpoints| {
let i = breakpoints.iter().position(|b| b.line == line); let i = breakpoints.iter().position(|b| b.line == line);
i.map(|i| (i, breakpoints[i].clone())) i.map(|i| (i, breakpoints[i].clone()))

@ -119,12 +119,7 @@ pub fn breakpoints<'doc>(
Box::new(move |line: usize, _selected: bool, out: &mut String| { Box::new(move |line: usize, _selected: bool, out: &mut String| {
let breakpoint = breakpoints let breakpoint = breakpoints
.iter() .iter()
.find(|breakpoint| breakpoint.line == line); .find(|breakpoint| breakpoint.line == line)?;
let breakpoint = match breakpoint {
Some(b) => b,
None => return None,
};
let mut style = if breakpoint.condition.is_some() && breakpoint.log_message.is_some() { let mut style = if breakpoint.condition.is_some() && breakpoint.log_message.is_some() {
error.add_modifier(Modifier::UNDERLINED) error.add_modifier(Modifier::UNDERLINED)

Loading…
Cancel
Save