IndexStoreDB

IndexStoreDB 是一个源代码索引库。它为查找源代码符号、符号出现和关系提供了一个可组合且高效的查询 API。IndexStoreDB 使用 libIndexStore 库,该库位于 apple/llvm-project 中,用于读取原始索引数据。原始索引数据可以由编译器(如 Apple Clang 和 Swift)使用 -index-store-path 选项生成。IndexStoreDB 通过在用 LMDB 构建的键值数据库中维护加速表,从而能够高效地查询这些数据。

IndexStoreDB 的数据模型源自 libIndexStore。有关 libIndexStore 以及生成原始索引数据的更多信息,请参阅 《构建时索引》 白皮书。

构建 IndexStoreDB

IndexStoreDB 使用 Swift Package Manager 构建。

对于标准调试构建和测试

$ swift build
$ swift test

在 Linux 上构建

索引中的 C++ 代码需要 libdispatch,但与 Swift 代码不同,它无法在 Linux 上自动找到它。您可以通过手动添加搜索路径来解决此问题。

$ swift build -Xcxx -I<path_to_swift_toolchain>/usr/lib/swift -Xcxx -I<path_to_swift_toolchain>/usr/lib/swift/Block

一些示例用户

Pecker:一个基于 SwiftSyntaxIndexStoreDB 检测未使用代码的工具。

开发

有关开发 IndexStoreDB 的更多信息,请参阅 Development