generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(provider): add templated test prompts
This commit adds a new feature to the provider module. It introduces a `TemplatedTestPrompt` class that allows users to lookup template files for test prompts. The class is responsible for retrieving the template code from the specified file and returning it as a string. This feature enhances the functionality of the provider module by providing users with pre-defined templates for test prompts, making it easier to write test cases.
- Loading branch information
Showing
4 changed files
with
78 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/cc/unitmesh/devti/custom/test/TemplatedTestPrompt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cc.unitmesh.devti.custom.test | ||
|
||
import cc.unitmesh.devti.settings.custom.teamPromptsSettings | ||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.project.guessProjectDir | ||
|
||
@Service(Service.Level.PROJECT) | ||
class TemplatedTestPrompt(private val project: Project) { | ||
val settings = project.teamPromptsSettings | ||
|
||
fun lookup(fileName: String): String? { | ||
val path = settings.state.teamPromptsDir | ||
val promptsDir = project.guessProjectDir()?.findChild(path) ?: return null | ||
val templateFile = promptsDir.findChild(fileName) ?: return null | ||
|
||
val templateCode = templateFile.children.firstOrNull { it.name.endsWith(".vm") } ?: return null | ||
return templateCode.inputStream.readBytes().toString(Charsets.UTF_8) | ||
} | ||
} |