@@ -6,7 +6,8 @@ use crate::job::Job;
6use super::*;
6use super::*;
8use helix_core::fuzzy::fuzzy_match;
8use helix_core::fuzzy::fuzzy_match;
9−use helix_core::{encoding, line_ending, shellwords::Shellwords};
9+use helix_core::{encoding, line_ending, path::get_canonicalized_path, shellwords::Shellwords};
10+use helix_lsp::{OffsetEncoding, Url};
10use helix_view::document::DEFAULT_LANGUAGE_NAME;
11use helix_view::document::DEFAULT_LANGUAGE_NAME;
11use helix_view::editor::{Action, CloseError, ConfigEvent};
12use helix_view::editor::{Action, CloseError, ConfigEvent};
12use serde_json::Value;
13use serde_json::Value;
@@ -2408,6 +2409,80 @@ fn redraw(
2413+ cx: &mut compositor::Context,
2415+ event: PromptEvent,
2416+) -> anyhow::Result<()> {
2417+ if event != PromptEvent::Validate {
2421+ ensure!(args.len() == 1, format!(":move takes one argument"));
2422+ let doc = doc!(cx.editor);
2424+ let new_path = get_canonicalized_path(&PathBuf::from(args.first().unwrap().to_string()));
2427+ .ok_or_else(|| anyhow!("Scratch buffer cannot be moved. Use :write instead"))?
2429+ let old_path_as_url = doc.url().unwrap();
2430+ let new_path_as_url = Url::from_file_path(&new_path).unwrap();
2433+ helix_lsp::Result<helix_lsp::lsp::WorkspaceEdit>,
2437+ .language_servers()
2440+ lsp.prepare_file_rename(&old_path_as_url, &new_path_as_url),
2441+ lsp.offset_encoding(),
2442+ lsp.name().to_owned(),
2445+ .filter(|(f, _, _)| f.is_some())
2446+ .map(|(f, encoding, name)| (helix_lsp::block_on(f.unwrap()), encoding, name))
2449+ for (lsp_reply, encoding, name) in edits {
2452+ if let Err(e) = apply_workspace_edit(cx.editor, encoding, &edit) {
2454+ ":move command failed to apply edits from lsp {}: {:?}",
2461+ log::error!("LSP {} failed to treat willRename request: {:?}", name, e);
2466+ let doc = doc_mut!(cx.editor);
2468+ doc.set_path(Some(new_path.as_path()));
2469+ if let Err(e) = std::fs::rename(&old_path, &new_path) {
2470+ doc.set_path(Some(old_path.as_path()));
2471+ bail!("Could not move file: {}", e);
2474+ doc.language_servers().for_each(|lsp| {
2475+ lsp.did_file_rename(&old_path_as_url, &new_path_as_url);
2480+ .file_event_handler
2481+ .file_changed(new_path);
2411pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2486pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2412 TypableCommand {
2487 TypableCommand {
2413 name: "quit",
2488 name: "quit",
@@ -3008,6 +3083,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
3008 fun: redraw,
3083 fun: redraw,
3009 signature: CommandSignature::none(),
3084 signature: CommandSignature::none(),
3089+ doc: "Move the current buffer and its corresponding file to a different path",
3091+ signature: CommandSignature::positional(&[completers::filename]),
3013pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
3095pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =