Skip to content

Commit 1c949f9

Browse files
committed
refactor: extract for uiqck prompts
1 parent bfda334 commit 1c949f9

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/221/main/kotlin/cc/unitmesh/devti/intentions/IntentionHelperUtil.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ object IntentionHelperUtil {
3434
CustomDocumentationIntention.create(it)
3535
} ?: emptyList()
3636

37-
val teamPromptsIntentions: List<IntentionAction> = project.service<TeamPromptsBuilder>().build().map {
37+
val teamPromptsIntentions: List<IntentionAction> = project.service<TeamPromptsBuilder>().default().map {
3838
TeamPromptIntention.create(it)
3939
}
4040

4141
val actionList = builtinIntentions + customActionIntentions + livingDocIntentions + teamPromptsIntentions
42-
return actionList.map { it as AbstractChatIntention }.sortedByDescending { it.priority() }
42+
return actionList
43+
.map { it as AbstractChatIntention }
44+
.sortedByDescending(AbstractChatIntention::priority)
4345
}
4446
}

src/main/kotlin/cc/unitmesh/devti/custom/team/TeamPromptsBuilder.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,30 @@ import com.intellij.openapi.application.runReadAction
55
import com.intellij.openapi.components.Service
66
import com.intellij.openapi.project.Project
77
import com.intellij.openapi.project.guessProjectDir
8+
import com.intellij.openapi.vfs.VirtualFile
89

910
@Service(Service.Level.PROJECT)
1011
class TeamPromptsBuilder(private val project: Project) {
1112
val settings = project.teamPromptsSettings
12-
fun build(): List<TeamPromptAction> {
13+
fun default(): List<TeamPromptAction> {
1314
val path = settings.state.teamPromptsDir
1415
val promptsDir = project.guessProjectDir()?.findChild(path) ?: return emptyList()
1516

16-
return promptsDir.children.filter { it.name.endsWith(".vm") }.map {
17+
val filterPrompts = promptsDir.children.filter { it.name.endsWith(".vm") }
18+
return buildPrompts(filterPrompts)
19+
}
20+
21+
fun quickPrompts(): List<TeamPromptAction> {
22+
val baseDir = settings.state.teamPromptsDir
23+
val promptsDir = project.guessProjectDir()?.findChild(baseDir) ?: return emptyList()
24+
val quickPromptDir = promptsDir.findChild("quick") ?: return emptyList()
25+
val quickPromptFiles = quickPromptDir.children.filter { it.name.endsWith(".vm") }
26+
27+
return buildPrompts(quickPromptFiles)
28+
}
29+
30+
private fun buildPrompts(prompts: List<VirtualFile>): List<TeamPromptAction> {
31+
return prompts.map {
1732
// a prompt should be named as <actionName>.vm, and we need to replace - with " "
1833
val promptName = it.nameWithoutExtension.replace("-", " ")
1934
// load content of the prompt file

0 commit comments

Comments
 (0)