Skip to content

Commit 2a5801c

Browse files
committed
refactor(prompting): simplify code and add TODO comment
- Renamed `postProcessors` to `devInProcessor` for clarity. - Simplified `collectFrameworkContext` by removing redundant file lookup. - Added a TODO comment for future enhancement in `SketchToolWindow`.
1 parent 2a78bfb commit 2a5801c

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ abstract class SimpleDevinPrompter {
2222
abstract val template: String
2323

2424
fun prompting(project: Project, userInput: String, editor: Editor?): String {
25-
/// handle with Velocity
2625
val variableCompile = VariableTemplateCompiler.create(project, editor)
2726
if (variableCompile == null) {
2827
val frameworkContext = collectFrameworkContext(editor, project)
@@ -31,7 +30,6 @@ abstract class SimpleDevinPrompter {
3130
return templateRender.renderTemplate(template)
3231
}
3332

34-
/// handle with DevIn language
3533
val postProcessors = LanguagePromptProcessor.devin()
3634
val compiledTemplate = postProcessors?.compile(project, template) ?: template
3735

@@ -41,12 +39,7 @@ abstract class SimpleDevinPrompter {
4139

4240
fun collectFrameworkContext(myEditor: Editor?, project: Project): String {
4341
val editor = myEditor ?: FileEditorManager.getInstance(project).selectedTextEditor ?: return ""
44-
val file = FileDocumentManager.getInstance().getFile(editor.document)
45-
val psiFile = runReadAction {
46-
return@runReadAction file?.let { _ ->
47-
return@let PsiDocumentManager.getInstance(project).getPsiFile(editor.document)
48-
}
49-
}
42+
val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.document)
5043

5144
val element = getElementToAction(project, editor)
5245
val creationContext =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class SketchInputListener(
5252
}
5353

5454
override fun manualSend(userInput: String) {
55-
val postProcessors = LanguagePromptProcessor.devin()
56-
val compiledInput = runReadAction { postProcessors?.compile(project, userInput) } ?: userInput
55+
val devInProcessor = LanguagePromptProcessor.devin()
56+
val compiledInput = runReadAction { devInProcessor?.compile(project, userInput) } ?: userInput
5757

5858
toolWindow.addRequestPrompt(compiledInput)
5959

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ class SketchToolWindow(val project: Project, val editor: Editor?, private val sh
158158
chatCodingService.clearSession()
159159
}
160160

161+
/**
162+
* Todo: add to all component lsit
163+
*/
161164
fun addRequestPrompt(text: String) {
162165
runInEdt {
163166
val codeBlockViewer = CodeHighlightSketch(project, text, PlainTextLanguage.INSTANCE).apply {

0 commit comments

Comments
 (0)