1use gpui_shared_string::SharedString;
2use lsp::{DiagnosticSeverity, NumberOrString};
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// A diagnostic associated with a certain range of a buffer.
7#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
8pub struct Diagnostic {
9 /// The name of the service that produced this diagnostic.
10 pub source: Option<String>,
11 /// The ID provided by the dynamic registration that produced this diagnostic.
12 pub registration_id: Option<SharedString>,
13 /// A machine-readable code that identifies this diagnostic.
14 pub code: Option<NumberOrString>,
15 pub code_description: Option<lsp::Uri>,
16 /// Whether this diagnostic is a hint, warning, or error.
17 pub severity: DiagnosticSeverity,
18 /// The human-readable message associated with this diagnostic.
19 pub message: String,
20 /// The human-readable message (in markdown format)
21 pub markdown: Option<String>,
22 /// An id that identifies the group to which this diagnostic belongs.
23 ///
24 /// When a language server produces a diagnostic with
25 /// one or more associated diagnostics, those diagnostics are all
26 /// assigned a single group ID.
27 pub group_id: usize,
28 /// Whether this diagnostic is the primary diagnostic for its group.
29 ///
30 /// In a given group, the primary diagnostic is the top-level diagnostic
31 /// returned by the language server. The non-primary diagnostics are the
32 /// associated diagnostics.
33 pub is_primary: bool,
34 /// Whether this diagnostic is considered to originate from an analysis of
35 /// files on disk, as opposed to any unsaved buffer contents. This is a
36 /// property of a given diagnostic source, and is configured for a given
37 /// language server via the `LspAdapter::disk_based_diagnostic_sources` method
38 /// for the language server.
39 pub is_disk_based: bool,
40 /// Whether this diagnostic marks unnecessary code.
41 pub is_unnecessary: bool,
42 /// Quick separation of diagnostics groups based by their source.
43 pub source_kind: DiagnosticSourceKind,
44 /// Data from language server that produced this diagnostic. Passed back to the LS when we request code actions for this diagnostic.
45 pub data: Option<Value>,
46 /// Whether to underline the corresponding text range in the editor.
47 pub underline: bool,
48}
49
50#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
51pub enum DiagnosticSourceKind {
52 Pulled,
53 Pushed,
54 Other,
55}
56
57impl Default for Diagnostic {
58 fn default() -> Self {
59 Self {
60 source: Default::default(),
61 source_kind: DiagnosticSourceKind::Other,
62 code: None,
63 code_description: None,
64 severity: DiagnosticSeverity::ERROR,
65 message: Default::default(),
66 markdown: None,
67 group_id: 0,
68 is_primary: false,
69 is_disk_based: false,
70 is_unnecessary: false,
71 underline: true,
72 data: None,
73 registration_id: None,
74 }
75 }
76}