ArkTS Extension
A Zed extension for ArkTS (aka.ETS) development support.
This project is based on Million-mo/tree-sitter-arkts and ohosvscode/arkTS. Thanks for offering an excellent foundation for ArkTS.
Features
- Syntax highlighting: Distinguishes ArkTS declarations, decorators, ArkUI components, methods, properties, types, constants, and resources.
- Outline navigation: Lists components, classes, interfaces, enums, functions, methods, and
buildmethods. - Automatic indentation: Indents ArkTS blocks, component bodies, UI containers, and multiline collections.
- Bracket matching: Matches parentheses, square brackets, and braces.
- Text objects: Selects components/classes, functions/methods, parameters, and comments.
- Language server: Provides basic language server support, such as go to definition and find references.
- HarmonyOS SDK types: Resolves OpenHarmony and HMS
@kit.*declarations from an installed DevEco Studio SDK.

Current Status
This is a Zed language extension that provides:
- File type detection (
.ets→ ETS language) - Syntax highlighting extending TypeScript grammar
- Go to definition
- Find references
- Module definition
- Code formatting support (via Language Server or external tools)
Plans
- Compatible with more Node.js versions.
- Autocomplete.
- JSON5 schemas support for
oh-package.json5.
Non-goals
- Debuggers.
- Code snippets.
- Installing or updating HarmonyOS SDKs.
Installation
From Source
You need a Node.js environment to build this extension. Prefer Node.js 24 currently.
- Clone this repository
- Open extension page in Zed and install extension from directory
Configuration
The extension automatically detects the SDK bundled with DevEco Studio in its
standard installation location and the macOS user SDK directories under
~/Library/OpenHarmony/Sdk and ~/Library/Huawei/Sdk. It also checks versioned
SDK directories and uses the newest installed version when no default SDK is
available.
Explicit settings take precedence over environment variables and automatic detection. Use the following configuration only when DevEco Studio or its SDK is installed in a custom location:
{
"lsp": {
"arkts-language-server": {
"initialization_options": {
"ohosSdkPath": "/path/to/sdk/default/openharmony",
"hmsSdkPath": "/path/to/sdk/default/hms"
}
}
}
}ohosSdkPath: OpenHarmony SDK root containingets/api,ets/kits, andets/build-tools/ets-loader/tsconfig.json.hmsSdkPath: Optional HMS SDK root. When omitted, a siblinghmsdirectory is detected automatically.tsdk: Optional TypeScript declarations directory. The wrapper normally detects theohos-typescriptinstallation automatically.
The corresponding environment variables are ZED_ETS_OHOS_SDK_PATH,
OHOS_SDK_PATH, HARMONYOS_SDK_HOME, OPENHARMONY_SDK_HOME,
DEVECO_SDK_HOME, DEVECO_STUDIO_HOME, DEVECO_HOME,
ZED_ETS_HMS_SDK_PATH, and HMS_SDK_PATH.
If imports such as @kit.AbilityKit report ts 2307, verify that
the configured directory contains openharmony/ets or is the OpenHarmony SDK
root itself. Do not point it directly at the child ets directory. Restart the
language server after changing SDK settings.
Code Formatting
The extension supports code formatting through the language server.
Using Language Server Formatting
The ArkTS language server provides built-in formatting support through the custom ets/formatDocument request. The extension automatically forwards standard LSP formatting requests to this custom endpoint, so no additional configuration is required. Simply use Zed's standard formatting commands (e.g., format on save or manual format).
Using External Formatters (e.g., Prettier)
You can configure external formatters in your settings.json:
{
"languages": {
"ArkTS Language": {
"formatter": {
"external": {
"command": "prettier",
"arguments": ["--stdin-filepath", "{buffer_path}", "--parser", "typescript"]
}
}
}
}
}Development
# Build in development mode
cargo build
# Build for release
cargo build --releaseTesting
This project includes comprehensive fully automated testing for the LSP implementation.
Tree-sitter editing queries are tested against the exact grammar revision from
extension.toml:
npm ci
npm run test:queriesFull E2E Automation (完全自动化)
# Complete end-to-end automated test (no manual steps!)
# 完全自动化端到端测试(无需人工操作!)
./scripts/e2e-automated-test.shThis script automatically:
- ✅ Installs Zed editor
- ✅ Installs OpenHarmony SDK (mock version)
- ✅ Builds and installs the extension
- ✅ Verifies Zed-LSP integration using real Zed CLI
- ✅ Runs automated LSP tests
- ✅ Validates results programmatically
Testing with Real Zed (真实 Zed 测试)
Test with actual Zed CLI and log analysis!
# Test using real Zed editor
# 使用真实 Zed 编辑器测试
./scripts/test-zed-real.sh
# This script:
# - Launches actual Zed with test files
# - Monitors Zed's log files in real-time
# - Detects extension loading and LSP startup
# - Extracts LSP messages from logs
# - Requires Zed to be installedIndividual Automation Scripts
# Install Zed automatically
./scripts/auto-install-zed.sh
# Install extension automatically
./scripts/auto-install-local-extension.sh
# Install OpenHarmony SDK (mock for testing)
./scripts/install-mock-ohos-sdk.sh
# Test with real Zed CLI
./scripts/test-zed-real.sh
# Run automated LSP tests (no GUI required)
./scripts/test-lsp-automated.shCode Formatting Tests
The project includes comprehensive automated tests for the code formatting functionality with actual content validation:
# Run formatting tests only
cd zed-ets-language-server
npm run test:formattingThe formatting tests verify:
- ✅ Actual formatting results: Validates that unformatted code becomes properly formatted
- ✅ TextEdit application: Verifies that formatting edits produce expected output
- ✅ Standard LSP formatting requests are forwarded to
ets/formatDocument - ✅ Range formatting requests are properly handled
- ✅ Formatting options (tab size, spaces vs tabs) are preserved and applied correctly
- ✅ Multiple sequential formatting requests work correctly
- ✅ Formatted code is syntactically valid with proper indentation
- ✅ Edge cases and various formatting configurations
Test Suite: 24 comprehensive test cases including:
- Content validation tests that check actual formatted output
- LSP protocol forwarding tests
- TextEdit structure and application tests
Unit & Integration Tests
# Run all unit tests
cd zed-ets-language-server
npm test
# Run integration tests
npm run test:integration
# Run with coverage
npm run test -- --coverageDocumentation
For detailed information about the automated testing design:
- Automation Design (自动化设计) - High-level design overview
Sample Project
A sample ArkTS project is provided in test-fixtures/arkts-sample-project/ for testing. See Sample Project README for details.
License
MIT License - see LICENSE file for details