Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-lsp/src/client.rs')
| -rw-r--r-- | helix-lsp/src/client.rs | 101 |
1 files changed, 81 insertions, 20 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index ee67201b..ad19efae 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -616,8 +616,12 @@ impl Client { relative_pattern_support: Some(true), }), file_operations: Some(lsp::WorkspaceFileOperationsClientCapabilities { + will_create: Some(true), + did_create: Some(true), will_rename: Some(true), did_rename: Some(true), + will_delete: Some(true), + did_delete: Some(true), ..Default::default() }), diagnostic: Some(lsp::DiagnosticWorkspaceClientCapabilities { @@ -808,6 +812,47 @@ impl Client { }) } + fn file_operation_uri(path: &Path, is_dir: bool) -> Option<String> { + let url = if is_dir { + Url::from_directory_path(path) + } else { + Url::from_file_path(path) + }; + Some(url.ok()?.to_string()) + } + + pub fn will_create( + &self, + path: &Path, + is_dir: bool, + ) -> Option<impl Future<Output = Result<Option<lsp::WorkspaceEdit>>>> { + let capabilities = self.file_operations_intests(); + if !capabilities.will_create.has_interest(path, is_dir) { + return None; + } + + let files = vec![lsp::FileCreate { + uri: Self::file_operation_uri(path, is_dir)?, + }]; + Some(self.call_with_timeout::<lsp::request::WillCreateFiles>( + &lsp::CreateFilesParams { files }, + 5, + )) + } + + pub fn did_create(&self, path: &Path, is_dir: bool) -> Option<()> { + let capabilities = self.file_operations_intests(); + if !capabilities.did_create.has_interest(path, is_dir) { + return None; + } + + let files = vec![lsp::FileCreate { + uri: Self::file_operation_uri(path, is_dir)?, + }]; + self.notify::<lsp::notification::DidCreateFiles>(lsp::CreateFilesParams { files }); + Some(()) + } + pub fn will_rename( &self, old_path: &Path, @@ -818,17 +863,9 @@ impl Client { if !capabilities.will_rename.has_interest(old_path, is_dir) { return None; } - let url_from_path = |path| { - let url = if is_dir { - Url::from_directory_path(path) - } else { - Url::from_file_path(path) - }; - Some(url.ok()?.to_string()) - }; let files = vec![lsp::FileRename { - old_uri: url_from_path(old_path)?, - new_uri: url_from_path(new_path)?, + old_uri: Self::file_operation_uri(old_path, is_dir)?, + new_uri: Self::file_operation_uri(new_path, is_dir)?, }]; Some(self.call_with_timeout::<lsp::request::WillRenameFiles>( &lsp::RenameFilesParams { files }, @@ -841,23 +878,47 @@ impl Client { if !capabilities.did_rename.has_interest(new_path, is_dir) { return None; } - let url_from_path = |path| { - let url = if is_dir { - Url::from_directory_path(path) - } else { - Url::from_file_path(path) - }; - Some(url.ok()?.to_string()) - }; let files = vec![lsp::FileRename { - old_uri: url_from_path(old_path)?, - new_uri: url_from_path(new_path)?, + old_uri: Self::file_operation_uri(old_path, is_dir)?, + new_uri: Self::file_operation_uri(new_path, is_dir)?, }]; self.notify::<lsp::notification::DidRenameFiles>(lsp::RenameFilesParams { files }); Some(()) } + pub fn will_delete( + &self, + path: &Path, + is_dir: bool, + ) -> Option<impl Future<Output = Result<Option<lsp::WorkspaceEdit>>>> { + let capabilities = self.file_operations_intests(); + if !capabilities.will_delete.has_interest(path, is_dir) { + return None; + } + + let files = vec![lsp::FileDelete { + uri: Self::file_operation_uri(path, is_dir)?, + }]; + Some(self.call_with_timeout::<lsp::request::WillDeleteFiles>( + &lsp::DeleteFilesParams { files }, + 5, + )) + } + + pub fn did_delete(&self, path: &Path, is_dir: bool) -> Option<()> { + let capabilities = self.file_operations_intests(); + if !capabilities.did_delete.has_interest(path, is_dir) { + return None; + } + + let files = vec![lsp::FileDelete { + uri: Self::file_operation_uri(path, is_dir)?, + }]; + self.notify::<lsp::notification::DidDeleteFiles>(lsp::DeleteFilesParams { files }); + Some(()) + } + // ------------------------------------------------------------------------------------------- // Text document // ------------------------------------------------------------------------------------------- |