]> git.lizzy.rs Git - rust.git/commitdiff
fix issue.
authorShuiRuTian <158983297@qq.com>
Sun, 10 Jan 2021 06:10:36 +0000 (14:10 +0800)
committerShuiRuTian <158983297@qq.com>
Sun, 10 Jan 2021 06:10:36 +0000 (14:10 +0800)
crates/rust-analyzer/src/handlers.rs
editors/code/src/client.ts

index 176774a7728f1c7d4eab40d770bf47bda9f700de..48060819668708b415c03d11533db5f53de9a70a 100644 (file)
@@ -435,22 +435,22 @@ pub(crate) fn handle_will_rename_files(
                     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 imitate_from_url = from.join("mod.rs").ok()?;
+                        let imite_new_file_name = to_path.file_name()?.to_str()?;
+                        Some((
+                            snap.url_to_file_id(&imitate_from_url).ok()?,
+                            imite_new_file_name.to_string(),
+                        ))
+                    } else {
+                        let old_name = from_path.file_stem()?;
+                        let old_name = old_name.to_str()?;
                         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 old_name != "mod" || new_name != "mod" {
+                            Some((snap.url_to_file_id(&from).ok()?, new_name.to_string()))
+                        } else {
+                            None
+                        }
                     }
                 }
                 _ => None,
index 2a8f2deb4df3df7c1ef7befb88e04a08eb137506..fb8cd4873ce1379ba11cbe531dc00a0eaf9bbe88 100644 (file)
@@ -58,6 +58,13 @@ export function createClient(serverPath: string, cwd: string, extraEnv: Env): lc
             // 2. filter some change in here.
             //     2.1 rename from or to `mod.rs` should be special. 
             //     2.2 not all folder change should be cared, only those have files with ".rs" postfix.
+            let newFiles =  data.files.map((file)=>{
+                const isFolder = !file.oldUri.path.endsWith(".rs");
+                return !isFolder ? file : {
+                    oldUri:vscode.Uri.file(file.oldUri.path+'/'),
+                    newUri:vscode.Uri.file(file.newUri.path+'/')
+                }});
+            data = {...data, files:newFiles};
             return next(data);
         }
     }