nautilus-orm-lsp 0.1.3

LSP server for .nautilus schema files
//! Per-document state cached by the LSP server.
//!
//! Every time the client sends a `didOpen`, `didChange`, or `didSave`
//! notification the server re-runs analysis and stores a fresh
//! [`DocumentState`].  Subsequent `textDocument/completion`, `hover`, and
//! `definition` requests read from this cache rather than re-analysing.

use nautilus_schema::analysis::{analyze, AnalysisResult};

/// Snapshot of a single `.nautilus` document.
#[derive(Clone)]
pub struct DocumentState {
    /// Full text of the document as last received from the client.
    pub source: String,
    /// Analysis result produced from `source`.
    pub analysis: AnalysisResult,
}

impl DocumentState {
    /// Analyze `source` and build a new [`DocumentState`].
    pub fn new(source: String) -> Self {
        let analysis = analyze(&source);
        Self { source, analysis }
    }
}