summaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2022-01-14 03:25:59 +0000
committerBlaž Hrastnik2022-01-16 05:19:48 +0000
commite7eab95b943ff15396c5d512a9c95650ab98a902 (patch)
tree88a485634f4eb4a98c86fa5e3fc235a0363cf6bc /helix-term/src
parentf5b0821860940782567a0baa17280aef04f845e3 (diff)
Update to rust 1.58, fix a bunch of optional lints
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs35
-rw-r--r--helix-term/src/job.rs14
-rw-r--r--helix-term/src/keymap.rs8
-rw-r--r--helix-term/src/ui/completion.rs2
4 files changed, 28 insertions, 31 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index c14216c0..9ac12931 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -173,7 +173,7 @@ macro_rules! static_commands {
impl MappableCommand {
pub fn execute(&self, cx: &mut Context) {
match &self {
- MappableCommand::Typable { name, args, doc: _ } => {
+ Self::Typable { name, args, doc: _ } => {
let args: Vec<Cow<str>> = args.iter().map(Cow::from).collect();
if let Some(command) = cmd::TYPABLE_COMMAND_MAP.get(name.as_str()) {
let mut cx = compositor::Context {
@@ -186,21 +186,21 @@ impl MappableCommand {
}
}
}
- MappableCommand::Static { fun, .. } => (fun)(cx),
+ Self::Static { fun, .. } => (fun)(cx),
}
}
pub fn name(&self) -> &str {
match &self {
- MappableCommand::Typable { name, .. } => name,
- MappableCommand::Static { name, .. } => name,
+ Self::Typable { name, .. } => name,
+ Self::Static { name, .. } => name,
}
}
pub fn doc(&self) -> &str {
match &self {
- MappableCommand::Typable { doc, .. } => doc,
- MappableCommand::Static { doc, .. } => doc,
+ Self::Typable { doc, .. } => doc,
+ Self::Static { doc, .. } => doc,
}
}
@@ -3494,11 +3494,9 @@ pub fn apply_document_resource_op(op: &lsp::ResourceOp) -> std::io::Result<()> {
match op {
ResourceOp::Create(op) => {
let path = op.uri.to_file_path().unwrap();
- let ignore_if_exists = if let Some(options) = &op.options {
+ let ignore_if_exists = op.options.as_ref().map_or(false, |options| {
!options.overwrite.unwrap_or(false) && options.ignore_if_exists.unwrap_or(false)
- } else {
- false
- };
+ });
if ignore_if_exists && path.exists() {
Ok(())
} else {
@@ -3508,11 +3506,12 @@ pub fn apply_document_resource_op(op: &lsp::ResourceOp) -> std::io::Result<()> {
ResourceOp::Delete(op) => {
let path = op.uri.to_file_path().unwrap();
if path.is_dir() {
- let recursive = if let Some(options) = &op.options {
- options.recursive.unwrap_or(false)
- } else {
- false
- };
+ let recursive = op
+ .options
+ .as_ref()
+ .and_then(|options| options.recursive)
+ .unwrap_or(false);
+
if recursive {
fs::remove_dir_all(&path)
} else {
@@ -3527,11 +3526,9 @@ pub fn apply_document_resource_op(op: &lsp::ResourceOp) -> std::io::Result<()> {
ResourceOp::Rename(op) => {
let from = op.old_uri.to_file_path().unwrap();
let to = op.new_uri.to_file_path().unwrap();
- let ignore_if_exists = if let Some(options) = &op.options {
+ let ignore_if_exists = op.options.as_ref().map_or(false, |options| {
!options.overwrite.unwrap_or(false) && options.ignore_if_exists.unwrap_or(false)
- } else {
- false
- };
+ });
if ignore_if_exists && to.exists() {
Ok(())
} else {
diff --git a/helix-term/src/job.rs b/helix-term/src/job.rs
index 4fa38174..f5a0a425 100644
--- a/helix-term/src/job.rs
+++ b/helix-term/src/job.rs
@@ -22,8 +22,8 @@ pub struct Jobs {
}
impl Job {
- pub fn new<F: Future<Output = anyhow::Result<()>> + Send + 'static>(f: F) -> Job {
- Job {
+ pub fn new<F: Future<Output = anyhow::Result<()>> + Send + 'static>(f: F) -> Self {
+ Self {
future: f.map(|r| r.map(|()| None)).boxed(),
wait: false,
}
@@ -31,22 +31,22 @@ impl Job {
pub fn with_callback<F: Future<Output = anyhow::Result<Callback>> + Send + 'static>(
f: F,
- ) -> Job {
- Job {
+ ) -> Self {
+ Self {
future: f.map(|r| r.map(Some)).boxed(),
wait: false,
}
}
- pub fn wait_before_exiting(mut self) -> Job {
+ pub fn wait_before_exiting(mut self) -> Self {
self.wait = true;
self
}
}
impl Jobs {
- pub fn new() -> Jobs {
- Jobs::default()
+ pub fn new() -> Self {
+ Self::default()
}
pub fn spawn<F: Future<Output = anyhow::Result<()>> + Send + 'static>(&mut self, f: F) {
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index c4bd25ed..79a06206 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -344,7 +344,7 @@ pub struct Keymap {
impl Keymap {
pub fn new(root: KeyTrie) -> Self {
- Keymap {
+ Self {
root,
state: Vec::new(),
sticky: None,
@@ -368,7 +368,7 @@ impl Keymap {
/// key cancels pending keystrokes. If there are no pending keystrokes but a
/// sticky node is in use, it will be cleared.
pub fn get(&mut self, key: KeyEvent) -> KeymapResult {
- if let key!(Esc) = key {
+ if key!(Esc) == key {
if !self.state.is_empty() {
return KeymapResult::new(
// Note that Esc is not included here
@@ -477,7 +477,7 @@ impl DerefMut for Keymaps {
}
impl Default for Keymaps {
- fn default() -> Keymaps {
+ fn default() -> Self {
let normal = keymap!({ "Normal mode"
"h" | "left" => move_char_left,
"j" | "down" => move_line_down,
@@ -784,7 +784,7 @@ impl Default for Keymaps {
"C-x" => completion,
"C-r" => insert_register,
});
- Keymaps(hashmap!(
+ Self(hashmap!(
Mode::Normal => Keymap::new(normal),
Mode::Select => Keymap::new(select),
Mode::Insert => Keymap::new(insert),
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index 274330c0..c9ed3b4a 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -158,7 +158,7 @@ impl Completion {
let resolved_additional_text_edits = if item.additional_text_edits.is_some() {
None
} else {
- Completion::resolve_completion_item(doc, item.clone())
+ Self::resolve_completion_item(doc, item.clone())
.and_then(|item| item.additional_text_edits)
};