minor: Remove a few unwraps.
This commit is contained in:
parent
cf0e191a6a
commit
ad3325db8e
6 changed files with 11 additions and 13 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -831,12 +831,12 @@ pub fn buffer_picker(cx: &mut Context) {
|
|||
.collect(),
|
||||
move |(id, path): &(DocumentId, Option<PathBuf>)| {
|
||||
// format_fn
|
||||
match path {
|
||||
match path.as_ref().and_then(|path| path.to_str()) {
|
||||
Some(path) => {
|
||||
if *id == current {
|
||||
format!("{} (*)", path.to_str().unwrap()).into()
|
||||
format!("{} (*)", path).into()
|
||||
} else {
|
||||
path.to_str().unwrap().into()
|
||||
path.into()
|
||||
}
|
||||
}
|
||||
None => "[NEW]".into(),
|
||||
|
|
|
@ -130,9 +130,7 @@ impl Prompt {
|
|||
theme.get("ui.statusline"),
|
||||
);
|
||||
for (i, (_range, completion)) in self.completion.iter().enumerate() {
|
||||
let color = if self.completion_selection_index.is_some()
|
||||
&& i == self.completion_selection_index.unwrap()
|
||||
{
|
||||
let color = if Some(i) == self.completion_selection_index {
|
||||
Style::default().bg(Color::Rgb(104, 60, 232))
|
||||
} else {
|
||||
text_color
|
||||
|
|
Loading…
Add table
Reference in a new issue