Skip to content

Commit 123da5b

Browse files
committed
feat(javascript): add language and frameworks to AutoPageContext.build #81
Add language and frameworks parameters to the `AutoPageContext.build` function in the `AutoPageContext.kt` file. This allows the function to accept the language and frameworks information from the `JsDependenciesSnapshot` in the `AutoPageAction.kt` file. The language and frameworks are then passed to the `AutoPageContext` object, which is used in the `AutoPageFlow` and `AutoPageTask` classes. This change enables the professional Frontend developer to choose the best components for the user based on the selected language and frameworks.
1 parent bbb480b commit 123da5b

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

docs/workflow/auto-page.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: default
3-
title: Frontend Flow
3+
title: AutoPage
44
nav_order: 3
55
parent: Workflow
66
---
@@ -34,6 +34,8 @@ data class AutoPageContext(
3434
var components: List<String>,
3535
val componentNames: List<String>,
3636
val routes: List<String>,
37+
val frameworks: List<String> = listOf("React"),
38+
val language: String = "JavaScript",
3739
)
3840
```
3941

@@ -43,8 +45,9 @@ Clarify:
4345

4446
You are a professional Frontend developer.
4547
According to the user's requirements, you should choose the best components for the user in List.
46-
47-
- Framework: React
48+
49+
- Framework: ${context.frameworks}
50+
- Language: ${context.language}
4851
- User component: ${context.componentNames}, ${context.pageNames}
4952

5053
For example:
@@ -67,6 +70,8 @@ Design:
6770
You are a professional Frontend developer.
6871
According to the user's requirements, and Components info, write Component for the user.
6972

73+
- Framework: ${context.frameworks}
74+
- Language: ${context.language}
7075
- User Components Infos: ${context.components}
7176

7277
For example:

docs/workflow/auto-sql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: default
3-
title: Gen SQL Flow
3+
title: AutoSQL
44
nav_order: 2
55
parent: Workflow
66
---

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cc.unitmesh.devti.AutoDevBundle
44
import cc.unitmesh.devti.gui.sendToChatPanel
55
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
66
import cc.unitmesh.devti.llms.LlmFactory
7+
import cc.unitmesh.ide.javascript.JsDependenciesSnapshot
78
import cc.unitmesh.ide.javascript.flow.model.AutoPageContext
89
import cc.unitmesh.ide.javascript.flow.AutoPageFlow
910
import cc.unitmesh.ide.javascript.flow.AutoPageTask
@@ -29,11 +30,15 @@ class AutoPageAction : ChatBaseIntention() {
2930
if (editor == null || file == null) return
3031
val selectedText = editor.selectionModel.selectedText ?: return
3132

33+
val snapshot = JsDependenciesSnapshot.create(project, file)
34+
val language = snapshot.language()
35+
val frameworks = snapshot.mostPopularFrameworks()
36+
3237
val reactAutoPage = ReactAutoPage(project, selectedText, editor)
3338

3439
sendToChatPanel(project) { contentPanel, _ ->
3540
val llmProvider = LlmFactory().create(project)
36-
val context = AutoPageContext.build(reactAutoPage)
41+
val context = AutoPageContext.build(reactAutoPage, language, frameworks)
3742
val prompter = AutoPageFlow(context, contentPanel, llmProvider)
3843

3944
val task = AutoPageTask(project, prompter, editor, reactAutoPage)

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/model/AutoPageContext.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ data class AutoPageContext(
99
var components: List<String>,
1010
val componentNames: List<String>,
1111
val routes: List<String>,
12+
val frameworks: List<String> = listOf("React"),
13+
val language: String = "JavaScript",
1214
) {
1315
companion object {
14-
fun build(reactAutoPage: ReactAutoPage): AutoPageContext {
16+
fun build(reactAutoPage: ReactAutoPage, language: String, frameworks: List<String>): AutoPageContext {
1517
return AutoPageContext(
1618
requirement = reactAutoPage.userTask,
1719
pages = reactAutoPage.getPages().map { it.format() },
1820
pageNames = reactAutoPage.getPages().map { it.name },
1921
components = reactAutoPage.getComponents().map { it.format() },
2022
componentNames = reactAutoPage.getComponents().map { it.name },
2123
routes = reactAutoPage.getRoutes().map { "${it.key}${it.value}" },
24+
frameworks = frameworks,
25+
language = language
2226
)
2327
}
2428
}

src/main/resources/genius/page/page-gen-clarify.vm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
You are a professional Frontend developer.
22
According to the user's requirements, you should choose the best components for the user in List.
33

4-
- Framework: React
4+
- Framework: ${context.frameworks}
5+
- Language: ${context.language}
56
- User component: ${context.componentNames}, ${context.pageNames}
67

78
For example:

0 commit comments

Comments
 (0)