1
0
mirror of https://github.com/helix-editor/helix synced 2024-11-10 10:34:45 +01:00

Remove a couple more unwraps

This commit is contained in:
Blaž Hrastnik 2022-06-21 05:47:48 +09:00
parent 19dccade7c
commit 23b5b1e25a
5 changed files with 21 additions and 10 deletions

@ -1683,8 +1683,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
let scrolloff = config.scrolloff;
let (view, doc) = current!(cx.editor);
let registers = &cx.editor.registers;
if let Some(query) = registers.read('/') {
let query = query.last().unwrap();
if let Some(query) = registers.read('/').and_then(|query| query.last()) {
let contents = doc.text().slice(..).to_string();
let search_config = &config.search;
let case_insensitive = if search_config.smart_case {
@ -2124,7 +2123,11 @@ fn append_mode(cx: &mut Context) {
// Make sure there's room at the end of the document if the last
// selection butts up against it.
let end = text.len_chars();
let last_range = doc.selection(view.id).iter().last().unwrap();
let last_range = doc
.selection(view.id)
.iter()
.last()
.expect("selection should always have at least one range");
if !last_range.is_empty() && last_range.head == end {
let transaction = Transaction::change(
doc.text(),

@ -61,7 +61,14 @@ fn jump_to_location(
return;
}
};
let _id = editor.open(&path, action).expect("editor.open failed");
match editor.open(&path, action) {
Ok(_) => (),
Err(err) => {
let err = format!("failed to open path: {:?}: {:?}", location.uri, err);
editor.set_error(err);
return;
}
}
let (view, doc) = current!(editor);
let definition_pos = location.range.start;
// TODO: convert inside server
@ -491,7 +498,7 @@ fn goto_impl(
locations: Vec<lsp::Location>,
offset_encoding: OffsetEncoding,
) {
let cwdir = std::env::current_dir().expect("couldn't determine current directory");
let cwdir = std::env::current_dir().unwrap_or_default();
match locations.as_slice() {
[location] => {

@ -1,3 +1,5 @@
use std::ops::Deref;
use super::*;
use helix_view::editor::{Action, ConfigEvent};
@ -961,7 +963,7 @@ fn get_option(
let key = &args[0].to_lowercase();
let key_error = || anyhow::anyhow!("Unknown key `{}`", key);
let config = serde_json::to_value(&cx.editor.config().clone()).unwrap();
let config = serde_json::json!(cx.editor.config().deref());
let pointer = format!("/{}", key.replace('.', "/"));
let value = config.pointer(&pointer).ok_or_else(key_error)?;
@ -984,7 +986,7 @@ fn set_option(
let key_error = || anyhow::anyhow!("Unknown key `{}`", key);
let field_error = |_| anyhow::anyhow!("Could not parse field `{}`", arg);
let mut config = serde_json::to_value(&cx.editor.config().clone()).unwrap();
let mut config = serde_json::json!(&cx.editor.config().deref());
let pointer = format!("/{}", key.replace('.', "/"));
let value = config.pointer_mut(&pointer).ok_or_else(key_error)?;

@ -263,8 +263,7 @@ pub mod completers {
pub fn setting(_editor: &Editor, input: &str) -> Vec<Completion> {
static KEYS: Lazy<Vec<String>> = Lazy::new(|| {
serde_json::to_value(Config::default())
.unwrap()
serde_json::json!(Config::default())
.as_object()
.unwrap()
.keys()

@ -443,7 +443,7 @@ impl Prompt {
let input: Cow<str> = if self.line.is_empty() {
// latest value in the register list
self.history_register
.and_then(|reg| cx.editor.registers.first(reg).cloned()) // TODO: can we avoid cloning?
.and_then(|reg| cx.editor.registers.first(reg))
.map(|entry| entry.into())
.unwrap_or_else(|| Cow::from(""))
} else {