Implement code formatting support for Zed ArkTS extension - #7
Conversation
Co-authored-by: liuyanghejerry <345442+liuyanghejerry@users.noreply.github.com>
Co-authored-by: liuyanghejerry <345442+liuyanghejerry@users.noreply.github.com>
Co-authored-by: liuyanghejerry <345442+liuyanghejerry@users.noreply.github.com>
Co-authored-by: liuyanghejerry <345442+liuyanghejerry@users.noreply.github.com>
|
Zed是否有格式化的自定义命令?我们能否将其与LSP的格式化对接?@copilot |
Co-authored-by: liuyanghejerry <345442+liuyanghejerry@users.noreply.github.com>
Zed 目前没有提供扩展级别的自定义格式化命令 API。所有格式化功能都是通过配置实现的,而不是通过扩展代码。 与 LSP 格式化的对接方式扩展通过以下方式与格式化系统对接:
扩展开发者只需确保语言服务器提供格式化功能,Zed 会自动处理集成。详细信息已添加到文档的第 10 节"自定义格式化命令与 LSP 集成"。 commit: 9a3e770 |
Co-authored-by: liuyanghejerry <345442+liuyanghejerry@users.noreply.github.com>
已实现。语言服务器包装器现在会自动将标准的 LSP 格式化请求转发到
这样用户可以直接使用 Zed 的标准格式化功能,无需额外配置。文档已更新说明这个实现。 commit: 236aa31 Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot 去掉docs/FORMATTING.md以及对应的英文版文档 |
|
@copilot languages/arkts/config.toml 不进行变更。ets语法与ts并不相同。 |
Co-authored-by: liuyanghejerry <345442+liuyanghejerry@users.noreply.github.com>
|
@copilot 基于仓库已有的自动化测试能力,尝试增加代码格式化相关的自动化测试用例。 |
Co-authored-by: liuyanghejerry <345442+liuyanghejerry@users.noreply.github.com>
已完成代码格式化相关的自动化测试用例。新增内容包括: 测试文件:
测试覆盖:
运行方式: # 使用 npm 脚本
cd zed-ets-language-server
npm run test:formatting
# 或使用 shell 脚本
./scripts/test-formatting.sh所有 14 个测试用例均通过验证。 commit: b3e2688 |
|
@copilot 格式化是否成功,应当看文件的内容是否变成了格式化后的内容,而不仅仅是断言LSP结构 |
Co-authored-by: liuyanghejerry <345442+liuyanghejerry@users.noreply.github.com>
已增强测试以验证实际格式化内容。新增内容包括: 内容验证测试 (
测试固件:
测试覆盖: 现在共有 24 个测试用例,包括:
所有测试均通过,验证格式化功能不仅在协议层面正确,而且在实际内容层面也产生正确的格式化输出。 commit: b9fe433 |
|
@copilot 测试失败[4/6] Requesting definition... [5/6] Requesting references... [6/6] Requesting completion... === Finalizing results === ✓ Results saved to /tmp/lsp-e2e-results.json === Test Summary === === Individual Results === |
这个测试失败与格式化代码更改无关。失败的是 E2E LSP 测试中的 definition、references 和 completion 功能,而不是格式化测试。 验证结果:
E2E 测试失败原因:
建议:
|
- Changed `on.pull_request.branches` to `"*"`.
Replaces direct npx call with npm run test:formatting. This allows for easier management and potential overrides of the formatting test command in the package.json.
Remove standalone formatting test script and integrate into CI. Update README accordingly.
Co-authored-by: liuyanghejerry <345442+liuyanghejerry@users.noreply.github.com>
已优化 CI 工作流配置以避免重复执行。 修改内容:
效果:
这样可以减少 CI 资源消耗,加快 PR 检查速度。 commit: 7e9ae45 |
…liuyanghejerry/zed-arkts into copilot/research-zed-language-extension

Implements custom formatting request forwarding for the ArkTS language server to enable seamless code formatting in Zed, with comprehensive automated testing that validates actual formatting results.
Implementation
Language Server Wrapper
zed-ets-language-server/index.jswrapper automatically forwards standard LSP formatting requests to ArkTS's customets/formatDocumentendpoint:textDocument/formatting→ets/formatDocumenttextDocument/rangeFormatting→ets/formatDocumentAutomated Testing
Formatting Test Suite
npm run test:formatting # or ./scripts/test-formatting.shTest Coverage
textDocument/formattingtoets/formatDocumenttextDocument/rangeFormattingtoets/formatDocumentCI/CD Optimization
ci.ymlande2e-automated.ymlto prevent duplicate workflow runs on pull requestsmainanddevelopbranches for push eventsmainanddeveloppushandpull_requestevents on the same PR)Documentation
Configuration
languages/arkts/config.tomlremains unchanged as ETS syntax differs from TypeScriptsettings.jsonif desiredDevelopment Notes
Research Completed
Changes Made
ets/formatDocumentThe implementation enables seamless code formatting for ArkTS files in Zed while maintaining compatibility with the language server's custom formatting endpoint. Tests validate not just LSP protocol correctness, but actual formatting results.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.