Skip to content

Commit 8ab56f1

Browse files
committed
feat(sketch): add current and opened files to context #257
- Display current and opened files in the sketch context. - Update `SketchRunContext` to use `String` for `currentFile` and include `openedFiles`. - Modify template files to reflect these changes.
1 parent 591b66e commit 8ab56f1

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

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

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

33
import cc.unitmesh.devti.gui.chat.message.ChatActionType
4+
import cc.unitmesh.devti.gui.chat.ui.relativePath
45
import cc.unitmesh.devti.provider.context.ChatContextItem
56
import cc.unitmesh.devti.provider.context.ChatContextProvider
67
import cc.unitmesh.devti.provider.context.ChatCreationContext
@@ -20,9 +21,9 @@ import kotlinx.coroutines.runBlocking
2021
import java.text.SimpleDateFormat
2122

2223
data class SketchRunContext(
23-
val currentFile: VirtualFile?,
24+
val currentFile: String?,
2425
val currentElement: PsiElement? = null,
25-
val selectedFile: List<VirtualFile>,
26+
val openedFiles: List<VirtualFile>,
2627
val relatedFiles: List<VirtualFile>,
2728
val workspace: String = workspace(),
2829
val os: String = osInfo(),
@@ -41,6 +42,8 @@ data class SketchRunContext(
4142
FileEditorManager.getInstance(project).selectedFiles.firstOrNull()
4243
}
4344

45+
val otherFiles = FileEditorManager.getInstance(project).selectedFiles.filter { it != currentFile }
46+
4447
val psi = if (currentFile != null) {
4548
PsiManager.getInstance(project).findFile(currentFile)
4649
} else {
@@ -57,9 +60,9 @@ data class SketchRunContext(
5760
ChatCreationContext(ChatOrigin.Intention, ChatActionType.CHAT, psi, listOf(), element = psi)
5861

5962
return SketchRunContext(
60-
currentFile = currentFile,
63+
currentFile = currentFile?.relativePath(project),
6164
currentElement = currentElement,
62-
selectedFile = emptyList(),
65+
openedFiles = otherFiles,
6366
relatedFiles = emptyList(),
6467
userInput = input,
6568
workspace = workspace(project),

core/src/main/resources/genius/en/code/sketch.vm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Your main goal is to follow the USER's instructions at each message.
1515
- The user's shell is ${context.shell}
1616
- User's workspace context is: ${context.frameworkContext}
1717
- Current time is: ${context.time}
18+
- Current open file is: ${context.currentFile}, other open files are: ${context.openedFiles}
1819

1920
Steps will be run asynchronously, so sometimes you will not yet see that steps
2021
are still running. If you need to see the output of previous tools before

core/src/main/resources/genius/zh/code/sketch.vm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Your main goal is to follow the USER's instructions at each message.
1515
- The user's shell is ${context.shell}
1616
- User's workspace context is: ${context.frameworkContext}
1717
- Current time is: ${context.time}
18+
- Current open file is: ${context.currentFile}, other open files are: ${context.openedFiles}
1819

1920
Steps will be run asynchronously, so sometimes you will not yet see that steps
2021
are still running. If you need to see the output of previous tools before

0 commit comments

Comments
 (0)