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

Code before:
                    return;
                };

                if let Some(parsed_cancellation_data) = parsed_cancellation_data {
                    if parsed_cancellation_data.retrigger_request {
                        tokio::time::sleep(Duration::from_millis(500)).await;

                        job::dispatch(move |editor, _| {
                            if let (Some(doc), Some(language_server)) = (
                                editor.document(document_id),
                                editor.language_server_by_id(language_server_id),
                            ) {
                                pull_diagnostics_for_document(doc, language_server);
                            }
                        })
                        .await;
                    }
                }
            }
        }
    });
}

fn handle_pull_diagnostics_response(
    editor: &mut Editor,
    response: lsp::DocumentDiagnosticReport,
    provider: DiagnosticProvider,
    uri: Uri,
    document_id: DocumentId,
) {
    let (result_id, related_documents) = match response {
        lsp::DocumentDiagnosticReport::Full(report) => {
            editor.handle_lsp_diagnostics(
                &provider,
                uri,
                None,
                report.full_document_diagnostic_report.items,
            );

            (
                report.full_document_diagnostic_report.result_id,
                report.related_documents,
            )
        }
        lsp::DocumentDiagnosticReport::Unchanged(report) => (
            Some(report.unchanged_document_diagnostic_report.result_id),
            report.related_documents,
        ),
    };

    if let Some(doc) = editor.document_mut(document_id) {

Review comment (suggestion):
It looks like the return value for the future should be `lsp::DocumentDiagnosticReportResult`: https://github.com/helix-editor/helix/blob/6da1a79d80d90d13cb4821362a52fa0d6b9bdee6/helix-lsp-types/src/request.rs#L900

(It decodes correctly as `lsp::DocumentDiagnosticReport` because the result one is an untagged enum that can be `lsp::DocumentDiagnosticReport`)

Ideally we would do the decoding in the client. This comes up fairly often actually so I might push a change to the LSP client code to always eagerly decode - there isn't really any point in doing it lazily and it can lead to type mixups like this

(Edit: added in https://github.com/helix-editor/helix/commit/7e7a98560e58371690d00e380d79e0bbaaf19d54 and rebased and handled the different type)

Code after:
                                .ok()
                        })
                    } else {
                        log::error!("Pull diagnostic request failed: {err}");
                        continue;
                    };
                    if parsed_cancellation_data.is_some_and(|data| data.retrigger_request) {
                        retry_language_servers.insert(server_id);
                    }
                }
                Some(None) => break,
                // The request was cancelled.
                None => return,
            }
        }

        if !retry_language_servers.is_empty() {
            tokio::time::sleep(Duration::from_millis(500)).await;

            job::dispatch(move |editor, _| {
                request_document_diagnostics_for_language_severs(
                    editor,
                    doc_id,
                    retry_language_servers,
                );
            })
            .await;
        }
    });
}

pub fn request_document_diagnostics(editor: &mut Editor, doc_id: DocumentId) {
    let Some(doc) = editor.document(doc_id) else {
        return;
    };

    let language_servers = doc
        .language_servers_with_feature(LanguageServerFeature::PullDiagnostics)
        .map(|language_servers| language_servers.id())
        .collect();

    request_document_diagnostics_for_language_severs(editor, doc_id, language_servers);
}

fn handle_pull_diagnostics_response(
    editor: &mut Editor,
    result: lsp::DocumentDiagnosticReportResult,
    provider: DiagnosticProvider,
    uri: Uri,
    document_id: DocumentId,
) {