about summary refs log tree commit diff
path: root/crates/rust-analyzer/src
diff options
context:
space:
mode:
authorShuiRuTian <158983297@qq.com>2021-01-10 01:29:08 +0800
committerShuiRuTian <158983297@qq.com>2021-01-10 01:29:08 +0800
commit0d86e222297233387ad4abc2796dfd27c5333aaa (patch)
tree740e53bdc4ab3b309dbf23471a01511d3ccd281a /crates/rust-analyzer/src
parentc08391ce32c471d09fcc6fe48bd295bbb5a7de10 (diff)
downloadrust-0d86e222297233387ad4abc2796dfd27c5333aaa.tar.gz
rust-0d86e222297233387ad4abc2796dfd27c5333aaa.zip
beta version for folder rename
Diffstat (limited to 'crates/rust-analyzer/src')
-rw-r--r--crates/rust-analyzer/src/caps.rs3
-rw-r--r--crates/rust-analyzer/src/handlers.rs23
2 files changed, 22 insertions, 4 deletions
diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs
index 5167a005fd7..406a93b101a 100644
--- a/crates/rust-analyzer/src/caps.rs
+++ b/crates/rust-analyzer/src/caps.rs
@@ -85,8 +85,9 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
                                 matches: Some(FileOperationPatternKind::File),
                                 options: None,
                             },
+                        },
                         FileOperationFilter {
-                            scheme: Some(String::from("untitled")),
+                            scheme: Some(String::from("file")),
                             pattern: FileOperationPattern {
                                 glob: String::from("**"),
                                 matches: Some(FileOperationPatternKind::Folder),
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index c13cdc4e383..176774a7728 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -432,9 +432,26 @@ pub(crate) fn handle_will_rename_files(
             // Limit to single-level moves for now.
             match (from_path.parent(), to_path.parent()) {
                 (Some(p1), Some(p2)) if p1 == p2 => {
-                    let new_name = to_path.file_stem()?;
-                    let new_name = new_name.to_str()?;
-                    Some((snap.url_to_file_id(&from).ok()?, new_name.to_string()))
+                    if from_path.is_dir() {
+                        // This is a quick implement, try to use will_rename_file code.
+                        // imitate change the older_folder/mod.rs to older_folder/new_folder.rs
+                        let imitate_from_path = from_path.join("mod.rs");
+                        let new_from_url = imitate_from_path.to_str()?;
+                        let new_from_url = Url::parse(new_from_url).ok()?;
+
+                        let new_folder_name = to_path.file_name()?.to_str()?;
+                        let mut imite_new_file_name  = new_folder_name.to_string();
+                        imite_new_file_name.push_str(".rs");
+                        let new_to = from_path.join(imite_new_file_name);
+                        let new_to = new_to.to_str()?;
+
+                        Some((snap.url_to_file_id(&new_from_url).ok()?, new_to.to_string()))
+                    }
+                    else{
+                        let new_name = to_path.file_stem()?;
+                        let new_name = new_name.to_str()?;
+                        Some((snap.url_to_file_id(&from).ok()?, new_name.to_string()))
+                    }
                 }
                 _ => None,
             }