jdt-lsp-cli
v1.7.2
Published
CLI tool for Java LSP operations, enabling AI agents to call Java language features from the command line
Downloads
1,846
Maintainers
Readme
JDT LSP CLI
CLI tool for Java LSP operations, enabling AI agents to call Java language features from the command line
简介
JDT LSP CLI 是一个基于 Eclipse JDT Language Server 的命令行工具,为 AI Agent 和开发者提供强大的 Java 代码分析能力:
- 🔍 符号搜索: 跨项目搜索类、方法、字段
- 📍 精确定位: 跳转到定义、查找引用、类型跳转
- 🔗 调用链分析: 分析方法调用关系,支持多种模式
- 📚 文档提取: 获取 Javadoc 和类型信息
- ⚡ 守护进程: 快速响应,性能提升 10-100 倍
快速开始
安装
npm install -g jdt-lsp-cli
jls --version基本使用
# 启动守护进程(推荐)
jls daemon start --eager --init-project /path/to/java-project
# 搜索类
jls -p /path/to/project find SqlSession --kind Class
# 获取文件符号
jls sym src/main/java/org/example/MyClass.java --flat
# 分析调用链
jls ch src/main/java/org/example/Service.java --method processOrder -d 3文档导航
📚 命令文档
LSP 命令
| 命令 | 别名 | 功能 | 文档 |
|------|------|------|------|
| find | f | 全局符号搜索 | 📖 |
| symbols | sym | 获取文件符号 | 📖 |
| definition | def | 跳转定义 | 📖 |
| references | refs | 查找引用 | 📖 |
| hover | | 悬停信息 | 📖 |
| call-hierarchy | ch | 调用链分析 | 📖 |
| implementations | impl | 查找实现 | 📖 |
| type-definition | typedef | 类型跳转 | 📖 |
管理命令
| 命令 | 功能 | 文档 |
|------|------|------|
| daemon | 守护进程管理 | 📖 |
| config | 配置管理 | 📖 |
🔧 参考文档
核心特性
🎯 精确定位
支持多种符号定位方式:
# 方法名定位
jls def MyClass.java --method myMethod
# 签名匹配(区分重载)
jls def MyClass.java --method process --signature "(String, int)"
# 索引选择
jls def MyClass.java --method process --index 0
# 全局搜索
jls def --global --symbol ArrayList --kind Class⚡ 守护进程模式
# 启动并预初始化
jls daemon start --eager --init-project /path/to/project --wait
# 享受毫秒级响应
jls find MyClass # 5-500ms(而非 30-60s)
jls sym MyClass.java # 即时响应🤖 AI 友好模式
call-hierarchy 命令提供多种 AI Agent 友好的查询模式:
# 惰性加载模式 - 按需探索
jls ch Service.java --method process --mode lazy
# 摘要模式 - 快速理解
jls ch Service.java --method process --mode summary
# 快照模式 - 完整存档
jls ch Service.java --method process --mode snapshot --snapshot-path ./output📦 紧凑输出
减少 token 消耗,适合 AI Agent:
jls def MyClass.java --method myMethod --json-compact典型工作流
# 1. 启动守护进程
jls daemon start --eager --init-project /path/to/project --wait
# 2. 搜索目标类
jls find UserService --kind Class
# 3. 查看类结构
jls sym src/main/java/com/example/UserService.java --flat
# 4. 分析方法调用链
jls ch src/main/java/com/example/UserService.java --method processOrder -d 3
# 5. 查找方法实现
jls impl src/main/java/com/example/OrderService.java --method createOrder
# 6. 获取方法文档
jls hover src/main/java/com/example/OrderService.java --method createOrder
# 7. 查找所有引用
jls refs src/main/java/com/example/UserService.java --method processOrder性能对比
| 模式 | 首次命令 | 后续命令 | |------|----------|----------| | 守护进程模式 | 30-60s | 5-500ms | | 直接模式 | 30-60s | 30-60s |
项目结构
jdt-lsp-cli/
├── docs/ # 文档目录
│ ├── commands/ # 各命令的详细文档
│ │ ├── find.md
│ │ ├── symbols.md
│ │ ├── definition.md
│ │ ├── references.md
│ │ ├── hover.md
│ │ ├── call-hierarchy.md
│ │ ├── implementations.md
│ │ ├── type-definition.md
│ │ ├── daemon.md
│ │ └── config.md
│ └── global-options.md # 全局选项文档
├── src/ # 源代码
│ ├── cli/ # CLI 命令实现
│ ├── core/ # 核心功能
│ ├── jdt/ # JDT LS 集成
│ └── services/ # 服务层
└── README.md # 本文件(文档索引)相关资源
- Eclipse JDT LS - Eclipse Java Language Server
- Red Hat Java Extension - VS Code Java 扩展
- LSP Specification - Language Server Protocol 规范
License
MIT License - 详见 LICENSE 文件
