代码索引库

TSG Indexer是一个使用Tree-sitter Stack Graphs分析代码仓库并构建代码结构图表示的Rust库,支持20多种编程语言,适用于代码导航和分析。

  • by eas4ai
  • Rust
  • 本地部署
  • 16 星标
  • 更新于
在 GitHub 查看 entrepeneur4lyf/tsg_indexer

使用说明

TSG索引器

一个使用Tree sitter Stack Graphs对代码库进行索引的库,设计用于MCP服务器和其他工具。

概述

TSG Indexer是一个Rust库,它使用Tree sitter Stack Graphs来分析代码存储库并构建代码结构的图形表示。它捕获了跨文件的定义和引用之间的关系,实现了强大的代码导航和分析功能。

主要特点:

TSG Indexer是一个使用 树型堆栈图 分析代码存储库并构建代码结构的图形表示。此图捕获了跨文件的定义和引用之间的关系,从而实现了强大的代码导航和分析。

支持20多种编程语言,包括Rust、Python、JavaScript、TypeScript、Java等 用于全面代码库分析的递归目录遍历 多种输出格式(JSON、DOT图) 通过功能标志提供可选的CLI和LSP支持 能够为不支持的语言生成TSG文件 该库旨在与模型控制协议(MCP)服务器和其他需要代码索引和导航功能的工具集成。它利用GitHub的树形图解析系统和堆栈图技术来创建一个全面的代码分析解决方案。

特性

  • 支持多种语言:
    • 锈
    • python
    • 脚本
    • TypeScript
    • Java
    • 迅速的
    • 内存管理
    • 层叠样式表
    • 斯卡拉
    • 之字形
    • 格式
    • 去
    • PHP程序
    • 可扩展置标语言
    • JSDoc
    • 猛击
    • 对象符号
    • 超文本标记语言
    • C
    • 红宝石
    • 降价
    • 洛
    • 达特
    • 还有更多!
  • 递归目录遍历
  • 多种输出格式:
    • 对象符号
    • DOT图
  • 可选功能的功能标志:
    • cli -命令行界面支持
    • lsp -语言服务器协议支持

安装

添加到您的Cargo.toml:

[dependencies]
tsg_indexer = { version = "0.1.0", features = ["cli", "lsp"] }

或者克隆并构建存储库:

# Clone the repository
git clone https://github.com/entrepeneur4lyf/tsg_indexer.git
cd tsg_indexer

# Build the project
cargo build --release

图书馆使用情况

use tsg_indexer::{IndexerConfig, run_indexer};
use std::path::PathBuf;

fn main() -> anyhow::Result<()> {
    // Create configuration
    let config = IndexerConfig {
        path: PathBuf::from("src/"),
        format: "json".to_string(),
        output: Some(PathBuf::from("output.json")),
        verbose: true,
    };
    
    // Run the indexer
    run_indexer(config)
}

CLI使用情况

当与 cli 特点:

# Index a single file
tsg_indexer_cli examples/test_rust.rs

# Index a directory recursively
tsg_indexer_cli src/

# Output in DOT format
tsg_indexer_cli --format dot src/

# Output to a file
tsg_indexer_cli --output graph.json src/

# Verbose mode
tsg_indexer_cli --verbose src/

与MCP服务器一起使用

该库旨在用于模型控制协议(MCP)服务器中的代码索引和导航功能。它提供了使用树形图和堆栈图解析和分析代码存储库所需的核心功能。

MCP集成

要与MCP服务器集成,请执行以下操作:

  1. 添加tsg_indexer作为具有适当功能的依赖项
  2. 使用库的API为代码编制索引并构建堆栈图
  3. 利用图形数据进行代码导航、参考查找等

示例

# Index the examples directory (with CLI feature enabled)
tsg_indexer_cli examples/

# The output will show the graph structure in JSON format by default

贡献

欢迎投稿!以下是您可以做出贡献的一些方式:

  • 报告错误
  • 添加对更多语言的支持
  • 改进错误处理
  • 添加更多输出格式
  • 优化性能

许可证

麻省理工学院许可证和Apache 2.0许可证-我不是100%确定如何正确许可这个lol。

致谢