From 2b785f39486bfb6a556b59780190d008198680e5 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 19 Apr 2022 18:50:46 +0200 Subject: [PATCH] Move loading of system files to before server declares initialized Loading of system files will sent mutating requests to self which can deadlock with requests by users. Finish this work before accepting user requests or notifications. --- src/lsp.rs | 57 +++++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/src/lsp.rs b/src/lsp.rs index ecc37a0d..0fe7bea8 100644 --- a/src/lsp.rs +++ b/src/lsp.rs @@ -85,16 +85,6 @@ struct Backend { } impl Backend { - async fn info_message(&self, message: M) - where - M: std::fmt::Display, - { - if let Some(client) = &self.client { - // Send these to the log by default. - client.log_message(MessageType::INFO, message).await; - } - } - async fn warn_message(&self, message: M) where M: std::fmt::Display, @@ -272,6 +262,29 @@ impl LanguageServer for Backend { state.set_workspace_folders(Arc::new(workspace_folders)); } + { + // Load system scripts. + match zeek::prefixes().await { + Ok(prefixes) => { + if let Ok(mut state) = self.state_mut() { + state.set_prefixes(Arc::new(prefixes)); + } + } + Err(e) => error!("{e}"), + } + + // Load all visible files. + if let Ok(files) = self.visible_files().await { + self.did_change_watched_files(DidChangeWatchedFilesParams { + changes: files + .into_iter() + .map(|f| FileEvent::new(f, FileChangeType::CREATED)) + .collect(), + }) + .await; + } + } + Ok(InitializeResult { capabilities: ServerCapabilities { text_document_sync: Some(TextDocumentSyncCapability::Kind( @@ -303,29 +316,7 @@ impl LanguageServer for Backend { } #[instrument] - async fn initialized(&self, _: InitializedParams) { - match zeek::prefixes().await { - Ok(prefixes) => { - if let Ok(mut state) = self.state_mut() { - state.set_prefixes(Arc::new(prefixes)); - } - } - Err(e) => error!("{e}"), - } - - // Load all visible files. - if let Ok(files) = self.visible_files().await { - self.did_change_watched_files(DidChangeWatchedFilesParams { - changes: files - .into_iter() - .map(|f| FileEvent::new(f, FileChangeType::CREATED)) - .collect(), - }) - .await; - } - - self.info_message("server initialized!").await; - } + async fn initialized(&self, _: InitializedParams) {} #[instrument] async fn shutdown(&self) -> Result<()> {