7220: same level folder rename for will_rename_files r=kjeremy a=ShuiRuTian

use tricky way to support folder rename.

Another step after #7009 and for #4471

Co-authored-by: ShuiRuTian <158983297@qq.com>
Co-authored-by: Song Gao <158983297@qq.com>
This commit is contained in:
bors[bot]
2021-01-13 17:40:45 +00:00
committed by GitHub
3 changed files with 178 additions and 14 deletions

View File

@@ -75,14 +75,24 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
will_create: None,
did_rename: None,
will_rename: Some(FileOperationRegistrationOptions {
filters: vec![FileOperationFilter {
scheme: Some(String::from("file")),
pattern: FileOperationPattern {
glob: String::from("**/*.rs"),
matches: Some(FileOperationPatternKind::File),
options: None,
filters: vec![
FileOperationFilter {
scheme: Some(String::from("file")),
pattern: FileOperationPattern {
glob: String::from("**/*.rs"),
matches: Some(FileOperationPatternKind::File),
options: None,
},
},
}],
FileOperationFilter {
scheme: Some(String::from("file")),
pattern: FileOperationPattern {
glob: String::from("**"),
matches: Some(FileOperationPatternKind::Folder),
options: None,
},
},
],
}),
did_delete: None,
will_delete: None,

View File

@@ -432,9 +432,27 @@ 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() {
// add '/' to end of url -- from `file://path/to/folder` to `file://path/to/folder/`
let mut old_folder_name = from_path.file_stem()?.to_str()?.to_string();
old_folder_name.push('/');
let from_with_trailing_slash = from.join(&old_folder_name).ok()?;
let imitate_from_url = from_with_trailing_slash.join("mod.rs").ok()?;
let new_file_name = to_path.file_name()?.to_str()?;
Some((
snap.url_to_file_id(&imitate_from_url).ok()?,
new_file_name.to_string(),
))
} else {
let old_name = from_path.file_stem()?.to_str()?;
let new_name = to_path.file_stem()?.to_str()?;
match (old_name, new_name) {
("mod", _) => None,
(_, "mod") => None,
_ => Some((snap.url_to_file_id(&from).ok()?, new_name.to_string())),
}
}
}
_ => None,
}