Skip to content

Commit ddb96de

Browse files
committed
feat(javascript): add GenComponentAction and GenComponentFlow #81
Add GenComponentAction and GenComponentFlow classes to handle generating components in JavaScript files. The GenComponentAction class is responsible for initiating the generation process when a specific text is selected in the editor. The GenComponentFlow class handles the flow of generating the component and interacts with the user through a chat coding panel.
1 parent dce72fb commit ddb96de

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/actions/GenComponentAction.kt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package cc.unitmesh.ide.javascript.actions
22

33
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.gui.chat.ChatCodingPanel
5+
import cc.unitmesh.devti.gui.sendToChatPanel
46
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
7+
import cc.unitmesh.devti.llms.LLMProvider
8+
import cc.unitmesh.devti.llms.LlmFactory
59
import cc.unitmesh.ide.javascript.flow.ReactAutoPage
610
import cc.unitmesh.ide.javascript.util.LanguageApplicableUtil
711
import com.intellij.openapi.editor.Editor
12+
import com.intellij.openapi.progress.ProgressIndicator
13+
import com.intellij.openapi.progress.ProgressManager
14+
import com.intellij.openapi.progress.Task
15+
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
816
import com.intellij.openapi.project.Project
917
import com.intellij.psi.PsiFile
1018

@@ -23,8 +31,25 @@ class GenComponentAction : ChatBaseIntention() {
2331
val selectedText = editor.selectionModel.selectedText ?: return
2432

2533
val reactAutoPage = ReactAutoPage(project, selectedText, editor)
26-
val pages = reactAutoPage.getPages()
34+
sendToChatPanel(project) { contentPanel, _ ->
35+
val llmProvider = LlmFactory().create(project)
36+
val prompter = GenComponentFlow(reactAutoPage, contentPanel, llmProvider)
37+
38+
val task = GenComponentTask(project, prompter, editor)
39+
ProgressManager.getInstance()
40+
.runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
41+
}
42+
43+
}
44+
}
45+
46+
class GenComponentTask(val project: Project, val prompter: GenComponentFlow, val editor: Editor) :
47+
Task.Backgroundable(project, "Gen Component", true) {
48+
override fun run(indicator: ProgressIndicator) {
2749

28-
println(pages)
2950
}
3051
}
52+
53+
class GenComponentFlow(val pages: ReactAutoPage, val contentPanel: ChatCodingPanel, val llmProvider: LLMProvider) {
54+
55+
}

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/ReactAutoPage.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,12 @@ class ReactAutoPage(
5555
if (jsFile.isTestFile) return@forEach
5656

5757
when {
58-
path.contains("pages") -> {
59-
buildComponent(jsFile)?.let {
60-
pages += it
61-
}
58+
path.contains("pages") -> buildComponent(jsFile)?.let {
59+
pages += it
6260
}
6361

64-
path.contains("components") -> {
65-
buildComponent(jsFile)?.let {
66-
components += it
67-
}
62+
path.contains("components") -> buildComponent(jsFile)?.let {
63+
components += it
6864
}
6965

7066
else -> {
@@ -74,8 +70,6 @@ class ReactAutoPage(
7470
}
7571
}
7672
}
77-
78-
println("pages: $pages")
7973
}
8074

8175

0 commit comments

Comments
 (0)