Skip to content

Commit d16e6fa

Browse files
committed
refactor(configuration): move string read/write logic to DevInsConfiguration #332
- Delete TextContextPrompter.kt and move its logic to ContextPrompter.kt - Extract string read/write methods into DevInsConfiguration.kt - Simplify MvcContextService.kt by removing unused imports and refactoring controllerPrompt logic
1 parent e24a0fb commit d16e6fa

File tree

6 files changed

+20
-82
lines changed

6 files changed

+20
-82
lines changed

core/src/main/kotlin/cc/unitmesh/devti/pair/arch/ProjectPackageTree.kt

Lines changed: 0 additions & 37 deletions
This file was deleted.

core/src/main/kotlin/cc/unitmesh/devti/pair/arch/TreeNode.kt

Lines changed: 0 additions & 29 deletions
This file was deleted.

core/src/main/kotlin/cc/unitmesh/devti/provider/ContextPrompter.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,7 @@ abstract class ContextPrompter : LazyExtensionInstance<ContextPrompter>() {
144144
}
145145
}
146146

147+
class TextContextPrompter(val prompt: String) : ContextPrompter() {
148+
override fun displayPrompt(): String = prompt
149+
override fun requestPrompt(): String = prompt
150+
}

core/src/main/kotlin/cc/unitmesh/devti/provider/TextContextPrompter.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/run/DevInsConfiguration.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package cc.unitmesh.devti.language.run
22

33
import cc.unitmesh.devti.language.DevInBundle
44
import cc.unitmesh.devti.language.DevInIcons
5-
import cc.unitmesh.devti.runconfig.config.readString
6-
import cc.unitmesh.devti.runconfig.config.writeString
75
import com.intellij.execution.Executor
86
import com.intellij.execution.configurations.*
97
import com.intellij.execution.runners.ExecutionEnvironment
@@ -53,3 +51,15 @@ class DevInsConfiguration(project: Project, factory: ConfigurationFactory, name:
5351

5452
var showConsole: Boolean = true
5553
}
54+
55+
fun Element.writeString(name: String, value: String) {
56+
val opt = Element("option")
57+
opt.setAttribute("name", name)
58+
opt.setAttribute("value", value)
59+
addContent(opt)
60+
}
61+
62+
fun Element.readString(name: String): String? =
63+
children
64+
.find { it.name == "option" && it.getAttributeValue("name") == name }
65+
?.getAttributeValue("value")

java/src/main/kotlin/cc/unitmesh/idea/flow/MvcContextService.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cc.unitmesh.idea.flow
22

3-
import cc.unitmesh.devti.context.model.DtClass
4-
import cc.unitmesh.idea.formatPsi
5-
import cc.unitmesh.idea.fromJavaFile
3+
import cc.unitmesh.idea.context.JavaClassContextBuilder
64
import com.intellij.openapi.application.runReadAction
75
import com.intellij.openapi.project.Project
86
import com.intellij.psi.JavaPsiFacade
@@ -64,19 +62,17 @@ class MvcContextService(private val project: Project) {
6462
}
6563

6664
fun controllerPrompt(psiFile: PsiFile?): String {
67-
val file = psiFile as? PsiJavaFileImpl
65+
val file = psiFile as? PsiJavaFileImpl ?: return ""
6866
val context = prepareControllerContext(file)
6967
val services = context?.services?.distinctBy { it.qualifiedName }
7068
val models = context?.models?.distinctBy { it.qualifiedName }
7169

7270
val relevantModel = (services ?: emptyList()) + (models ?: emptyList())
7371

74-
val clazz = fromJavaFile(file)
75-
7672
val classList = relevantModel.map {
77-
DtClass.Companion.formatPsi(it, clazz.packageName ?: "")
73+
JavaClassContextBuilder().getClassContext(file, false)?.format() ?: return@map ""
7874
}
7975

80-
return "\n${classList.joinToString("\n")}\n//current path: ${clazz.path}\n"
76+
return "\n${classList.joinToString("\n")}\n//current path: ${file.virtualFile.path}\n"
8177
}
8278
}

0 commit comments

Comments
 (0)