perl_lsp_diagnostic_types/lib.rs
1//! Shared diagnostic model types for Perl LSP crates.
2
3#![deny(unsafe_code)]
4#![warn(rust_2018_idioms)]
5#![warn(missing_docs)]
6#![warn(clippy::all)]
7
8/// Severity level for diagnostics.
9///
10/// Represents the importance and type of a diagnostic message.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
12pub enum DiagnosticSeverity {
13 /// Critical error that prevents successful parsing or execution.
14 Error = 1,
15 /// Non-critical issue that should be addressed.
16 Warning = 2,
17 /// Informational message.
18 Information = 3,
19 /// Subtle suggestion for improvement.
20 Hint = 4,
21}
22
23/// A diagnostic message.
24///
25/// Represents an issue found during code analysis with location,
26/// severity, and additional context information.
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct Diagnostic {
29 /// Source code range (start, end) where the issue occurs.
30 pub range: (usize, usize),
31 /// Severity level of the diagnostic.
32 pub severity: DiagnosticSeverity,
33 /// Optional diagnostic code for categorization.
34 pub code: Option<String>,
35 /// Human-readable description of the issue.
36 pub message: String,
37 /// Additional context and related information.
38 pub related_information: Vec<RelatedInformation>,
39 /// Tags for categorizing the diagnostic.
40 pub tags: Vec<DiagnosticTag>,
41}
42
43/// Related information for a diagnostic.
44///
45/// Additional context that helps understand or resolve the main diagnostic.
46#[derive(Debug, Clone, PartialEq, Eq)]
47pub struct RelatedInformation {
48 /// Location in source code for the related information.
49 pub location: (usize, usize),
50 /// Description of the related information.
51 pub message: String,
52}
53
54/// Tags for diagnostics.
55///
56/// Additional metadata about the nature of a diagnostic.
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub enum DiagnosticTag {
59 /// Code that is not needed and can be removed.
60 Unnecessary,
61 /// Code that uses deprecated features.
62 Deprecated,
63}