lsp 代码排查
- 作者仓库星标 3,367
- 许可证 MIT
- 作者仓库 atopile
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):
python -m atopile.lsp.lsp_server
Relevant Files
- Server implementation:
src/atopile/lsp/lsp_server.py- owns global
LSP_SERVER(pyglsLanguageServer) - maintains per-document
DocumentState(graph/typegraph/build_result) - implements completion/hover/definition/diagnostics handlers
- owns global
- 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+TypeGraphstored inDocumentState. - Keep last good build: the server keeps the last successful
BuildFileResultto power completion/hover even when the current edit has errors.
Development Workflow
- Edit handlers/helpers in
src/atopile/lsp/lsp_server.py. - 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_graphcallsGraphView.destroy()). - Do not assume builds succeed; most features must handle:
- syntax errors (ANTLR)
- partial typegraphs
- exceptions from linking/deferred execution
- 流狐分类
- 通用
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 94 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @atopile · MIT
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 需简单配置
- 是否需要外部 API Key
- 未发现要求
- 检测到的系统要求
- 未声明
- 底层运行要求
- Python
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 检测到的网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
作者没有在当前 SKILL.md 中定义固定输出样例。 Quick Start
Run the server on stdio (what editors expect):
Development Workflow
Edit handlers/helpers in src/atopile/lsp/lspserver.py. Run completion tests (fast loop) and verify GraphView cleanup paths.
# 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
… 证据边界与执行链路
作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> Quick Start → Relevant Files → Dependants (Call Sites) → How to Work With / Develop / Test → Core Concepts → Development Workflow
要点 -> VSCode Extension · Compiler · Partial Compilation · Latency · Per-document graphs · Keep last good build · Robustness · Debouncing
文件/命令 -> lsp · src/atopile/lsp/ · ato · src/atopile/lsp/lspserver.py · LSPSERVER · LanguageServer · DocumentState · src/atopile/lsp/lsputils.py
内容 SHA-256 -> 81d561a5f974
方法与流程
适用与边界
原文中的明确线索
lsp、src/atopile/lsp/、ato、src/atopile/lsp/lspserver.py、LSPSERVER、LanguageServer、DocumentState、src/atopile/lsp/lsputils.py