Skip to content

Commit da4852e

Browse files
committed
feat(harmonyos): add JS and CPP PSI modules
Added two PSI modules for self-developed JavaScript and C++ in the HarmonyOS extension. Also included the JS and CPP classes for reference: `com.huawei.ace.language.psi.impl.JavaScriptIdentifierNameImpl` and `com.huawei.ideacpp.psi.impl.CPPIdentifierImpl`. These modules are essential for the new language support, legacy system migration, and the new UI framework. They will be used in HiStudio, a self-developed IDE, and no additional functionality is needed in AutoDev for now. Support for ArkTS has been maintained as well.
1 parent 91317d1 commit da4852e

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

exts/ext-harmonyos/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
# HarmonyOS Extension
22

33
openharmony/lib/ohos-info-center-plugin-3.1.0.501, API Reference,可惜使用的是远程 API 。
4-
openharmony/lib/javascript-3.1.0.501.jar, 自研 JavaScript 模块
5-
4+
openharmony/lib/javascript-3.1.0.501.jar, 自研 JavaScript PSI 模块
5+
openharmony/lib/ohos-cpp-lsp-client-3.1.0.501.jar, 自研 C++ PSI 模块
66

7+
JS 类:`class class com.huawei.ace.language.psi.impl.JavaScriptIdentifierNameImpl`
8+
CPP 类:`class class com.huawei.ideacpp.psi.impl.CPPIdentifierImpl`
79

810
## 设计思念
911

1012
三个新要素:新的语言、遗留系统迁移、新的 UI 框架。
1113

14+
而且结合源码中 HiStudio 等信息的存在,我猜这会是一个自研的 IDE,所以暂时不会在 AutoDev 添加一些额外新的功能。
15+
16+
而在标准的 JetBrains 是以 ObjectiveC 作为抽象,所以又存在一系列的差异,又会是一个新的头疼问题,诸如于:
17+
18+
CCELanguage, CLanguage, CPPLanguage,所以理由上拿到 CannonicalName 会是一个更好的选择。
19+
1220
## ArkTS 支持
1321

1422
>

exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/provider/HarmonyOSChatContextProvider.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@ package cc.unitmesh.harmonyos.provider
33
import cc.unitmesh.devti.provider.context.ChatContextItem
44
import cc.unitmesh.devti.provider.context.ChatContextProvider
55
import cc.unitmesh.devti.provider.context.ChatCreationContext
6+
import com.intellij.openapi.diagnostic.logger
67
import com.intellij.openapi.project.Project
78

89
class HarmonyOSChatContextProvider : ChatContextProvider {
10+
val logger = logger<HarmonyOSChatContextProvider>()
11+
912
override fun isApplicable(project: Project, creationContext: ChatCreationContext): Boolean {
1013
return System.getProperty("idea.platform.prefix", "idea") == "DevEcoStudio"
1114
}
1215

1316
override suspend fun collect(project: Project, creationContext: ChatCreationContext): List<ChatContextItem> {
1417
var context = "This project is a HarmonyOS project."
1518

16-
val languageName = creationContext.element?.language?.displayName
19+
val languageName = creationContext.sourceFile?.language?.displayName
20+
21+
logger.info("context: $context")
1722

1823
if (languageName == "TypeScript" || languageName == "JavaScript" || languageName == "ArkTS") {
19-
context += "Which use TypeScript as the main language, and use Flutter like UI framework."
24+
context += "Which use TypeScript (ArkTS) as the main language, and use Flutter like TypeScript UI framework."
25+
} else {
26+
val className = creationContext.sourceFile?.language?.displayName
27+
if (className == "CPP" || className == "C/C" || className == "CCE") {
28+
context += "Which use C++ as the main language, and NAPI for building native Addons."
29+
}
2030
}
2131

2232
return listOf(ChatContextItem(HarmonyOSChatContextProvider::class, context))
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package cc.unitmesh.devti.provider.builtin
22

3-
import com.intellij.temporary.similar.chunks.SimilarChunksWithPaths
43
import cc.unitmesh.devti.provider.ContextPrompter
4+
import cc.unitmesh.devti.provider.context.ChatCreationContext
5+
import cc.unitmesh.devti.provider.context.ChatOrigin
56
import com.intellij.psi.PsiFile
7+
import kotlinx.coroutines.runBlocking
68

79
class DefaultContextPrompter : ContextPrompter() {
810
private var similarChunkCache: MutableMap<PsiFile, String?> = mutableMapOf()
@@ -15,14 +17,20 @@ class DefaultContextPrompter : ContextPrompter() {
1517
}
1618

1719
private fun getPrompt(): String {
18-
if (file == null) {
19-
return "$action\n```${lang}\n$selectedText\n```"
20+
var additionContext: String
21+
runBlocking {
22+
val creationContext = ChatCreationContext(ChatOrigin.ChatAction, action!!, file, emptyList(), null)
23+
additionContext = collectionContext(creationContext)
2024
}
2125

22-
if (file !in similarChunkCache) {
23-
similarChunkCache[file!!] = SimilarChunksWithPaths.createQuery(file!!)
26+
if (file == null) {
27+
return "$action\n$additionContext\n```${lang}\n$selectedText\n```"
2428
}
2529

26-
return "$action\n```${lang}\n${similarChunkCache[file!!]}\n$selectedText\n```"
30+
// if (file !in similarChunkCache) {
31+
// similarChunkCache[file!!] = SimilarChunksWithPaths.createQuery(file!!)
32+
// }
33+
34+
return "$action\n```${lang}\n$selectedText\n```"
2735
}
2836
}

src/main/kotlin/cc/unitmesh/devti/provider/context/ChatContextProvider.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface ChatContextProvider {
3434
e.printStackTrace()
3535
}
3636
}
37+
3738
elements.addAll(chatCreationContext.extraItems)
3839
return elements.distinctBy { it.text }
3940
}

0 commit comments

Comments
 (0)