rantlr-core 0.1.0

Rantlr core: .gr lexer, parser, linter, and in-process runtime
Documentation
//! Structured auto-fix payloads for the linter / playground / LSP.

use serde::Serialize;

use crate::span::Span;

/// A concrete rewrite the UI can preview and apply.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FixHint {
    pub title: String,
    /// Human explanation in plain “dev-speak”.
    pub explanation: String,
    /// Current source slice that will be replaced.
    pub before: String,
    /// Suggested replacement source.
    pub after: String,
    /// Inclusive-exclusive UTF-8 byte range into the grammar source.
    pub start: u32,
    pub end: u32,
}

impl FixHint {
    pub fn new(
        title: impl Into<String>,
        explanation: impl Into<String>,
        before: impl Into<String>,
        after: impl Into<String>,
        span: Span,
    ) -> Self {
        Self {
            title: title.into(),
            explanation: explanation.into(),
            before: before.into(),
            after: after.into(),
            start: span.start.0,
            end: span.end.0,
        }
    }
}