Skip to main content

rantlr_core/
fix_hint.rs

1//! Structured auto-fix payloads for the linter / playground / LSP.
2
3use serde::Serialize;
4
5use crate::span::Span;
6
7/// A concrete rewrite the UI can preview and apply.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct FixHint {
11    pub title: String,
12    /// Human explanation in plain “dev-speak”.
13    pub explanation: String,
14    /// Current source slice that will be replaced.
15    pub before: String,
16    /// Suggested replacement source.
17    pub after: String,
18    /// Inclusive-exclusive UTF-8 byte range into the grammar source.
19    pub start: u32,
20    pub end: u32,
21}
22
23impl FixHint {
24    pub fn new(
25        title: impl Into<String>,
26        explanation: impl Into<String>,
27        before: impl Into<String>,
28        after: impl Into<String>,
29        span: Span,
30    ) -> Self {
31        Self {
32            title: title.into(),
33            explanation: explanation.into(),
34            before: before.into(),
35            after: after.into(),
36            start: span.start.0,
37            end: span.end.0,
38        }
39    }
40}