@@ -3,6 +3,7 @@ package cc.unitmesh.devti.sketch
3
3
import cc.unitmesh.devti.agent.tool.search.RipgrepSearcher
4
4
import cc.unitmesh.devti.gui.chat.message.ChatActionType
5
5
import cc.unitmesh.devti.gui.chat.ui.relativePath
6
+ import cc.unitmesh.devti.mcp.host.Response
6
7
import cc.unitmesh.devti.provider.BuildSystemProvider
7
8
import cc.unitmesh.devti.provider.context.ChatContextItem
8
9
import cc.unitmesh.devti.provider.context.ChatContextProvider
@@ -17,6 +18,7 @@ import com.intellij.openapi.diagnostic.logger
17
18
import com.intellij.openapi.editor.Editor
18
19
import com.intellij.openapi.fileEditor.FileDocumentManager
19
20
import com.intellij.openapi.fileEditor.FileEditorManager
21
+ import com.intellij.openapi.module.ModuleManager
20
22
import com.intellij.openapi.project.Project
21
23
import com.intellij.openapi.project.ProjectManager
22
24
import com.intellij.openapi.project.guessProjectDir
@@ -44,6 +46,7 @@ data class SketchRunContext(
44
46
val buildTool : String = " " ,
45
47
val searchTool : String = " localSearch" ,
46
48
val rule : String = " " ,
49
+ val moduleInfo : String = " " ,
47
50
) : TemplateContext {
48
51
companion object {
49
52
suspend fun create (project : Project , myEditor : Editor ? , input : String ): SketchRunContext {
@@ -87,6 +90,8 @@ data class SketchRunContext(
87
90
" "
88
91
}
89
92
93
+ val moduleInfo = moduleContext(project)
94
+
90
95
return SketchRunContext (
91
96
currentFile = currentFile?.relativePath(project),
92
97
currentElement = currentElement,
@@ -101,8 +106,37 @@ data class SketchRunContext(
101
106
buildTool = buildTool,
102
107
searchTool = lookupSearchTool(),
103
108
rule = rule,
109
+ moduleInfo = moduleInfo,
104
110
)
105
111
}
112
+
113
+ private val JAVA_ONE_PROJECT_SIZE_IN_IDEA = 2
114
+ fun moduleContext (project : Project ): String {
115
+ val moduleManager = ModuleManager .getInstance(project)
116
+ val allModules = moduleManager.modules.map { it.name }
117
+ if (allModules.size <= JAVA_ONE_PROJECT_SIZE_IN_IDEA ) {
118
+ return " "
119
+ }
120
+
121
+ val rootProjectName = allModules.minByOrNull { it.length } ? : return " "
122
+
123
+ val cleanedModules = allModules
124
+ .filter { it != rootProjectName && ! it.endsWith(" .test" ) }
125
+ .map { moduleName ->
126
+ moduleName
127
+ .removePrefix(" $rootProjectName ." )
128
+ .removeSuffix(" .main" )
129
+ }
130
+ .distinct() // Remove duplicates after cleaning
131
+ .filter { it.isNotEmpty() } // Remove any empty strings that might result
132
+
133
+ return if (cleanedModules.isNotEmpty()) {
134
+ val modules = cleanedModules.joinToString(" , " ) { it }
135
+ " - This project is a mono-repo projects, Please careful to create file in module. Here's modules: $modules "
136
+ } else {
137
+ " "
138
+ }
139
+ }
106
140
}
107
141
}
108
142
@@ -130,3 +164,4 @@ private fun workspace(myProject: Project? = null): String {
130
164
val project = myProject ? : ProjectManager .getInstance().openProjects.firstOrNull()
131
165
return project?.guessProjectDir()?.path ? : " "
132
166
}
167
+
0 commit comments