Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-view/src/handlers/lsp.rs')
| -rw-r--r-- | helix-view/src/handlers/lsp.rs | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/helix-view/src/handlers/lsp.rs b/helix-view/src/handlers/lsp.rs index b052138f..ecdbfdf7 100644 --- a/helix-view/src/handlers/lsp.rs +++ b/helix-view/src/handlers/lsp.rs @@ -230,7 +230,6 @@ impl Editor { op: &lsp::ResourceOp, ) -> Result<(), ApplyEditErrorKind> { use lsp::ResourceOp; - use std::fs; // NOTE: If `Uri` gets another variant than `Path`, the below `expect`s // may no longer be valid. match op { @@ -241,40 +240,25 @@ impl Editor { !options.overwrite.unwrap_or(false) && options.ignore_if_exists.unwrap_or(false) }); if !ignore_if_exists || !path.exists() { - // Create directory if it does not exist - if let Some(dir) = path.parent() { - if !dir.is_dir() { - fs::create_dir_all(dir)?; - } - } - - fs::write(path, [])?; - self.language_servers - .file_event_handler - .file_changed(path.to_path_buf()); + self.create_path(path, false)?; } } ResourceOp::Delete(op) => { let uri = Uri::try_from(&op.uri)?; let path = uri.as_path().expect("URIs are valid paths"); - if path.is_dir() { - let recursive = op - .options - .as_ref() - .and_then(|options| options.recursive) - .unwrap_or(false); - - if recursive { - fs::remove_dir_all(path)? - } else { - fs::remove_dir(path)? - } - self.language_servers - .file_event_handler - .file_changed(path.to_path_buf()); - } else if path.is_file() { - fs::remove_file(path)?; + let ignore_if_not_exists = op + .options + .as_ref() + .is_some_and(|options| options.ignore_if_not_exists.unwrap_or(false)); + if ignore_if_not_exists && !path.exists() { + return Ok(()); } + let recursive = op + .options + .as_ref() + .and_then(|options| options.recursive) + .unwrap_or(false); + self.delete_path(path, recursive)?; } ResourceOp::Rename(op) => { let from_uri = Uri::try_from(&op.old_uri)?; |