1
1
package cc.unitmesh.devti.custom.team
2
2
3
+ import cc.unitmesh.devti.custom.variable.CustomVariable
3
4
import cc.unitmesh.devti.gui.chat.ChatActionType
4
5
import cc.unitmesh.devti.provider.context.ChatContextProvider
5
6
import cc.unitmesh.devti.provider.context.ChatCreationContext
@@ -22,23 +23,24 @@ class TeamPromptTemplateCompiler(
22
23
val editor : Editor ,
23
24
val selectedText : String = " " ,
24
25
) {
26
+ private val log = logger<TeamPromptTemplateCompiler >()
25
27
private val velocityContext = VelocityContext ()
26
28
27
29
init {
28
- this .set(" selection " , selectedText)
29
- this .set(" beforeCursor " , file.text.substring(0 , editor.caretModel.offset))
30
- this .set(" afterCursor " , file.text.substring(editor.caretModel.offset))
30
+ this .set(CustomVariable . SELECTION .variable , selectedText)
31
+ this .set(CustomVariable . BEFORE_CURSOR .variable , file.text.substring(0 , editor.caretModel.offset))
32
+ this .set(CustomVariable . AFTER_CURSOR .variable , file.text.substring(editor.caretModel.offset))
31
33
}
32
34
33
35
fun set (key : String , value : String ) {
34
36
velocityContext.put(key, value)
35
37
}
36
38
37
39
fun compile (template : String ): String {
38
- velocityContext.put(" fileName " , file.name)
39
- velocityContext.put(" filePath " , file.virtualFile?.path ? : " " )
40
+ velocityContext.put(CustomVariable . FILE_NAME .variable , file.name)
41
+ velocityContext.put(CustomVariable . FILE_PATH .variable , file.virtualFile?.path ? : " " )
40
42
velocityContext.put(
41
- " methodName " , when (element) {
43
+ CustomVariable . METHOD_NAME .variable , when (element) {
42
44
is PsiNameIdentifierOwner -> element.nameIdentifier?.text ? : " "
43
45
else -> " "
44
46
}
@@ -74,16 +76,16 @@ class TeamPromptTemplateCompiler(
74
76
)
75
77
76
78
val collectChatContextList = ChatContextProvider .collectChatContextList(file.project, context)
77
- velocityContext.put(" frameworkContext " , collectChatContextList.joinToString(" \n " ) {
79
+ velocityContext.put(CustomVariable . FRAMEWORK_CONTEXT .variable , collectChatContextList.joinToString(" \n " ) {
78
80
it.text
79
81
})
80
82
}
81
83
}
82
84
83
85
private fun configForLanguage () {
84
- velocityContext.put(" language " , language.displayName)
86
+ velocityContext.put(CustomVariable . LANGUAGE .variable , language.displayName)
85
87
velocityContext.put(
86
- " commentSymbol " , when (language.displayName.lowercase()) {
88
+ CustomVariable . COMMENT_SYMBOL .variable , when (language.displayName.lowercase()) {
87
89
" java" , " kotlin" -> " //"
88
90
" python" -> " #"
89
91
" javascript" -> " //"
@@ -93,8 +95,4 @@ class TeamPromptTemplateCompiler(
93
95
}
94
96
)
95
97
}
96
-
97
- companion object {
98
- val log = logger<TeamPromptTemplateCompiler >()
99
- }
100
98
}
0 commit comments