From 46f3c69f06cc55f36bcc6244a9f96c2481836dea Mon Sep 17 00:00:00 2001
From: Blaž Hrastnik
Date: Thu, 2 Sep 2021 13:55:08 +0900
Subject: lsp: Don't send notifications until initialize completes

Then send open events for all documents with the LSP attached.
---
 helix-term/src/application.rs | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

(limited to 'helix-term')

diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index d3b65a4f..e21c5504 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -275,6 +275,37 @@ impl Application {
                 };
 
                 match notification {
+                    Notification::Initialized => {
+                        let language_server =
+                            match self.editor.language_servers.get_by_id(server_id) {
+                                Some(language_server) => language_server,
+                                None => {
+                                    warn!("can't find language server with id `{}`", server_id);
+                                    return;
+                                }
+                            };
+
+                        let docs = self.editor.documents().filter(|doc| {
+                            doc.language_server().map(|server| server.id()) == Some(server_id)
+                        });
+
+                        // trigger textDocument/didOpen for docs that are already open
+                        for doc in docs {
+                            // TODO: extract and share with editor.open
+                            let language_id = doc
+                                .language()
+                                .and_then(|s| s.split('.').last()) // source.rust
+                                .map(ToOwned::to_owned)
+                                .unwrap_or_default();
+
+                            tokio::spawn(language_server.text_document_did_open(
+                                doc.url().unwrap(),
+                                doc.version(),
+                                doc.text(),
+                                language_id,
+                            ));
+                        }
+                    }
                     Notification::PublishDiagnostics(params) => {
                         let path = params.uri.to_file_path().unwrap();
                         let doc = self.editor.document_by_path_mut(&path);
-- 
cgit v1.2.3-70-g09d2