1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! impl of the `textDocument/publishDiagnostics` notification
//!
//! # Usage
//! A server can publish diagnostics for a specific document via [`Connection::publish_diagnostics`]
//! in any callback. The client will then display these diagnostics in the editor.
use serde::{Serialize, Deserialize};
use serde_repr::{Serialize_repr, Deserialize_repr};
use crate::{Connection, TypeProvider};
use crate::connection::RpcConnection;
use super::{DocumentUri, Range};
#[derive(Default, Clone)]
pub(super) struct PublishDiagnostics;
/// The diagnostic information.
#[derive(Deserialize, Serialize, Debug)]
pub struct Diagnostic {
/// A range in the document that contains the diagnostic message.
pub range: Range,
/// The severity of the diagnostic.
pub severity: Option<DiagnosticSeverity>,
/// A optional code to identify the diagnostic.
pub code: Option<String>,
/// A string describing the source of this diagnostic.
pub source: Option<String>,
/// A human-readable string describing the diagnostic.
pub message: String,
}
/// The diagnostic severity.
#[repr(i32)]
#[derive(Deserialize_repr, Serialize_repr, Debug)]
pub enum DiagnosticSeverity {
Error = 1,
Warning = 2,
Information = 3,
Hint = 4
}
#[derive(Serialize)]
struct PublishDiagnosticsParams {
uri: DocumentUri,
diagnostics: Vec<Diagnostic>
}
impl PublishDiagnostics {
const METHOD: &'static str = "textDocument/publishDiagnostics";
}
impl<T: TypeProvider> Connection<T> {
/// [Publishes diagnostics](self) for a specific document.
///
/// # Arguments
/// * `uri` - The [`DocumentUri`] of the document to publish diagnostics for.
/// * `diagnostics` - A list of diagnostics to publish.
pub fn publish_diagnostics(&mut self, uri: DocumentUri, diagnostics: Vec<Diagnostic>) {
self.notify(
PublishDiagnostics::METHOD,
PublishDiagnosticsParams {
uri,
diagnostics
}
);
}
}