Skip to content

Commit 2a78bfb

Browse files
committed
refactor(prompt): simplify DevIn processor access
Replace repetitive `LanguagePromptProcessor.instance("DevIn").firstOrNull()` calls with a dedicated `devin()` method for cleaner and more consistent access to the DevIn processor.
1 parent 40131b8 commit 2a78bfb

File tree

6 files changed

+14
-7
lines changed

6 files changed

+14
-7
lines changed

core/src/main/kotlin/cc/unitmesh/devti/agent/CustomAgentChatProcessor.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ class CustomAgentChatProcessor(val project: Project) {
147147
}
148148

149149
if (!devInCode.isNullOrEmpty()) {
150-
LanguagePromptProcessor.instance("DevIn").forEach {
151-
it.execute(project, CustomAgentContext(selectedAgent, devInCode!!))
152-
}
150+
val devin = LanguagePromptProcessor.devin()
151+
devin?.execute(project, CustomAgentContext(selectedAgent, devInCode!!))
153152
}
154153

155154
return llmResponse

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ChatCodingPanel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
114114

115115
val context = ChatContext(null, "", "")
116116

117-
val postProcessors = LanguagePromptProcessor.instance("DevIn").firstOrNull()
117+
val postProcessors = LanguagePromptProcessor.devin()
118118
if (postProcessors != null) {
119119
prompt = postProcessors.compile(chatCodingService.project, prompt)
120120
}

core/src/main/kotlin/cc/unitmesh/devti/prompting/SimpleDevinPrompter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class SimpleDevinPrompter {
3232
}
3333

3434
/// handle with DevIn language
35-
val postProcessors = LanguagePromptProcessor.instance("DevIn").firstOrNull()
35+
val postProcessors = LanguagePromptProcessor.devin()
3636
val compiledTemplate = postProcessors?.compile(project, template) ?: template
3737

3838
variableCompile.set("input", userInput)

core/src/main/kotlin/cc/unitmesh/devti/provider/devins/LanguagePromptProcessor.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ interface LanguagePromptProcessor {
2626
companion object {
2727
val EP_NAME = ExtensionPointName<LanguagePromptProcessor>("cc.unitmesh.languageProcessor")
2828

29-
fun instance(languageName: String): List<LanguagePromptProcessor> {
29+
private fun instance(languageName: String): List<LanguagePromptProcessor> {
3030
return EP_NAME.extensionList.filter { it.name == languageName }
3131
}
32+
33+
fun devin(): LanguagePromptProcessor? {
34+
return instance("DevIn").firstOrNull()
35+
}
3236
}
3337
}

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchInputListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SketchInputListener(
5252
}
5353

5454
override fun manualSend(userInput: String) {
55-
val postProcessors = LanguagePromptProcessor.instance("DevIn").firstOrNull()
55+
val postProcessors = LanguagePromptProcessor.devin()
5656
val compiledInput = runReadAction { postProcessors?.compile(project, userInput) } ?: userInput
5757

5858
toolWindow.addRequestPrompt(compiledInput)

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchRunContext.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import com.intellij.psi.PsiManager
2323
import kotlinx.coroutines.runBlocking
2424
import java.text.SimpleDateFormat
2525

26+
/**
27+
* provide context for [core/src/main/resources/genius/zh/code/sketch.vm]
28+
* make sure the context is serializable and keep same with the template
29+
*/
2630
data class SketchRunContext(
2731
val currentFile: String?,
2832
val currentElement: PsiElement? = null,

0 commit comments

Comments
 (0)