Skip to content

Commit 347e912

Browse files
Add ArkTS language support (#7593)
* Add ArkTS language support - Add ArkTS as a new programming language with .ets file extension - Configure syntax highlighting using TextMate grammar from ohosvscode/arkTS - Add real-world ArkTS samples from HarmonyOS development (Index.ets, EntryAbility.ets, EntryBackupAbility.ets) - Set language ID using script/update-ids (56341321) and color to #3178c6 - Configure ace_mode as typescript and codemirror_mode as javascript - Add license information for ArkTS submodule - Update grammars.yml and .gitmodules with proper alphabetical sorting * Update ArkTS color to #0080ff to match ArkTS's official color scheme
1 parent 4239ed7 commit 347e912

File tree

9 files changed

+278
-0
lines changed

9 files changed

+278
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
[submodule "vendor/grammars/Alloy.tmbundle"]
88
path = vendor/grammars/Alloy.tmbundle
99
url = https://github.com/macekond/Alloy.tmbundle
10+
[submodule "vendor/grammars/ArkTS"]
11+
path = vendor/grammars/ArkTS
12+
url = https://github.com/ohosvscode/arkTS
1013
[submodule "vendor/grammars/Assembly-Syntax-Definition"]
1114
path = vendor/grammars/Assembly-Syntax-Definition
1215
url = https://github.com/calculuswhiz/Assembly-Syntax-Definition

grammars.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ vendor/grammars/AL:
44
- source.al
55
vendor/grammars/Alloy.tmbundle:
66
- source.alloy
7+
vendor/grammars/ArkTS:
8+
- source.ets
79
vendor/grammars/Assembly-Syntax-Definition:
810
- source.x86
911
vendor/grammars/Atom-PostScript:

lib/linguist/languages.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,16 @@ Arc:
404404
tm_scope: none
405405
ace_mode: text
406406
language_id: 20
407+
ArkTS:
408+
type: programming
409+
color: "#0080ff"
410+
extensions:
411+
- ".ets"
412+
tm_scope: source.ets
413+
ace_mode: typescript
414+
codemirror_mode: javascript
415+
codemirror_mime_type: application/typescript
416+
language_id: 56341321
407417
AsciiDoc:
408418
type: prose
409419
color: "#73a0c5"

samples/ArkTS/EntryAbility.ets

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
2+
import { hilog } from '@kit.PerformanceAnalysisKit';
3+
import { window } from '@kit.ArkUI';
4+
5+
const DOMAIN = 0x0000;
6+
7+
export default class EntryAbility extends UIAbility {
8+
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
9+
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
10+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
11+
}
12+
13+
onDestroy(): void {
14+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy');
15+
}
16+
17+
onWindowStageCreate(windowStage: window.WindowStage): void {
18+
// Main window is created, set main page for this ability
19+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
20+
21+
windowStage.loadContent('pages/Index', (err) => {
22+
if (err.code) {
23+
hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
24+
return;
25+
}
26+
hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
27+
});
28+
}
29+
30+
onWindowStageDestroy(): void {
31+
// Main window is destroyed, release UI related resources
32+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
33+
}
34+
35+
onForeground(): void {
36+
// Ability has brought to foreground
37+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground');
38+
}
39+
40+
onBackground(): void {
41+
// Ability has back to background
42+
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground');
43+
}
44+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { hilog } from '@kit.PerformanceAnalysisKit';
2+
import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit';
3+
4+
const DOMAIN = 0x0000;
5+
6+
export default class EntryBackupAbility extends BackupExtensionAbility {
7+
async onBackup() {
8+
hilog.info(DOMAIN, 'testTag', 'onBackup ok');
9+
await Promise.resolve();
10+
}
11+
12+
async onRestore(bundleVersion: BundleVersion) {
13+
hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion));
14+
await Promise.resolve();
15+
}
16+
}

