From ef37ebbbd036f3a0b5803b024288b94140ed89e7 Mon Sep 17 00:00:00 2001 From: groupguanfang <1203970284@qq.com> Date: Mon, 22 Sep 2025 03:47:34 +0800 Subject: [PATCH 1/2] 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 --- .gitmodules | 3 + grammars.yml | 2 + lib/linguist/languages.yml | 10 + samples/ArkTS/EntryAbility.ets | 44 +++++ samples/ArkTS/EntryBackupAbility.ets | 16 ++ samples/ArkTS/Index.ets | 191 ++++++++++++++++++++ vendor/README.md | 1 + vendor/grammars/ArkTS | 1 + vendor/licenses/git_submodule/ArkTS.dep.yml | 10 + 9 files changed, 278 insertions(+) create mode 100644 samples/ArkTS/EntryAbility.ets create mode 100644 samples/ArkTS/EntryBackupAbility.ets create mode 100644 samples/ArkTS/Index.ets create mode 100644 vendor/grammars/ArkTS create mode 100644 vendor/licenses/git_submodule/ArkTS.dep.yml diff --git a/.gitmodules b/.gitmodules index b624f58166..d061a86d94 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,9 @@ [submodule "vendor/grammars/Alloy.tmbundle"] path = vendor/grammars/Alloy.tmbundle url = https://github.com/macekond/Alloy.tmbundle +[submodule "vendor/grammars/ArkTS"] + path = vendor/grammars/ArkTS + url = https://github.com/ohosvscode/arkTS [submodule "vendor/grammars/Assembly-Syntax-Definition"] path = vendor/grammars/Assembly-Syntax-Definition url = https://github.com/calculuswhiz/Assembly-Syntax-Definition diff --git a/grammars.yml b/grammars.yml index a55124190e..c7e5a2b06f 100644 --- a/grammars.yml +++ b/grammars.yml @@ -4,6 +4,8 @@ vendor/grammars/AL: - source.al vendor/grammars/Alloy.tmbundle: - source.alloy +vendor/grammars/ArkTS: +- source.ets vendor/grammars/Assembly-Syntax-Definition: - source.x86 vendor/grammars/Atom-PostScript: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 7df856d938..d7edb7ebe2 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -404,6 +404,16 @@ Arc: tm_scope: none ace_mode: text language_id: 20 +ArkTS: + type: programming + color: "#3178c6" + extensions: + - ".ets" + tm_scope: source.ets + ace_mode: typescript + codemirror_mode: javascript + codemirror_mime_type: application/typescript + language_id: 56341321 AsciiDoc: type: prose color: "#73a0c5" diff --git a/samples/ArkTS/EntryAbility.ets b/samples/ArkTS/EntryAbility.ets new file mode 100644 index 0000000000..a66373c6dd --- /dev/null +++ b/samples/ArkTS/EntryAbility.ets @@ -0,0 +1,44 @@ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/samples/ArkTS/EntryBackupAbility.ets b/samples/ArkTS/EntryBackupAbility.ets new file mode 100644 index 0000000000..c67027d18c --- /dev/null +++ b/samples/ArkTS/EntryBackupAbility.ets @@ -0,0 +1,16 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} diff --git a/samples/ArkTS/Index.ets b/samples/ArkTS/Index.ets new file mode 100644 index 0000000000..e52b812c19 --- /dev/null +++ b/samples/ArkTS/Index.ets @@ -0,0 +1,191 @@ +import { hilog } from '@kit.PerformanceAnalysisKit' + +@Entry +@Component +struct Index { + @State currentTime: string = '' + @State isConnected: boolean = false + @State systemInfo: SystemInfo | null = null + + aboutToAppear() { + this.updateTime() + this.checkNetworkStatus() + this.getSystemInfo() + + setInterval(() => { + this.updateTime() + }, 1000) + } + + build() { + Column() { + // 顶部状态栏 + this.buildStatusBar() + + // 主要内容区域 + this.buildMainContent() + + // 底部操作区域 + this.buildActionArea() + } + .width('100%') + .height('100%') + .backgroundColor('#F5F5F5') + .padding(16) + } + + @Builder + buildStatusBar() { + Row() { + Text('My App') + .fontSize(18) + .fontWeight(FontWeight.Bold) + .fontColor('#333333') + + Blank() + + Row() { + Image("icon.png") + .width(16) + .height(16) + .fillColor(this.isConnected ? '#00C851' : '#FF4444') + + Text(this.isConnected ? 'Connected' : 'Disconnected') + .fontSize(12) + .fontColor(this.isConnected ? '#00C851' : '#FF4444') + .margin({ left: 4 }) + } + } + .width('100%') + .padding({ bottom: 16 }) + } + + @Builder + buildMainContent() { + Column() { + // 时间显示 + Text(this.currentTime) + .fontSize(32) + .fontWeight(FontWeight.Bold) + .fontColor('#007AFF') + .margin({ bottom: 24 }) + + // 系统信息卡片 + if (this.systemInfo) { + this.buildSystemInfoCard() + } + + // 功能按钮区域 + this.buildFeatureButtons() + } + .width('100%') + .layoutWeight(1) + .justifyContent(FlexAlign.Center) + } + + @Builder + buildSystemInfoCard() { + Column() { + Text('System information') + .fontSize(16) + .fontWeight(FontWeight.Medium) + .margin({ bottom: 12 }) + + Row() { + Text('Device model:') + .fontSize(14) + .fontColor('#666666') + + Text(this.systemInfo?.deviceModel || 'Unknown') + .fontSize(14) + .fontColor('#333333') + .margin({ left: 8 }) + } + .width('100%') + .justifyContent(FlexAlign.SpaceBetween) + .margin({ bottom: 8 }) + + Row() { + Text('System version:') + .fontSize(14) + .fontColor('#666666') + + Text(this.systemInfo?.osVersion || 'Unknown') + .fontSize(14) + .fontColor('#333333') + .margin({ left: 8 }) + } + .width('100%') + .justifyContent(FlexAlign.SpaceBetween) + } + .width('100%') + .backgroundColor(Color.White) + .borderRadius(12) + .padding(16) + .margin({ bottom: 24 }) + } + + @Builder + buildFeatureButtons() { + Row() { + Button('Refresh status') + .onClick(() => { + this.checkNetworkStatus() + this.getSystemInfo() + }) + .backgroundColor('#007AFF') + .borderRadius(8) + .layoutWeight(1) + .margin({ right: 8 }) + + Button('Settings') + .onClick(() => { + hilog.info(0x0000, 'testTag', 'Navigate to settings...') + }) + .backgroundColor(Color.Transparent) + .border({ width: 1, color: '#007AFF' }) + .borderRadius(8) + .layoutWeight(1) + } + .width('100%') + } + + @Builder + buildActionArea() { + Row() { + Text('My footer') + .fontSize(12) + .fontColor('#999999') + } + .width('100%') + .justifyContent(FlexAlign.Center) + } + + private updateTime() { + const now = new Date() + this.currentTime = now.toLocaleTimeString('zh-CN', { + hour12: false, + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }) + } + + private checkNetworkStatus() { + this.isConnected = Math.random() > 0.3 + } + + private getSystemInfo() { + this.systemInfo = { + deviceModel: 'HarmonyOS Device', + osVersion: 'HarmonyOS 6.0.0', + apiLevel: 20 + } + } +} + +interface SystemInfo { + deviceModel: string + osVersion: string + apiLevel: number +} diff --git a/vendor/README.md b/vendor/README.md index f4a226d74e..dfadcf5cf2 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -40,6 +40,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting - **Apex:** [forcedotcom/apex-tmLanguage](https://github.com/forcedotcom/apex-tmLanguage) - **Apollo Guidance Computer:** [Alhadis/language-agc](https://github.com/Alhadis/language-agc) - **AppleScript:** [textmate/applescript.tmbundle](https://github.com/textmate/applescript.tmbundle) +- **ArkTS:** [ohosvscode/arkTS](https://github.com/ohosvscode/arkTS) - **AsciiDoc:** [zuckschwerdt/asciidoc.tmbundle](https://github.com/zuckschwerdt/asciidoc.tmbundle) - **AspectJ:** [pchaigno/sublime-aspectj](https://github.com/pchaigno/sublime-aspectj) - **Assembly:** [Nessphoro/sublimeassembly](https://github.com/Nessphoro/sublimeassembly) diff --git a/vendor/grammars/ArkTS b/vendor/grammars/ArkTS new file mode 100644 index 0000000000..325bd4218b --- /dev/null +++ b/vendor/grammars/ArkTS @@ -0,0 +1 @@ +Subproject commit 107a21c78819540405549c9e65d9447d313c165a diff --git a/vendor/licenses/git_submodule/ArkTS.dep.yml b/vendor/licenses/git_submodule/ArkTS.dep.yml new file mode 100644 index 0000000000..831f8da602 --- /dev/null +++ b/vendor/licenses/git_submodule/ArkTS.dep.yml @@ -0,0 +1,10 @@ +--- +name: ArkTS +version: 107a21c78819540405549c9e65d9447d313c165a +type: git_submodule +homepage: https://github.com/ohosvscode/arkTS +license: mit +licenses: +- sources: LICENSE + 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." +notices: [] From fc3ffb351310ab353656d9d082686a02c6930254 Mon Sep 17 00:00:00 2001 From: groupguanfang <1203970284@qq.com> Date: Mon, 22 Sep 2025 23:07:52 +0800 Subject: [PATCH 2/2] Update ArkTS color to #0080ff to match ArkTS's official color scheme --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index d7edb7ebe2..120662b148 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -406,7 +406,7 @@ Arc: language_id: 20 ArkTS: type: programming - color: "#3178c6" + color: "#0080ff" extensions: - ".ets" tm_scope: source.ets