Skip to content

Commit d94f797

Browse files
committed
feat: add .ets language support
1 parent f101af5 commit d94f797

8 files changed

Lines changed: 268 additions & 0 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,3 +1530,6 @@
15301530
[submodule "vendor/grammars/zephir-sublime"]
15311531
path = vendor/grammars/zephir-sublime
15321532
url = https://github.com/phalcon/zephir-sublime
1533+
[submodule "vendor/grammars/ArkTS"]
1534+
path = vendor/grammars/ArkTS
1535+
url = https://github.com/ohosvscode/arkTS

grammars.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ vendor/grammars/SublimeXtend:
163163
vendor/grammars/Syntax-highlighting-for-PostCSS:
164164
- source.css.postcss.sugarss
165165
- source.postcss
166+
vendor/grammars/ArkTS:
167+
- source.ets
166168
vendor/grammars/SystemVerilog:
167169
- source.systemverilog
168170
- source.ucfconstraints

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: "#3178c6"
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: 1000001
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

Submodule ArkTS added at 107a21c

0 commit comments

Comments
 (0)