Skip to main content

ontocore_core/
quick_fix.rs

1//! Structured quick-fix payloads for diagnostics and LSP code actions.
2
3use serde::{Deserialize, Serialize};
4
5/// Machine-readable quick fix attached to a [`crate::Diagnostic`].
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7#[serde(tag = "kind", rename_all = "snake_case")]
8pub enum QuickFix {
9    /// Insert text at a 1-based line/column in the document.
10    InsertText { label: String, line: usize, column: usize, text: String },
11    /// Apply OntoCore Turtle patch operations (same JSON as `ontocore patch`).
12    ApplyPatch { label: String, document_path: String, patches: Vec<serde_json::Value> },
13    /// Remove a line (1-based) from the document.
14    RemoveLine { label: String, line: usize },
15}
16
17impl QuickFix {
18    pub fn encode(&self) -> Option<String> {
19        serde_json::to_string(self).ok()
20    }
21
22    pub fn decode(raw: &str) -> Option<Self> {
23        serde_json::from_str(raw).ok()
24    }
25}