aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorShuiRuTian <[email protected]>2021-01-09 17:29:08 +0000
committerShuiRuTian <[email protected]>2021-01-09 17:29:08 +0000
commit0d86e222297233387ad4abc2796dfd27c5333aaa (patch)
tree740e53bdc4ab3b309dbf23471a01511d3ccd281a /crates
parentc08391ce32c471d09fcc6fe48bd295bbb5a7de10 (diff)
beta version for folder rename
Diffstat (limited to 'crates')
-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 5167a005f..406a93b10 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
85 matches: Some(FileOperationPatternKind::File), 85 matches: Some(FileOperationPatternKind::File),
86 options: None, 86 options: None,
87 }, 87 },
88 },
88 FileOperationFilter { 89 FileOperationFilter {
89 scheme: Some(String::from("untitled")), 90 scheme: Some(String::from("file")),
90 pattern: FileOperationPattern { 91 pattern: FileOperationPattern {
91 glob: String::from("**"), 92 glob: String::from("**"),
92 matches: Some(FileOperationPatternKind::Folder), 93 matches: Some(FileOperationPatternKind::Folder),
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index c13cdc4e3..176774a77 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(
432 // Limit to single-level moves for now. 432 // Limit to single-level moves for now.
433 match (from_path.parent(), to_path.parent()) { 433 match (from_path.parent(), to_path.parent()) {
434 (Some(p1), Some(p2)) if p1 == p2 => { 434 (Some(p1), Some(p2)) if p1 == p2 => {
435 let new_name = to_path.file_stem()?; 435 if from_path.is_dir() {
436 let new_name = new_name.to_str()?; 436 // This is a quick implement, try to use will_rename_file code.
437 Some((snap.url_to_file_id(&from).ok()?, new_name.to_string())) 437 // imitate change the older_folder/mod.rs to older_folder/new_folder.rs
438 let imitate_from_path = from_path.join("mod.rs");
439 let new_from_url = imitate_from_path.to_str()?;
440 let new_from_url = Url::parse(new_from_url).ok()?;
441
442 let new_folder_name = to_path.file_name()?.to_str()?;
443 let mut imite_new_file_name = new_folder_name.to_string();
444 imite_new_file_name.push_str(".rs");
445 let new_to = from_path.join(imite_new_file_name);
446 let new_to = new_to.to_str()?;
447
448 Some((snap.url_to_file_id(&new_from_url).ok()?, new_to.to_string()))
449 }
450 else{
451 let new_name = to_path.file_stem()?;
452 let new_name = new_name.to_str()?;
453 Some((snap.url_to_file_id(&from).ok()?, new_name.to_string()))
454 }
438 } 455 }
439 _ => None, 456 _ => None,
440 } 457 }