代码排查
- 作者仓库星标 3,367
- 许可证 MIT
- 作者仓库 atopile
- 领域
- 通用
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 94 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @atopile · MIT
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- Python
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 命令执行
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
python -m atopile.lsp.lsp_server
# LSP Module
The `lsp` module (located in `src/atopile/lsp/`) implements the Language Server Protocol for atopile. It provides IDE features like autocomplete, go-to-definition, and diagnostics (error reporting) for `ato` files.
## Quick Start
Run the server on stdio (what editors expect):
```bash
python -m atopile.lsp.lsp_server
```
## Relevant Files
- Server implementation: `src/atopile/lsp/lsp_server.py`
- owns global `LSP_SERVER` (pygls `LanguageServer`)
- maintains per-document `DocumentState` (graph/typegraph/build_result)
- implements completion/hover/definition/diagnostics handlers
- Utilities: `src/atopile/lsp/lsp_utils.py`
- Optional debugging helper: `src/atopile/lsp/_debug_server.py`
## Dependants (Call Sites)
- **VSCode Extension**: The designated client for this server.
- **Compiler**: The LSP invokes the compiler (often in a partial or fault-tolerant mode) to understand the code structure.
## How to Work With / Develop / Test
### Core Concepts
- **Partial Compilation**: Unlike the CLI build, the LSP must handle broken or incomplete code without crashing.
- **Latency**: Features must be fast (<50ms for typing, <200ms for completion).
- **Per-document graphs**: each open document has an isolated `GraphView` + `TypeGraph` stored in `DocumentState`.
- **Keep last good build**: the server keeps the last successful `BuildFileResult` to power completion/hover even when the current edit has errors.
### Development Workflow
1) Edit handlers/helpers in `src/atopile/lsp/lsp_server.py`.
2) Run completion tests (fast loop) and verify GraphView cleanup paths.
### Testing
- Integration-style tests: `ato dev test --llm test/test_lsp_completion.py -q`
## Best Practices
- **Robustness**: Never let the server crash. Catch all exceptions in handlers and log them.
- **Debouncing**: Don't trigger expensive operations on every keystroke.
## Core Invariants (easy to regress)
- Always destroy old graphs on rebuild/reset (`DocumentState.reset_graph` calls `GraphView.destroy()`).
- Do not assume builds succeed; most features must handle:
- syntax errors (ANTLR)
- partial typegraphs
- exceptions from linking/deferred execution
章节与文件索引
按说明文件中的顺序排列。
快速入门
相关文件
家属(呼叫站点)
核心概念
开发流程
文件/命令 -> lsp · src/atopile/lsp/ · ato · src/atopile/lsp/lsp_server.py · LSP_SERVER · LanguageServer · DocumentState · src/atopile/lsp/lsp_utils.py
内容校验值 -> 81d561a5f974
当前原文的自动摘译,尚未人工审校。
快速入门
在 stdio 上运行服务器(编辑者所期望的):
相关文件
服务器实现:
src/atopile/lsp/lsp_server.py拥有全局LSP_SERVER(pyglsLanguageServer) 维护每个文档DocumentState(graph/typegraph/build_result) 实现完成/悬停/定义/诊断处理程序 实用程序:src/atopile/lsp/lsp_utils.py家属(呼叫站点)
VSCode 扩展:该服务器的指定客户端。编译器:LSP 调用编译器(通常以部分或容错模式)来理解代码结构。
核心概念
部分编译:与 CLI 构建不同,LSP 必须处理损坏或不完整的代码而不崩溃。延迟:功能必须很快(打字 <50 毫秒,完成 <200 毫秒)。每个文档图表:每个打开的文档都有一个独立的
GraphView+TypeGraph存储在DocumentState中。保留最后的良好构建:即使当前编辑有错误,服务器也会保留上次成功的BuildFileResult以完成/悬停。开发流程
在
src/atopile/lsp/lsp_server.py中编辑处理程序/助手。运行完成测试(快速循环)并验证 GraphView 清理路径。