dsh-symbol-search
v0.1.0
Published
多语言符号定位插件:索引会话工作区(及可配置 roots)内的源码文件(java/kotlin/rust/python/go/csharp/c/cpp/js/ts/tsx),提取类/接口/结构体/trait/命名空间/函数/方法/字段/常量的精确行号,向 agent 注册 symbol_search 工具,按符号名快速定位定义位置。
Maintainers
Readme
dsh-symbol-search(多语言符号定位)
代码符号定位插件:自动索引会话工作区(及可配置 roots)内的源码文件,按扩展名用 tree-sitter 对应语法提取类/接口/结构体/trait/命名空间/函数/方法/字段/常量的精确行号,向 agent 注册 symbol_search 工具 —— 输入名字,返回文件绝对路径 + 行号 + 签名,快速跳到定义处。
支持语言
| 语言 | 扩展名 | 符号示例 |
|---|---|---|
| Java | .java | class / interface / enum / record / annotation / method / constructor / field |
| Kotlin | .kt .kts | class / interface / object / function / property / class parameter |
| Rust | .rs | mod / struct / enum / trait / fn / const / impl 方法 |
| Python | .py .pyi | class / def / 模块级常量 / 类属性 |
| Go | .go | type(struct/interface) / func / 方法(receiver 归属)/ const / var |
| C# | .cs | namespace / class / interface / enum / record / method / property / field |
| C | .c .h | struct / enum / function / #define |
| C++ | .cpp .cc .cxx .hpp .hh | namespace / class / struct / 模板函数 / 构造器识别 |
| JavaScript | .js .mjs .cjs .jsx | class / function / 模块级常量 |
| TypeScript | .ts .mts .cts .tsx | interface / type alias / abstract class / enum / 函数组件 |
用法(agent 侧)
symbol_search(query: "UserService")
symbol_search(query: "run_with_retry", language: "rust")
symbol_search(query: "FindById", language: "csharp", kind: "method")
symbol_search(query: "Shop.Services.UserServiceImpl") # 命名空间限定
symbol_search(query: "Config.ShouldRetry") # 类型.方法 限定返回(渲染文本示例):
### C:\proj\services\user_service.go:22-24 — method retry.Config.ShouldRetry
func (c Config) ShouldRetry(attempt int) bool搜索支持精确 / 大小写不敏感 / 前缀 / 包含匹配,限定查询(带 .)按 fqn 精确过滤,拼写小误差(Levenshtein ≤ 2)有兜底。
配置(cordis config)
- id: symbol-search
name: dsh-symbol-search
config:
enabled: true # 默认 true
maxResults: 10 # 工具默认返回条数(1-50)
scanIntervalMs: 30000 # 增量扫描周期
maxFileBytes: 2097152 # 单文件大小上限
maxFiles: 20000 # 单 root 最大文件数(walk 模式兜底)
languages: # 启用的语言(默认全部)
- java
- rust
- python
- go
- csharp
- c
- cpp
- kotlin
- javascript
- typescript
roots: [] # 额外索引目录(如 D:\proj\foo)实现要点
- 解析:ast-grep napi + 各语言 tree-sitter 动态库(预编译,无本机构建);JS/TS/TSX 用 napi 内置语法
- 容错:tree-sitter 对残缺文件天然容错;Java 另有正则降级兜底
- 增量:SQLite(
~/.dsh/symbol-search/index.sqlite),mtime+size 增量,删除自愈 - 查询性能:名字匹配下沉 SQL 索引(精确/NOCASE/前缀/包含),模糊仅对去重名字集做 Levenshtein —— 查询代价与符号总量解耦,大项目不退化(6000 符号实测 1-4ms)
状态 API(验证/调试)
GET /symbol-search/status → { roots, languages, files, symbols, degradedFiles, byKind, byLanguage, scanning, lastScanAt, lastError, scanCount }
开发
npm install
node test-parser.mjs # Java 符号提取单元测试
node test-langs.mjs # 多语言提取单元测试
node test-indexer.mjs # 扫描/搜索/自愈/多语言/规模冒烟
node test-plugin.mjs # 插件冒烟测试(需先同步 lib 到 profiles)