From 79a5d35a1a738aee32a2b42487279829d6a1a333 Mon Sep 17 00:00:00 2001 From: ontley Date: Sat, 14 Jan 2023 11:28:50 +0000 Subject: [PATCH 01/18] Added rename command --- book/src/generated/typable-cmd.md | 1 + helix-lsp/src/client.rs | 31 ++++++++++++++ helix-term/src/commands/typed.rs | 67 ++++++++++++++++++++++++++++++- 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index 66e6ac039c26..896beceaf844 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -73,3 +73,4 @@ | `:pipe` | Pipe each selection to the shell command. | | `:pipe-to` | Pipe each selection to the shell command, ignoring output. | | `:run-shell-command`, `:sh` | Run a shell command | +| `:rename` | Rename the currently selected buffer | diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index dd2581c6d916..b0d15de94cd1 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -304,6 +304,11 @@ impl Client { execute_command: Some(lsp::DynamicRegistrationClientCapabilities { dynamic_registration: Some(false), }), + file_operations: Some(lsp::WorkspaceFileOperationsClientCapabilities { + will_rename: Some(true), + did_rename: Some(true), + ..Default::default() + }), ..Default::default() }), text_document: Some(lsp::TextDocumentClientCapabilities { @@ -423,6 +428,32 @@ impl Client { ) } + pub fn will_rename_files( + &self, + params: &Vec + ) -> impl Future>> { + let files = params.clone(); + let request = self.call::( + lsp::RenameFilesParams { files } + ); + + async move { + let json = request.await?; + let response: Option = serde_json::from_value(json)?; + Ok(response) + } + } + + pub fn did_rename_files( + &self, + params: &Vec + ) -> impl Future>{ + let files = params.clone(); + self.notify::( + lsp::RenameFilesParams { files } + ) + } + // ------------------------------------------------------------------------------------------- // Text document // ------------------------------------------------------------------------------------------- diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index de24c4fba5ca..733232bb2b3c 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1,9 +1,10 @@ -use std::ops::Deref; +use std::{ops::Deref, ffi::OsStr}; use crate::job::Job; use super::*; +use helix_lsp::{ Url, lsp }; use helix_view::{ apply_transaction, editor::{Action, CloseError, ConfigEvent}, @@ -1825,6 +1826,63 @@ fn run_shell_command( Ok(()) } +fn rename_buffer( + cx: &mut compositor::Context, + args: &[Cow], + event: PromptEvent, +) -> anyhow::Result<()> { + if event != PromptEvent::Validate { + return Ok(()); + } + ensure!(args.len() == 1, ":rename_buffer takes one argument"); + let new_name = args.first().unwrap(); + + let (_, doc) = current!(cx.editor); + let path = doc + .relative_path() + .ok_or_else(|| anyhow!("Buffer not saved, use :write"))? + .canonicalize() + .map_err(|_| anyhow!("Could not get absolute path of the document"))?; + let mut path_new = path.clone(); + path_new.set_file_name(OsStr::new(new_name.as_ref())); + + if std::fs::rename(&path, &path_new).is_err() { + return Err(anyhow!("Could not rename file")) + } + let (_, doc) = current!(cx.editor); + doc.set_path(Some(path_new.as_path())) + .map_err(|_| anyhow!("File renamed, but could not set path of the document"))?; + + let mut lsp_success = false; + if let Some(lsp_client) = doc.language_server() { + let old_uri = Url::from_file_path(&path) + .map_err(|_| anyhow!("Language server request failed, could not get current path uri"))? + .to_string(); + let new_uri = Url::from_file_path(&path_new) + .map_err(|_| anyhow!("Language server request failed, could not get new path uri"))? + .to_string(); + let mut files = vec![ + lsp::FileRename { + old_uri, + new_uri + } + ]; + let result = helix_lsp::block_on(lsp_client.will_rename_files(&files))?; + _ = helix_lsp::block_on(lsp_client.did_rename_files(&files)).is_ok(); + if let Some(edit) = result { + apply_workspace_edit(cx.editor, helix_lsp::OffsetEncoding::Utf8, &edit); + lsp_success = true; + } else { + files.clear(); + } + } + + match lsp_success { + true => Ok(()), + false => Err(anyhow!("File renaming succeeded, but language server did not respond to change")) + } +} + pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ TypableCommand { name: "quit", @@ -2340,6 +2398,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: run_shell_command, completer: Some(completers::directory), }, + TypableCommand { + name: "rename", + aliases: &[], + doc: "Rename the currently selected buffer", + fun: rename_buffer, + completer: None + }, ]; pub static TYPABLE_COMMAND_MAP: Lazy> = From 398a820dbd546114ad622b44ac458d0d12d3c162 Mon Sep 17 00:00:00 2001 From: ontley Date: Sat, 14 Jan 2023 12:03:22 +0000 Subject: [PATCH 02/18] Added an error if the new path already exists --- helix-term/src/commands/typed.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 733232bb2b3c..f56280f16887 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1845,6 +1845,9 @@ fn rename_buffer( .map_err(|_| anyhow!("Could not get absolute path of the document"))?; let mut path_new = path.clone(); path_new.set_file_name(OsStr::new(new_name.as_ref())); + if path_new.exists() { + return Err(anyhow!("This file already exists")); + } if std::fs::rename(&path, &path_new).is_err() { return Err(anyhow!("Could not rename file")) From 25ca3d512352a266744c98787db8822c1299a3ad Mon Sep 17 00:00:00 2001 From: ontley Date: Sat, 14 Jan 2023 14:44:47 +0000 Subject: [PATCH 03/18] Formatting --- helix-lsp/src/client.rs | 14 +++++--------- helix-term/src/commands/typed.rs | 19 ++++++++----------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index b0d15de94cd1..ed667bf27b02 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -430,12 +430,10 @@ impl Client { pub fn will_rename_files( &self, - params: &Vec + params: &Vec, ) -> impl Future>> { let files = params.clone(); - let request = self.call::( - lsp::RenameFilesParams { files } - ); + let request = self.call::(lsp::RenameFilesParams { files }); async move { let json = request.await?; @@ -446,12 +444,10 @@ impl Client { pub fn did_rename_files( &self, - params: &Vec - ) -> impl Future>{ + params: &Vec, + ) -> impl Future> { let files = params.clone(); - self.notify::( - lsp::RenameFilesParams { files } - ) + self.notify::(lsp::RenameFilesParams { files }) } // ------------------------------------------------------------------------------------------- diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index f56280f16887..97d72c88529a 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1,10 +1,10 @@ -use std::{ops::Deref, ffi::OsStr}; +use std::{ffi::OsStr, ops::Deref}; use crate::job::Job; use super::*; -use helix_lsp::{ Url, lsp }; +use helix_lsp::{lsp, Url}; use helix_view::{ apply_transaction, editor::{Action, CloseError, ConfigEvent}, @@ -1850,13 +1850,13 @@ fn rename_buffer( } if std::fs::rename(&path, &path_new).is_err() { - return Err(anyhow!("Could not rename file")) + return Err(anyhow!("Could not rename file")); } let (_, doc) = current!(cx.editor); doc.set_path(Some(path_new.as_path())) .map_err(|_| anyhow!("File renamed, but could not set path of the document"))?; - let mut lsp_success = false; + let mut lsp_success = false; if let Some(lsp_client) = doc.language_server() { let old_uri = Url::from_file_path(&path) .map_err(|_| anyhow!("Language server request failed, could not get current path uri"))? @@ -1864,12 +1864,7 @@ fn rename_buffer( let new_uri = Url::from_file_path(&path_new) .map_err(|_| anyhow!("Language server request failed, could not get new path uri"))? .to_string(); - let mut files = vec![ - lsp::FileRename { - old_uri, - new_uri - } - ]; + let mut files = vec![lsp::FileRename { old_uri, new_uri }]; let result = helix_lsp::block_on(lsp_client.will_rename_files(&files))?; _ = helix_lsp::block_on(lsp_client.did_rename_files(&files)).is_ok(); if let Some(edit) = result { @@ -1882,7 +1877,9 @@ fn rename_buffer( match lsp_success { true => Ok(()), - false => Err(anyhow!("File renaming succeeded, but language server did not respond to change")) + false => Err(anyhow!( + "File renaming succeeded, but language server did not respond to change" + )), } } From 3b23489f6aa3915157f68e23be65fd1af0e961fa Mon Sep 17 00:00:00 2001 From: ontley Date: Sat, 14 Jan 2023 15:30:00 +0000 Subject: [PATCH 04/18] Fixed wrong command name being used --- helix-term/src/commands/typed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 97d72c88529a..d2f036c12c4d 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1834,7 +1834,7 @@ fn rename_buffer( if event != PromptEvent::Validate { return Ok(()); } - ensure!(args.len() == 1, ":rename_buffer takes one argument"); + ensure!(args.len() == 1, ":rename takes one argument"); let new_name = args.first().unwrap(); let (_, doc) = current!(cx.editor); From fdef4f24d22fd8f4cf6a6273f990f123f50c17c2 Mon Sep 17 00:00:00 2001 From: ontley Date: Sat, 14 Jan 2023 15:30:35 +0000 Subject: [PATCH 05/18] fixed clippy suggestions --- helix-lsp/src/client.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index ed667bf27b02..7e5d84a61fc5 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -432,7 +432,7 @@ impl Client { &self, params: &Vec, ) -> impl Future>> { - let files = params.clone(); + let files = params.to_owned(); let request = self.call::(lsp::RenameFilesParams { files }); async move { @@ -442,11 +442,8 @@ impl Client { } } - pub fn did_rename_files( - &self, - params: &Vec, - ) -> impl Future> { - let files = params.clone(); + pub fn did_rename_files(&self, params: &[lsp::FileRename]) -> impl Future> { + let files = params.to_owned(); self.notify::(lsp::RenameFilesParams { files }) } From 258aaa546fd73fbf64c5b61b24f4dadacf1455f5 Mon Sep 17 00:00:00 2001 From: ontley Date: Tue, 17 Jan 2023 09:45:45 +0100 Subject: [PATCH 06/18] removed didRenameFiles call, fixed early return due to path Err --- helix-term/src/commands/typed.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index d2f036c12c4d..1c07150aeed2 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1849,8 +1849,8 @@ fn rename_buffer( return Err(anyhow!("This file already exists")); } - if std::fs::rename(&path, &path_new).is_err() { - return Err(anyhow!("Could not rename file")); + if let Err(e) = std::fs::rename(&path, &path_new) { + return Err(anyhow!("Could not rename file, error: {}", e)); } let (_, doc) = current!(cx.editor); doc.set_path(Some(path_new.as_path())) @@ -1858,20 +1858,21 @@ fn rename_buffer( let mut lsp_success = false; if let Some(lsp_client) = doc.language_server() { - let old_uri = Url::from_file_path(&path) - .map_err(|_| anyhow!("Language server request failed, could not get current path uri"))? - .to_string(); - let new_uri = Url::from_file_path(&path_new) - .map_err(|_| anyhow!("Language server request failed, could not get new path uri"))? - .to_string(); - let mut files = vec![lsp::FileRename { old_uri, new_uri }]; - let result = helix_lsp::block_on(lsp_client.will_rename_files(&files))?; - _ = helix_lsp::block_on(lsp_client.did_rename_files(&files)).is_ok(); - if let Some(edit) = result { - apply_workspace_edit(cx.editor, helix_lsp::OffsetEncoding::Utf8, &edit); - lsp_success = true; + if let Ok(old_uri_str) = Url::from_file_path(&path) { + let old_uri = old_uri_str.to_string(); + if let Ok(new_uri_str) = Url::from_file_path(&path_new) { + let new_uri = new_uri_str.to_string(); + let files = vec![lsp::FileRename { old_uri, new_uri }]; + let result = helix_lsp::block_on(lsp_client.will_rename_files(&files))?; + if let Some(edit) = result { + apply_workspace_edit(cx.editor, helix_lsp::OffsetEncoding::Utf8, &edit); + lsp_success = true; + } + } else { + log::error!(":rename command could not get new path uri") + } } else { - files.clear(); + log::error!(":rename command could not get current path uri") } } From 6ef8fad80392fa8ecdeb6e55e4e6284c36b1b309 Mon Sep 17 00:00:00 2001 From: ontley Date: Wed, 18 Jan 2023 23:04:12 +0100 Subject: [PATCH 07/18] added ':rnm' alias to ':rename' --- book/src/generated/typable-cmd.md | 2 +- helix-term/src/commands/typed.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index 896beceaf844..3983d3b4ca59 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -73,4 +73,4 @@ | `:pipe` | Pipe each selection to the shell command. | | `:pipe-to` | Pipe each selection to the shell command, ignoring output. | | `:run-shell-command`, `:sh` | Run a shell command | -| `:rename` | Rename the currently selected buffer | +| `:rename`, `:rnm` | Rename the currently selected buffer | diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 1c07150aeed2..f4c60ab84e36 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2401,7 +2401,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ }, TypableCommand { name: "rename", - aliases: &[], + aliases: &["rnm"], doc: "Rename the currently selected buffer", fun: rename_buffer, completer: None From 406fd8893d238117f46966a4ac117d8dc2aec358 Mon Sep 17 00:00:00 2001 From: ontley Date: Sun, 22 Jan 2023 11:11:44 +0100 Subject: [PATCH 08/18] code cleanup --- helix-term/src/commands/typed.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index f4c60ab84e36..704db39a90c0 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1846,17 +1846,16 @@ fn rename_buffer( let mut path_new = path.clone(); path_new.set_file_name(OsStr::new(new_name.as_ref())); if path_new.exists() { - return Err(anyhow!("This file already exists")); + bail!("This file already exists"); } if let Err(e) = std::fs::rename(&path, &path_new) { - return Err(anyhow!("Could not rename file, error: {}", e)); + bail!("Could not rename file, error: {}", e); } let (_, doc) = current!(cx.editor); doc.set_path(Some(path_new.as_path())) .map_err(|_| anyhow!("File renamed, but could not set path of the document"))?; - let mut lsp_success = false; if let Some(lsp_client) = doc.language_server() { if let Ok(old_uri_str) = Url::from_file_path(&path) { let old_uri = old_uri_str.to_string(); @@ -1866,7 +1865,8 @@ fn rename_buffer( let result = helix_lsp::block_on(lsp_client.will_rename_files(&files))?; if let Some(edit) = result { apply_workspace_edit(cx.editor, helix_lsp::OffsetEncoding::Utf8, &edit); - lsp_success = true; + } else { + bail!("File renaming succeded, but language server did not respond to change") } } else { log::error!(":rename command could not get new path uri") @@ -1875,13 +1875,8 @@ fn rename_buffer( log::error!(":rename command could not get current path uri") } } - - match lsp_success { - true => Ok(()), - false => Err(anyhow!( - "File renaming succeeded, but language server did not respond to change" - )), - } + cx.editor.set_status(format!("Renamed file to {}", new_name)); + Ok(()) } pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ From 9526d7c1b76b3d6241fcd0fc50cc56316ded080c Mon Sep 17 00:00:00 2001 From: ontley Date: Sun, 22 Jan 2023 20:55:07 +0100 Subject: [PATCH 09/18] formatting --- helix-term/src/commands/typed.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 333b6aa50df4..a70c839f700d 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1862,8 +1862,10 @@ fn rename_buffer( let files = vec![lsp::FileRename { old_uri, new_uri }]; log::debug!("{:?}", files); match helix_lsp::block_on(lsp_client.will_rename_files(&files)) { - Ok(edit) => apply_workspace_edit(cx.editor, helix_lsp::OffsetEncoding::Utf8, &edit), - Err(err) => log::error!("Language server error: {}", err) + Ok(edit) => { + apply_workspace_edit(cx.editor, helix_lsp::OffsetEncoding::Utf8, &edit) + } + Err(err) => log::error!("Language server error: {}", err), } } else { log::error!(":rename command could not get new path uri") @@ -1872,7 +1874,8 @@ fn rename_buffer( log::error!(":rename command could not get current path uri") } } - cx.editor.set_status(format!("Renamed file to {}", new_name)); + cx.editor + .set_status(format!("Renamed file to {}", new_name)); Ok(()) } From 826d9b78511b9c9fa01d1286786083711d87266e Mon Sep 17 00:00:00 2001 From: ontley Date: Fri, 24 Mar 2023 20:28:23 +0100 Subject: [PATCH 10/18] removed debug line --- helix-term/src/commands/typed.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index a70c839f700d..6874966a6c4c 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1860,7 +1860,6 @@ fn rename_buffer( if let Ok(new_uri_str) = Url::from_file_path(&path_new) { let new_uri = new_uri_str.to_string(); let files = vec![lsp::FileRename { old_uri, new_uri }]; - log::debug!("{:?}", files); match helix_lsp::block_on(lsp_client.will_rename_files(&files)) { Ok(edit) => { apply_workspace_edit(cx.editor, helix_lsp::OffsetEncoding::Utf8, &edit) From 17904c6d13f6d53a051d2446442e2187f22ed79e Mon Sep 17 00:00:00 2001 From: ontley Date: Fri, 24 Mar 2023 21:19:21 +0100 Subject: [PATCH 11/18] cargo fmt --- helix-term/src/commands/typed.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 01fcdcdba779..dcd11a65c87a 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1,13 +1,13 @@ -use std::fmt::Write; use std::ffi::OsStr; +use std::fmt::Write; use std::ops::Deref; use crate::job::Job; use super::*; -use helix_lsp::{lsp, Url}; use helix_core::{encoding, shellwords::Shellwords}; +use helix_lsp::{lsp, Url}; use helix_view::document::DEFAULT_LANGUAGE_NAME; use helix_view::editor::{Action, CloseError, ConfigEvent}; use serde_json::Value; @@ -2189,7 +2189,9 @@ fn rename_buffer( let files = vec![lsp::FileRename { old_uri, new_uri }]; match helix_lsp::block_on(lsp_client.will_rename_files(&files)) { Ok(edit) => { - if apply_workspace_edit(cx.editor, helix_lsp::OffsetEncoding::Utf8, &edit).is_err() { + if apply_workspace_edit(cx.editor, helix_lsp::OffsetEncoding::Utf8, &edit) + .is_err() + { log::error!(":rename command failed to apply edits") } } From e1d628d35b7c08ad50d4d70c1fd4d61c8610df27 Mon Sep 17 00:00:00 2001 From: ontley Date: Sat, 25 Mar 2023 07:33:32 +0100 Subject: [PATCH 12/18] docgen --- book/src/generated/typable-cmd.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index d1ab2535b2da..a6ced674e4db 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -76,5 +76,5 @@ | `:pipe` | Pipe each selection to the shell command. | | `:pipe-to` | Pipe each selection to the shell command, ignoring output. | | `:run-shell-command`, `:sh` | Run a shell command | +| `:reset-diff-change`, `:diffget`, `:diffg` | Reset the diff change at the cursor position. | | `:rename`, `:rnm` | Rename the currently selected buffer | -| `:reset-diff-change`, `:diffget`, `:diffg` | Reset the diff change at the cursor position. | \ No newline at end of file From 9925f3ebda7b46c562ec70e4b8c71f089cf09557 Mon Sep 17 00:00:00 2001 From: ontley <67148677+ontley@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:19:23 +0200 Subject: [PATCH 13/18] Improved new buffer error message Co-authored-by: Pascal Kuthe --- helix-term/src/commands/typed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index dd64b121e37c..22109c3068d9 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2183,7 +2183,7 @@ fn rename_buffer( let (_, doc) = current!(cx.editor); let path = doc .relative_path() - .ok_or_else(|| anyhow!("Buffer not saved, use :write"))? + .ok_or_else(|| anyhow!("Scratch buffers can not be renamed, use :write"))? .canonicalize() .map_err(|_| anyhow!("Could not get absolute path of the document"))?; let mut path_new = path.clone(); From e78775078bc9fe67f5687b02cfc564d5c21d54ae Mon Sep 17 00:00:00 2001 From: ontley <67148677+ontley@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:20:19 +0200 Subject: [PATCH 14/18] Removed unnecessary path normalizing Co-authored-by: Pascal Kuthe --- helix-term/src/commands/typed.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 22109c3068d9..2085d45dd348 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2184,8 +2184,6 @@ fn rename_buffer( let path = doc .relative_path() .ok_or_else(|| anyhow!("Scratch buffers can not be renamed, use :write"))? - .canonicalize() - .map_err(|_| anyhow!("Could not get absolute path of the document"))?; let mut path_new = path.clone(); path_new.set_file_name(OsStr::new(new_name.as_ref())); if path_new.exists() { From 411be74fd41802b8ad00a01a5b2ba91e032db307 Mon Sep 17 00:00:00 2001 From: ontley <67148677+ontley@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:22:00 +0200 Subject: [PATCH 15/18] Update helix-term/src/commands/typed.rs Co-authored-by: Pascal Kuthe --- helix-term/src/commands/typed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 2085d45dd348..206eb040339b 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2182,7 +2182,7 @@ fn rename_buffer( let (_, doc) = current!(cx.editor); let path = doc - .relative_path() + .path() .ok_or_else(|| anyhow!("Scratch buffers can not be renamed, use :write"))? let mut path_new = path.clone(); path_new.set_file_name(OsStr::new(new_name.as_ref())); From a9a30c16f8223765520166ba8505b7cb3c647aae Mon Sep 17 00:00:00 2001 From: ontley <67148677+ontley@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:22:23 +0200 Subject: [PATCH 16/18] Update helix-term/src/commands/typed.rs Co-authored-by: Pascal Kuthe --- helix-term/src/commands/typed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 206eb040339b..ad41a2755ac6 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2187,7 +2187,7 @@ fn rename_buffer( let mut path_new = path.clone(); path_new.set_file_name(OsStr::new(new_name.as_ref())); if path_new.exists() { - bail!("This file already exists"); + bail!("Destination already exists"); } if let Err(e) = std::fs::rename(&path, &path_new) { From c8205667e9c42fbd4720dae9b65ce80883bbe4f4 Mon Sep 17 00:00:00 2001 From: ontley <67148677+ontley@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:22:43 +0200 Subject: [PATCH 17/18] Update helix-term/src/commands/typed.rs Co-authored-by: Pascal Kuthe --- helix-term/src/commands/typed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index ad41a2755ac6..12172e86aece 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2211,7 +2211,7 @@ fn rename_buffer( log::error!(":rename command failed to apply edits") } } - Err(err) => log::error!("Language server error: {}", err), + Err(err) => log::error!("willRename request failed: {err}"), } } else { log::error!(":rename command could not get new path uri") From c0e7f508af1960f8de8961505ef58b2753305121 Mon Sep 17 00:00:00 2001 From: ontley <67148677+ontley@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:23:36 +0200 Subject: [PATCH 18/18] Update helix-term/src/commands/typed.rs Co-authored-by: Pascal Kuthe --- helix-term/src/commands/typed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 12172e86aece..900a2c19643e 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2191,7 +2191,7 @@ fn rename_buffer( } if let Err(e) = std::fs::rename(&path, &path_new) { - bail!("Could not rename file, error: {}", e); + bail!("Could not rename file: {e}"); } let (_, doc) = current!(cx.editor); doc.set_path(Some(path_new.as_path()))