on master help sign in
minor: Remove a few unwraps.
ad3325dBlaž Hrastnik
helix-core/src/indent.rs+1−1
@@ -24,7 +24,7 @@ fn indent_level_for_line(line: RopeSlice, tab_width: usize) -> usize {
24/// Find the highest syntax node at position.
24/// Find the highest syntax node at position.
25/// This is to identify the column where this node (e.g., an HTML closing tag) ends.
25/// This is to identify the column where this node (e.g., an HTML closing tag) ends.
26fn get_highest_syntax_node_at_bytepos(syntax: &Syntax, pos: usize) -> Option<Node> {
26fn get_highest_syntax_node_at_bytepos(syntax: &Syntax, pos: usize) -> Option<Node> {
27− let tree = syntax.root_layer.tree.as_ref().unwrap();
27+ let tree = syntax.tree();
28
28
29 // named_descendant
29 // named_descendant
30 let mut node = match tree.root_node().descendant_for_byte_range(pos, pos) {
30 let mut node = match tree.root_node().descendant_for_byte_range(pos, pos) {
helix-core/src/match_brackets.rs+1−1
@@ -5,7 +5,7 @@ use crate::{Range, Rope, Selection, Syntax};
5
5
6#[must_use]
6#[must_use]
7pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
7pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
8− let tree = syntax.root_layer.tree.as_ref().unwrap();
8+ let tree = syntax.tree();
9
9
10 let byte_pos = doc.char_to_byte(pos);
10 let byte_pos = doc.char_to_byte(pos);
11
11
helix-core/src/object.rs+1−1
@@ -4,7 +4,7 @@ use smallvec::smallvec;
4// TODO: to contract_selection we'd need to store the previous ranges before expand.
4// TODO: to contract_selection we'd need to store the previous ranges before expand.
5// Maybe just contract to the first child node?
5// Maybe just contract to the first child node?
6pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: &Selection) -> Selection {
6pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: &Selection) -> Selection {
7− let tree = syntax.root_layer.tree.as_ref().unwrap();
7+ let tree = syntax.tree();
8
8
9 selection.transform(|range| {
9 selection.transform(|range| {
10 let from = text.char_to_byte(range.from());
10 let from = text.char_to_byte(range.from());
helix-core/src/syntax.rs+4−4
@@ -172,7 +172,7 @@ thread_local! {
172pub struct Syntax {
172pub struct Syntax {
173 config: Arc<HighlightConfiguration>,
173 config: Arc<HighlightConfiguration>,
174
174
175− pub(crate) root_layer: LanguageLayer,
175+ root_layer: LanguageLayer,
176}
176}
177
177
178fn byte_range_to_str(range: std::ops::Range<usize>, source: RopeSlice) -> Cow<str> {
178fn byte_range_to_str(range: std::ops::Range<usize>, source: RopeSlice) -> Cow<str> {
@@ -251,7 +251,7 @@ impl Syntax {
251 //
251 //
252 // fn parse(language, old_tree, ranges)
252 // fn parse(language, old_tree, ranges)
253 //
253 //
254− fn tree(&self) -> &Tree {
254+ pub fn tree(&self) -> &Tree {
255 self.root_layer.tree()
255 self.root_layer.tree()
256 }
256 }
257 //
257 //
@@ -363,7 +363,7 @@ impl LanguageLayer {
363 // Self { tree: None }
363 // Self { tree: None }
364 // }
364 // }
365
365
366− fn tree(&self) -> &Tree {
366+ pub fn tree(&self) -> &Tree {
367 // TODO: no unwrap
367 // TODO: no unwrap
368 self.tree.as_ref().unwrap()
368 self.tree.as_ref().unwrap()
369 }
369 }
@@ -1566,7 +1566,7 @@ fn test_parser() {
1566 ",
1566 ",
1567 );
1567 );
1568 let syntax = Syntax::new(&source, Arc::new(config));
1568 let syntax = Syntax::new(&source, Arc::new(config));
1569− let tree = syntax.root_layer.tree.unwrap();
1569+ let tree = syntax.tree();
1570 let root = tree.root_node();
1570 let root = tree.root_node();
1571 assert_eq!(root.kind(), "source_file");
1571 assert_eq!(root.kind(), "source_file");
1572
1572
helix-term/src/commands.rs+3−3
@@ -831,12 +831,12 @@ pub fn buffer_picker(cx: &mut Context) {
831 .collect(),
831 .collect(),
832 move |(id, path): &(DocumentId, Option<PathBuf>)| {
832 move |(id, path): &(DocumentId, Option<PathBuf>)| {
833 // format_fn
833 // format_fn
834− match path {
834+ match path.as_ref().and_then(|path| path.to_str()) {
835 Some(path) => {
835 Some(path) => {
836 if *id == current {
836 if *id == current {
837− format!("{} (*)", path.to_str().unwrap()).into()
837+ format!("{} (*)", path).into()
838 } else {
838 } else {
839− path.to_str().unwrap().into()
839+ path.into()
840 }
840 }
841 }
841 }
842 None => "[NEW]".into(),
842 None => "[NEW]".into(),
helix-term/src/ui/prompt.rs+1−3
@@ -130,9 +130,7 @@ impl Prompt {
130 theme.get("ui.statusline"),
130 theme.get("ui.statusline"),
131 );
131 );
132 for (i, (_range, completion)) in self.completion.iter().enumerate() {
132 for (i, (_range, completion)) in self.completion.iter().enumerate() {
133− let color = if self.completion_selection_index.is_some()
134− && i == self.completion_selection_index.unwrap()
133+ let color = if Some(i) == self.completion_selection_index {
135− {
136 Style::default().bg(Color::Rgb(104, 60, 232))
134 Style::default().bg(Color::Rgb(104, 60, 232))
137 } else {
135 } else {
138 text_color
136 text_color