@@ -58,6 +58,36 @@ pub mod util {
58 use super::*;
58 use super::*;
59 use helix_core::{Range, Rope, Transaction};
59 use helix_core::{Range, Rope, Transaction};
61+ /// Converts a diagnostic in the document to [`lsp::Diagnostic`].
63+ /// Panics when [`pos_to_lsp_pos`] would for an invalid range on the diagnostic.
64+ pub fn diagnostic_to_lsp_diagnostic(
66+ diag: &helix_core::diagnostic::Diagnostic,
67+ offset_encoding: OffsetEncoding,
68+ ) -> lsp::Diagnostic {
69+ use helix_core::diagnostic::Severity::*;
71+ let range = Range::new(diag.range.start, diag.range.end);
72+ let severity = diag.severity.map(|s| match s {
73+ Hint => lsp::DiagnosticSeverity::HINT,
74+ Info => lsp::DiagnosticSeverity::INFORMATION,
75+ Warning => lsp::DiagnosticSeverity::WARNING,
76+ Error => lsp::DiagnosticSeverity::ERROR,
79+ // TODO: add support for Diagnostic.data
80+ lsp::Diagnostic::new(
81+ range_to_lsp_range(doc, range, offset_encoding),
85+ diag.message.to_owned(),
61 /// Converts [`lsp::Position`] to a position in the document.
91 /// Converts [`lsp::Position`] to a position in the document.
63 /// Returns `None` if position exceeds document length or an operation overflows.
93 /// Returns `None` if position exceeds document length or an operation overflows.