diff options
author | Blaž Hrastnik | 2021-03-26 02:02:32 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-03-26 02:03:14 +0000 |
commit | ad3325db8e6dce3a10b9f8e0319ab9814c7ade1b (patch) | |
tree | b855b4ca22fccb6eb97f011af3f26372d5c8df1c /helix-core | |
parent | cf0e191a6a42a2382128765dc0ff1531ad9800af (diff) |
minor: Remove a few unwraps.
Diffstat (limited to 'helix-core')
-rw-r--r-- | helix-core/src/indent.rs | 2 | ||||
-rw-r--r-- | helix-core/src/match_brackets.rs | 2 | ||||
-rw-r--r-- | helix-core/src/object.rs | 2 | ||||
-rw-r--r-- | helix-core/src/syntax.rs | 8 |
4 files changed, 7 insertions, 7 deletions
diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index 7fedb7d3..4bd644d4 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -24,7 +24,7 @@ fn indent_level_for_line(line: RopeSlice, tab_width: usize) -> usize { /// Find the highest syntax node at position. /// This is to identify the column where this node (e.g., an HTML closing tag) ends. fn get_highest_syntax_node_at_bytepos(syntax: &Syntax, pos: usize) -> Option<Node> { - let tree = syntax.root_layer.tree.as_ref().unwrap(); + let tree = syntax.tree(); // named_descendant let mut node = match tree.root_node().descendant_for_byte_range(pos, pos) { diff --git a/helix-core/src/match_brackets.rs b/helix-core/src/match_brackets.rs index f641d094..fd161776 100644 --- a/helix-core/src/match_brackets.rs +++ b/helix-core/src/match_brackets.rs @@ -5,7 +5,7 @@ use crate::{Range, Rope, Selection, Syntax}; #[must_use] pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> { - let tree = syntax.root_layer.tree.as_ref().unwrap(); + let tree = syntax.tree(); let byte_pos = doc.char_to_byte(pos); diff --git a/helix-core/src/object.rs b/helix-core/src/object.rs index 19ff9d96..1c644fb2 100644 --- a/helix-core/src/object.rs +++ b/helix-core/src/object.rs @@ -4,7 +4,7 @@ use smallvec::smallvec; // TODO: to contract_selection we'd need to store the previous ranges before expand. // Maybe just contract to the first child node? pub fn expand_selection(syntax: &Syntax, text: RopeSlice, selection: &Selection) -> Selection { - let tree = syntax.root_layer.tree.as_ref().unwrap(); + let tree = syntax.tree(); selection.transform(|range| { let from = text.char_to_byte(range.from()); diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index a6b1cf61..42bfb855 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -172,7 +172,7 @@ thread_local! { pub struct Syntax { config: Arc<HighlightConfiguration>, - pub(crate) root_layer: LanguageLayer, + root_layer: LanguageLayer, } fn byte_range_to_str(range: std::ops::Range<usize>, source: RopeSlice) -> Cow<str> { @@ -251,7 +251,7 @@ impl Syntax { // // fn parse(language, old_tree, ranges) // - fn tree(&self) -> &Tree { + pub fn tree(&self) -> &Tree { self.root_layer.tree() } // @@ -363,7 +363,7 @@ impl LanguageLayer { // Self { tree: None } // } - fn tree(&self) -> &Tree { + pub fn tree(&self) -> &Tree { // TODO: no unwrap self.tree.as_ref().unwrap() } @@ -1566,7 +1566,7 @@ fn test_parser() { ", ); let syntax = Syntax::new(&source, Arc::new(config)); - let tree = syntax.root_layer.tree.unwrap(); + let tree = syntax.tree(); let root = tree.root_node(); assert_eq!(root.kind(), "source_file"); |