oo-ide 0.0.4

∞ is a terminal IDE focused on low distraction, high usability.
Documentation
//! Format-specific cursor context detectors.
//!
//! Each sub-module is responsible for parsing a specific file format and
//! converting a (buffer, cursor) pair into a [`CursorContext`].
//!
//! Add new sub-modules here when adding YAML/JSON/etc. support.

pub mod toml;
pub mod yaml;
pub mod json;

use std::path::Path;

use crate::editor::position::Position;
use crate::schema::context::CursorContext;

/// Detect the cursor context for the file at `path`.
///
/// Returns `None` if the format is unsupported or context detection fails,
/// in which case the caller should fall back to the legacy heuristic.
pub fn detect_cursor_context(
    lines: &[String],
    trigger: &Position,
    path: Option<&Path>,
) -> Option<CursorContext> {
    let ext = path?.extension()?.to_str()?;
    match ext {
        "toml" => toml::detect_context(lines, trigger),
        "yaml" | "yml" => yaml::detect_context(lines, trigger),
        "json" => json::detect_context(lines, trigger),
        _ => None,
    }
}