Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-lsp/src/file_event.rs')
| -rw-r--r-- | helix-lsp/src/file_event.rs | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/helix-lsp/src/file_event.rs b/helix-lsp/src/file_event.rs index 5e7f8ca6..93457fa5 100644 --- a/helix-lsp/src/file_event.rs +++ b/helix-lsp/src/file_event.rs @@ -3,24 +3,24 @@ use std::{collections::HashMap, path::PathBuf, sync::Weak}; use globset::{GlobBuilder, GlobSetBuilder}; use tokio::sync::mpsc; -use crate::{lsp, Client, LanguageServerId}; +use crate::{lsp, Client}; enum Event { FileChanged { path: PathBuf, }, Register { - client_id: LanguageServerId, + client_id: usize, client: Weak<Client>, registration_id: String, options: lsp::DidChangeWatchedFilesRegistrationOptions, }, Unregister { - client_id: LanguageServerId, + client_id: usize, registration_id: String, }, RemoveClient { - client_id: LanguageServerId, + client_id: usize, }, } @@ -59,7 +59,7 @@ impl Handler { pub fn register( &self, - client_id: LanguageServerId, + client_id: usize, client: Weak<Client>, registration_id: String, options: lsp::DidChangeWatchedFilesRegistrationOptions, @@ -72,7 +72,7 @@ impl Handler { }); } - pub fn unregister(&self, client_id: LanguageServerId, registration_id: String) { + pub fn unregister(&self, client_id: usize, registration_id: String) { let _ = self.tx.send(Event::Unregister { client_id, registration_id, @@ -83,12 +83,12 @@ impl Handler { let _ = self.tx.send(Event::FileChanged { path }); } - pub fn remove_client(&self, client_id: LanguageServerId) { + pub fn remove_client(&self, client_id: usize) { let _ = self.tx.send(Event::RemoveClient { client_id }); } async fn run(mut rx: mpsc::UnboundedReceiver<Event>) { - let mut state: HashMap<LanguageServerId, ClientState> = HashMap::new(); + let mut state: HashMap<usize, ClientState> = HashMap::new(); while let Some(event) = rx.recv().await { match event { Event::FileChanged { path } => { @@ -113,13 +113,17 @@ impl Handler { "Sending didChangeWatchedFiles notification to client '{}'", client.name() ); - client.did_change_watched_files(vec![lsp::FileEvent { - uri, - // We currently always send the CHANGED state - // since we don't actually have more context at - // the moment. - typ: lsp::FileChangeType::CHANGED, - }]); + if let Err(err) = crate::block_on(client + .did_change_watched_files(vec![lsp::FileEvent { + uri, + // We currently always send the CHANGED state + // since we don't actually have more context at + // the moment. + typ: lsp::FileChangeType::CHANGED, + }])) + { + log::warn!("Failed to send didChangeWatchedFiles notification to client: {err}"); + } true }); } @@ -135,7 +139,7 @@ impl Handler { registration_id ); - let entry = state.entry(client_id).or_default(); + let entry = state.entry(client_id).or_insert_with(ClientState::default); entry.client = client; let mut builder = GlobSetBuilder::new(); |