Skip to content

Commit 76bcefc

Browse files
committed
feat(javascript): add ReactFlow pages retrieval
Add functionality to retrieve pages from ReactFlow in the GenComponentAction class. This is done by creating an instance of ReactFlow and calling the getPages() method. The retrieved pages are then printed to the console. Additionally, some variable names were updated for clarity.
1 parent 457bf89 commit 76bcefc

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class GenComponentAction : ChatBaseIntention() {
2222
if (editor == null || file == null) return
2323
val selectedText = editor.selectionModel.selectedText ?: return
2424

25-
ReactFlow(project, selectedText, editor)
25+
val reactFlow = ReactFlow(project, selectedText, editor)
26+
val pages = reactFlow.getPages()
27+
28+
println(pages)
2629
}
2730
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cc.unitmesh.ide.javascript.flow
33
import com.intellij.lang.ecmascript6.JSXHarmonyFileType
44
import com.intellij.lang.javascript.JavaScriptFileType
55
import com.intellij.lang.javascript.TypeScriptJSXFileType
6+
import com.intellij.lang.javascript.dialects.TypeScriptJSXLanguageDialect
7+
import com.intellij.lang.javascript.frameworks.react.ReactJSXImplementation
68
import com.intellij.lang.javascript.psi.JSFile
79
import com.intellij.openapi.editor.Editor
810
import com.intellij.openapi.project.Project
@@ -26,7 +28,7 @@ class ReactFlow(
2628
private val pages: MutableList<JSFile> = mutableListOf()
2729
private val components: MutableList<JSFile> = mutableListOf()
2830

29-
// confg files
31+
// config files
3032
private val configs: MutableList<JSFile> = mutableListOf()
3133

3234
init {
@@ -42,6 +44,8 @@ class ReactFlow(
4244
FileTypeIndex.getFiles(TypeScriptJSXFileType.INSTANCE, searchScope) +
4345
FileTypeIndex.getFiles(JSXHarmonyFileType.INSTANCE, searchScope)
4446

47+
val root = project.guessProjectDir()!!
48+
4549
virtualFiles.forEach {
4650
val path = it.canonicalFile?.path ?: return@forEach
4751

@@ -58,7 +62,9 @@ class ReactFlow(
5862
}
5963

6064
else -> {
61-
configs.add(jsFile)
65+
if (root.findChild(it.name) != null) {
66+
configs.add(jsFile)
67+
}
6268
}
6369
}
6470
}
@@ -73,7 +79,14 @@ class ReactFlow(
7379
override fun getPages(): List<DsComponent> {
7480
val result = mutableListOf<DsComponent>()
7581
pages.forEach {
82+
when(it.language) {
83+
is TypeScriptJSXLanguageDialect -> {
84+
val context = ReactJSXImplementation().getContext(it)
85+
if (ReactJSXImplementation().isApplicable(it)) {
7686

87+
}
88+
}
89+
}
7790
}
7891

7992
return result

src/222/main/kotlin/cc/unitmesh/devti/intentions/IntentionHelperUtil.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ object IntentionHelperUtil {
2727

2828
val promptConfig = CustomPromptConfig.load()
2929
val customActionIntentions: List<IntentionAction> = promptConfig.prompts.map {
30-
CustomActionIntention.create(it)
30+
CustomActionBaseIntention.create(it)
3131
}
3232

3333
val livingDocIntentions: List<IntentionAction> = promptConfig.documentations?.map {
34-
CustomDocumentationIntention.create(it)
34+
CustomDocumentationBaseIntention.create(it)
3535
} ?: emptyList()
3636

3737
val teamPromptsIntentions: List<IntentionAction> = project.service<TeamPromptsBuilder>().default().map {
38-
TeamPromptIntention.create(it, true)
38+
TeamPromptBaseIntention.create(it, true)
3939
}
4040

4141
val actionList = builtinIntentions + customActionIntentions + livingDocIntentions + teamPromptsIntentions
4242
return actionList
43-
.map { it as AbstractChatIntention }
44-
.sortedByDescending(AbstractChatIntention::priority)
43+
.map { it as ChatBaseIntention }
44+
.sortedByDescending(ChatBaseIntention::priority)
4545
}
4646
}

0 commit comments

Comments
 (0)