grapha 0.1.0

Blazingly fast code intelligence CLI and MCP server for Swift and Rust
Documentation
/// Controls which optional fields appear in CLI output.
///
/// Fields can be selected via `--fields` flag (comma-separated) or configured
/// in `grapha.toml` under `[output] default_fields`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FieldSet {
    pub file: bool,
    pub id: bool,
    pub module: bool,
    pub span: bool,
    pub snippet: bool,
    pub visibility: bool,
    pub signature: bool,
    pub role: bool,
}

impl Default for FieldSet {
    fn default() -> Self {
        Self {
            file: true,
            id: false,
            module: false,
            span: false,
            snippet: false,
            visibility: false,
            signature: false,
            role: false,
        }
    }
}

impl FieldSet {
    pub fn all() -> Self {
        Self {
            file: true,
            id: true,
            module: true,
            span: true,
            snippet: true,
            visibility: true,
            signature: true,
            role: true,
        }
    }

    pub fn none() -> Self {
        Self {
            file: false,
            id: false,
            module: false,
            span: false,
            snippet: false,
            visibility: false,
            signature: false,
            role: false,
        }
    }

    pub fn parse(input: &str) -> Self {
        match input.trim() {
            "all" => Self::all(),
            "none" => Self::none(),
            s => {
                let mut fs = Self::none();
                for field in s.split(',') {
                    match field.trim() {
                        "file" => fs.file = true,
                        "id" => fs.id = true,
                        "module" => fs.module = true,
                        "span" => fs.span = true,
                        "snippet" => fs.snippet = true,
                        "visibility" => fs.visibility = true,
                        "signature" => fs.signature = true,
                        "role" => fs.role = true,
                        _ => {}
                    }
                }
                fs
            }
        }
    }

    pub fn from_config(fields: &[String]) -> Self {
        Self::parse(&fields.join(","))
    }
}