Skip to main content

marco_core/intelligence/
mod.rs

1//! Smart Markdown editor intelligence (in-process engine).
2//!
3//! This module replaces the old `lsp` naming with an intelligence-first layout:
4//! - `markdown`: shared markdown model/view of parser data
5//! - `analysis`: linting + diagnostics
6//! - `editor`: highlighting, hover, completion
7//! - `lsp_protocol`: optional protocol adapter surface
8
9#[cfg(feature = "intelligence-diagnostics")]
10pub mod analysis;
11pub mod catalog;
12#[cfg(any(
13    feature = "intelligence-highlights",
14    feature = "intelligence-completions",
15    feature = "intelligence-hover"
16))]
17pub mod editor;
18pub mod lsp_protocol;
19pub mod markdown;
20pub mod toc;
21
22#[cfg(feature = "intelligence-diagnostics")]
23pub use analysis::{
24    compute_diagnostics, compute_diagnostics_critical, compute_diagnostics_with_options,
25    compute_lints, compute_lints_detailed, compute_lints_detailed_with_options,
26    compute_lints_with_options, Diagnostic, DiagnosticCode, DiagnosticSeverity, DiagnosticsOptions,
27    DiagnosticsProfile, LintCodeBucket, LintDetailedReport, LintReport,
28};
29pub use catalog::{
30    diagnostics_catalog, diagnostics_catalog_groups, diagnostics_catalog_settings,
31    diagnostics_markdown_features, find_catalog_entry, find_catalog_entry_by_key,
32    find_catalog_group, find_catalog_group_by_code, find_markdown_feature, DiagnosticsCatalog,
33    DiagnosticsCatalogEntry, DiagnosticsCatalogGroup, DiagnosticsCatalogSettings,
34    MarkdownFeatureCoverage,
35};
36#[cfg(feature = "intelligence-highlights")]
37pub use editor::{compute_highlights, compute_highlights_with_source, Highlight, HighlightTag};
38#[cfg(feature = "intelligence-hover")]
39pub use editor::{get_hover_info, get_position_span, HoverInfo};
40#[cfg(feature = "intelligence-completions")]
41pub use editor::{get_markdown_completions, CompletionItem};
42
43use crate::parser::Document;
44#[cfg(feature = "intelligence-hover")]
45use crate::parser::Position;
46
47/// In-process provider for editor intelligence features.
48#[derive(Default)]
49pub struct MarkdownIntelligenceProvider {
50    document: Option<Document>,
51}
52
53impl MarkdownIntelligenceProvider {
54    /// Create a new intelligence provider with no active document.
55    pub fn new() -> Self {
56        log::info!("Markdown intelligence provider initialized");
57        Self { document: None }
58    }
59
60    /// Replace the currently analyzed document.
61    pub fn update_document(&mut self, document: Document) {
62        self.document = Some(document);
63    }
64
65    /// Compute semantic highlights for the current document using source-aware markers.
66    #[cfg(feature = "intelligence-highlights")]
67    pub fn highlights(&self, source: &str) -> Vec<Highlight> {
68        self.document
69            .as_ref()
70            .map(|doc| compute_highlights_with_source(doc, source))
71            .unwrap_or_default()
72    }
73
74    /// Compute diagnostics for the current document.
75    #[cfg(feature = "intelligence-diagnostics")]
76    pub fn diagnostics(&self) -> Vec<Diagnostic> {
77        self.document
78            .as_ref()
79            .map(compute_diagnostics)
80            .unwrap_or_default()
81    }
82
83    /// Compute diagnostics for the current document using custom options.
84    #[cfg(feature = "intelligence-diagnostics")]
85    pub fn diagnostics_with_options(&self, options: DiagnosticsOptions) -> Vec<Diagnostic> {
86        self.document
87            .as_ref()
88            .map(|doc| compute_diagnostics_with_options(doc, options))
89            .unwrap_or_default()
90    }
91
92    /// Resolve hover information for a source position.
93    #[cfg(feature = "intelligence-hover")]
94    pub fn hover(&self, position: Position) -> Option<HoverInfo> {
95        self.document
96            .as_ref()
97            .and_then(|doc| get_hover_info(position, doc))
98    }
99
100    /// Get completion candidates for a query.
101    #[cfg(feature = "intelligence-completions")]
102    pub fn completions(&self, query: &str) -> Vec<CompletionItem> {
103        get_markdown_completions(query)
104    }
105}