samples/ArkTS/Index.ets

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
import { hilog } from '@kit.PerformanceAnalysisKit'
2+
3+
@Entry
4+
@Component
5+
struct Index {
6+
@State currentTime: string = ''
7+
@State isConnected: boolean = false
8+
@State systemInfo: SystemInfo | null = null
9+
10+
aboutToAppear() {
11+
this.updateTime()
12+
this.checkNetworkStatus()
13+
this.getSystemInfo()
14+
15+
setInterval(() => {
16+
this.updateTime()
17+
}, 1000)
18+
}
19+
20+
build() {
21+
Column() {
22+
// 顶部状态栏
23+
this.buildStatusBar()
24+
25+
// 主要内容区域
26+
this.buildMainContent()
27+
28+
// 底部操作区域
29+
this.buildActionArea()
30+
}
31+
.width('100%')
32+
.height('100%')
33+
.backgroundColor('#F5F5F5')
34+
.padding(16)
35+
}
36+
37+
@Builder
38+
buildStatusBar() {
39+
Row() {
40+
Text('My App')
41+
.fontSize(18)
42+
.fontWeight(FontWeight.Bold)
43+
.fontColor('#333333')
44+
45+
Blank()
46+
47+
Row() {
48+
Image("icon.png")
49+
.width(16)
50+
.height(16)
51+
.fillColor(this.isConnected ? '#00C851' : '#FF4444')
52+
53+
Text(this.isConnected ? 'Connected' : 'Disconnected')
54+
.fontSize(12)
55+
.fontColor(this.isConnected ? '#00C851' : '#FF4444')
56+
.margin({ left: 4 })
57+
}
58+
}
59+
.width('100%')
60+
.padding({ bottom: 16 })
61+
}
62+
63+
@Builder
64+
buildMainContent() {
65+
Column() {
66+
// 时间显示
67+
Text(this.currentTime)
68+
.fontSize(32)
69+
.fontWeight(FontWeight.Bold)
70+
.fontColor('#007AFF')
71+
.margin({ bottom: 24 })
72+
73+
// 系统信息卡片
74+
if (this.systemInfo) {
75+
this.buildSystemInfoCard()
76+
}
77+
78+
// 功能按钮区域
79+
this.buildFeatureButtons()
80+
}
81+
.width('100%')
82+
.layoutWeight(1)
83+
.justifyContent(FlexAlign.Center)
84+
}
85+
86+
@Builder
87+
buildSystemInfoCard() {
88+
Column() {
89+
Text('System information')
90+
.fontSize(16)
91+
.fontWeight(FontWeight.Medium)
92+
.margin({ bottom: 12 })
93+
94+
Row() {
95+
Text('Device model:')
96+
.fontSize(14)
97+
.fontColor('#666666')
98+
99+
Text(this.systemInfo?.deviceModel || 'Unknown')
100+
.fontSize(14)
101+
.fontColor('#333333')
102+
.margin({ left: 8 })
103+
}
104+
.width('100%')
105+
.justifyContent(FlexAlign.SpaceBetween)
106+
.margin({ bottom: 8 })
107+
108+
Row() {
109+
Text('System version:')
110+
.fontSize(14)
111+
.fontColor('#666666')
112+
113+
Text(this.systemInfo?.osVersion || 'Unknown')
114+
.fontSize(14)
115+
.fontColor('#333333')
116+
.margin({ left: 8 })
117+
}
118+
.width('100%')
119+
.justifyContent(FlexAlign.SpaceBetween)
120+
}
121+
.width('100%')
122+
.backgroundColor(Color.White)
123+
.borderRadius(12)
124+
.padding(16)
125+
.margin({ bottom: 24 })
126+
}
127+
128+
@Builder
129+
buildFeatureButtons() {
130+
Row() {
131+
Button('Refresh status')
132+
.onClick(() => {
133+
this.checkNetworkStatus()
134+
this.getSystemInfo()
135+
})
136+
.backgroundColor('#007AFF')
137+
.borderRadius(8)
138+
.layoutWeight(1)
139+
.margin({ right: 8 })
140+
141+
Button('Settings')
142+
.onClick(() => {
143+
hilog.info(0x0000, 'testTag', 'Navigate to settings...')
144+
})
145+
.backgroundColor(Color.Transparent)
146+
.border({ width: 1, color: '#007AFF' })
147+
.borderRadius(8)
148+
.layoutWeight(1)
149+
}
150+
.width('100%')
151+
}
152+
153+
@Builder
154+
buildActionArea() {
155+
Row() {
156+
Text('My footer')
157+
.fontSize(12)
158+
.fontColor('#999999')
159+
}
160+
.width('100%')
161+
.justifyContent(FlexAlign.Center)
162+
}
163+
164+
private updateTime() {
165+
const now = new Date()
166+
this.currentTime = now.toLocaleTimeString('zh-CN', {
167+
hour12: false,
168+
hour: '2-digit',
169+
minute: '2-digit',
170+
second: '2-digit'
171+
})
172+
}
173+
174+
private checkNetworkStatus() {
175+
this.isConnected = Math.random() > 0.3
176+
}
177+
178+
private getSystemInfo() {
179+
this.systemInfo = {
180+
deviceModel: 'HarmonyOS Device',
181+
osVersion: 'HarmonyOS 6.0.0',
182+
apiLevel: 20
183+
}
184+
}
185+
}
186+
187+
interface SystemInfo {
188+
deviceModel: string
189+
osVersion: string
190+
apiLevel: number
191+
}

vendor/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
4040
- **Apex:** [forcedotcom/apex-tmLanguage](https://github.com/forcedotcom/apex-tmLanguage)
4141
- **Apollo Guidance Computer:** [Alhadis/language-agc](https://github.com/Alhadis/language-agc)
4242
- **AppleScript:** [textmate/applescript.tmbundle](https://github.com/textmate/applescript.tmbundle)
43+
- **ArkTS:** [ohosvscode/arkTS](https://github.com/ohosvscode/arkTS)
4344
- **AsciiDoc:** [zuckschwerdt/asciidoc.tmbundle](https://github.com/zuckschwerdt/asciidoc.tmbundle)
4445
- **AspectJ:** [pchaigno/sublime-aspectj](https://github.com/pchaigno/sublime-aspectj)
4546
- **Assembly:** [Nessphoro/sublimeassembly](https://github.com/Nessphoro/sublimeassembly)

vendor/grammars/ArkTS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 107a21c78819540405549c9e65d9447d313c165a
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: ArkTS
3+
version: 107a21c78819540405549c9e65d9447d313c165a
4+
type: git_submodule
5+
homepage: https://github.com/ohosvscode/arkTS
6+
license: mit
7+
licenses:
8+
- sources: LICENSE
9+
text: "MIT License\n\nCopyright (c) 2025 Naily Zero\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."
10+
notices: []

0 commit comments

Comments
 (0)