code-repo-wiki 0.4.0

自动分析代码仓库结构,通过 LLM 生成结构化项目文档(Code Repo Wiki)
Documentation
use petgraph::stable_graph::NodeIndex;
use serde::{Deserialize, Serialize};

/// 节点 ID(映射到 petgraph 的 NodeIndex)
pub type NodeId = NodeIndex<u32>;

/// 代码实体节点
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CodeNode {
    /// 在 petgraph 图中的索引
    pub id: NodeId,
    /// 实体类型
    pub kind: NodeKind,
    /// 实体名称
    pub name: String,
    /// 所属文件路径(相对项目根)
    pub file_path: Option<String>,
    /// 源代码行范围 [start, end]
    pub line_range: Option<(usize, usize)>,
    /// 文档注释
    pub doc_comment: Option<String>,
    /// 函数/类型签名
    pub signature: Option<String>,
    /// 可见性修饰符("pub"/"pub(crate)"/"private"/"internal"/"export" 等),
    /// 由解析器按行级文本提取;缺失(默认可见性)为 None。
    /// serde(default) 兼容旧版 insights_cache 反序列化。
    #[serde(default)]
    pub visibility: Option<String>,
    /// 模块路径(用 :: 分隔)
    pub module_path: Vec<String>,
}

/// 节点类型
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum NodeKind {
    /// 项目根
    Project,
    /// 模块/目录
    Module,
    /// 文件
    File,
    /// 结构体
    Struct,
    /// 枚举
    Enum,
    /// 函数/方法
    Function,
    /// Trait
    Trait,
    /// Trait 实现
    Impl,
    /// 类型别名
    Type,
    /// 常量
    Constant,
    /// 变量
    Variable,
    /// 接口(TypeScript/Go/Java)
    Interface,
    ///    Class,
    ///    Macro,
}

impl NodeKind {
    pub fn as_str(&self) -> &'static str {
        match self {
            NodeKind::Project => "project",
            NodeKind::Module => "module",
            NodeKind::File => "file",
            NodeKind::Struct => "struct",
            NodeKind::Enum => "enum",
            NodeKind::Function => "function",
            NodeKind::Trait => "trait",
            NodeKind::Impl => "impl",
            NodeKind::Type => "type",
            NodeKind::Constant => "constant",
            NodeKind::Variable => "variable",
            NodeKind::Interface => "interface",
            NodeKind::Class => "class",
            NodeKind::Macro => "macro",
        }
    }
}