Repository: helix-editor/helix
File: helix-term/src/application.rs (Rust)

Code before:
                            tokio::spawn(language_server.did_change_configuration(config.clone()));
                        }

                        let docs = self
                            .editor
                            .documents()
                            .filter(|doc| doc.supports_language_server(server_id));

                        // trigger textDocument/didOpen for docs that are already open
                        for doc in docs {
                            let url = match doc.url() {
                                Some(url) => url,
                                None => continue, // skip documents with no path
                            };

                            let language_id =
                                doc.language_id().map(ToOwned::to_owned).unwrap_or_default();

                            tokio::spawn(language_server.text_document_did_open(
                                url,
                                doc.version(),
                                doc.text(),
                                language_id,
                            ));

                            helix_event::dispatch(helix_view::events::DocumentDidOpen { doc });
                        }
                    }
                    Notification::PublishDiagnostics(params) => {
                        let uri = match helix_core::Uri::try_from(params.uri) {
                            Ok(uri) => uri,
                            Err(err) => {
                                log::error!("{err}");
                                return;
                            }
                        };
                        let language_server = language_server!();
                        if !language_server.is_initialized() {
                            log::error!("Discarding publishDiagnostic notification sent by an uninitialized server: {}", language_server.name());
                            return;
                        }

                        let diagnostics: Vec<(lsp::Diagnostic, LanguageServerId)> = params
                            .diagnostics
                            .into_iter()
                            .map(|d| (d, server_id))
                            .collect();

                        self.editor.add_diagnostics(
                            diagnostics,
                            server_id,

Review comment (suggestion):
Ideally we should only be dispatching the internal DocumentDidOpen when we initially open a buffer. Here instead of using `DocumentDidOpen` we should be able to use `pull_diagnostics_for_document`

Code after:
                    Some(mode.into()),
                );
                true
            }
            #[cfg(windows)]
            TerminalEvent::Resize(width, height) => {
                self.terminal
                    .resize(Rect::new(0, 0, width, height))
                    .expect("Unable to resize terminal");

                let area = self.terminal.size().expect("couldn't get terminal size");

                self.compositor.resize(area);

                self.compositor
                    .handle_event(&Event::Resize(width, height), &mut cx)
            }
            #[cfg(windows)]
            // Ignore keyboard release events.
            crossterm::event::Event::Key(crossterm::event::KeyEvent {
                kind: crossterm::event::KeyEventKind::Release,
                ..
            }) => false,
            event => self.compositor.handle_event(&event.into(), &mut cx),
        };

        if should_redraw && !self.editor.should_close() {
            self.render().await;
        }
    }

    pub async fn handle_language_server_message(
        &mut self,
        call: helix_lsp::Call,
        server_id: LanguageServerId,
    ) {
        use helix_lsp::{Call, MethodCall, Notification};

        macro_rules! language_server {
            () => {
                match self.editor.language_server_by_id(server_id) {
                    Some(language_server) => language_server,
                    None => {
                        warn!("can't find language server with id `{}`", server_id);
                        return;
                    }
                }
            };
        }

        match call {