marco_core/intelligence/
mod.rs1#[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#[derive(Default)]
49pub struct MarkdownIntelligenceProvider {
50 document: Option<Document>,
51}
52
53impl MarkdownIntelligenceProvider {
54 pub fn new() -> Self {
56 log::info!("Markdown intelligence provider initialized");
57 Self { document: None }
58 }
59
60 pub fn update_document(&mut self, document: Document) {
62 self.document = Some(document);
63 }
64
65 #[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 #[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 #[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 #[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 #[cfg(feature = "intelligence-completions")]
102 pub fn completions(&self, query: &str) -> Vec<CompletionItem> {
103 get_markdown_completions(query)
104 }
105}