From 5c41f22c2a20a1b8a91ddd6397686bd752591ffc Mon Sep 17 00:00:00 2001 From: Ryan Fowler Date: Fri, 21 Jul 2023 15:21:21 -0700 Subject: Add support for LSP DidChangeWatchedFiles (#7665) * Add initial support for LSP DidChangeWatchedFiles * Move file event Handler to helix-lsp * Simplify file event handling * Refactor file event handling * Block on future within LSP file event handler * Fully qualify uses of the file_event::Handler type * Rename ops field to options * Revert newline removal from helix-view/Cargo.toml * Ensure file event Handler is cleaned up when lsp client is shutdown--- helix-view/src/editor.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'helix-view/src') diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index affe87dd..20469ae9 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1535,7 +1535,18 @@ impl Editor { let path = path.map(|path| path.into()); let doc = doc_mut!(self, &doc_id); - let future = doc.save(path, force)?; + let doc_save_future = doc.save(path, force)?; + + // When a file is written to, notify the file event handler. + // Note: This can be removed once proper file watching is implemented. + let handler = self.language_servers.file_event_handler.clone(); + let future = async move { + let res = doc_save_future.await; + if let Ok(event) = &res { + handler.file_changed(event.path.clone()); + } + res + }; use futures_util::stream; @@ -1671,6 +1682,14 @@ impl Editor { &self, timeout: Option, ) -> Result<(), tokio::time::error::Elapsed> { + // Remove all language servers from the file event handler. + // Note: this is non-blocking. + for client in self.language_servers.iter_clients() { + self.language_servers + .file_event_handler + .remove_client(client.id()); + } + tokio::time::timeout( Duration::from_millis(timeout.unwrap_or(3000)), future::join_all( -- cgit v1.2.3-70-g09d2