diff --git a/src/main/kotlin/ee/carlrobert/codegpt/codecompletions/CodeCompletionRequestFactory.kt b/src/main/kotlin/ee/carlrobert/codegpt/codecompletions/CodeCompletionRequestFactory.kt index f6b9f168..9c91e081 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/codecompletions/CodeCompletionRequestFactory.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/codecompletions/CodeCompletionRequestFactory.kt @@ -6,7 +6,7 @@ import com.intellij.openapi.components.service import ee.carlrobert.codegpt.completions.llama.LlamaModel import ee.carlrobert.codegpt.credentials.CredentialsStore.CredentialKey import ee.carlrobert.codegpt.credentials.CredentialsStore.getCredential -import ee.carlrobert.codegpt.settings.configuration.Placeholder +import ee.carlrobert.codegpt.settings.configuration.Placeholder.* import ee.carlrobert.codegpt.settings.service.codegpt.CodeGPTServiceSettings import ee.carlrobert.codegpt.settings.service.custom.CustomServiceSettings import ee.carlrobert.codegpt.settings.service.llama.LlamaSettings @@ -140,11 +140,16 @@ object CodeCompletionRequestFactory { details: InfillRequestDetails ): Any { if (value !is String) return value + return when (value) { - "$" + Placeholder.FIM_PROMPT -> template.buildPrompt(details) - "$" + Placeholder.PREFIX -> details.prefix - "$" + Placeholder.SUFFIX -> details.suffix - else -> value + FIM_PROMPT.code -> template.buildPrompt(details) + PREFIX.code -> details.prefix + SUFFIX.code -> details.suffix + else -> { + return value.takeIf { it.contains(PREFIX.code) || it.contains(SUFFIX.code) } + ?.replace(PREFIX.code, details.prefix) + ?.replace(SUFFIX.code, details.suffix) ?: value + } } } @@ -158,4 +163,4 @@ object CodeCompletionRequestFactory { } private fun isBoundaryCharacter(c: Char): Boolean = c in "()[]{}<>~!@#$%^&*-+=|\\;:'\",./?" -} +} \ No newline at end of file diff --git a/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/Placeholder.kt b/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/Placeholder.kt index 20f8ce15..7ac7145b 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/Placeholder.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/Placeholder.kt @@ -5,12 +5,15 @@ import git4idea.GitUtil import git4idea.branch.GitBranchUtil import java.time.LocalDate -enum class Placeholder(val description: String) { - DATE_ISO_8601("Current date in ISO 8601 format, e.g. 2021-01-01."), - BRANCH_NAME("The name of the current branch."), - PREFIX("Code before the cursor."), - SUFFIX("Code after the cursor."), - FIM_PROMPT("Prebuilt Fill-In-The-Middle (FIM) prompt using the specified template."), +enum class Placeholder(val description: String, val code: String) { + DATE_ISO_8601("Current date in ISO 8601 format, e.g. 2021-01-01.", "$" + "DATE_ISO_8601"), + BRANCH_NAME("The name of the current branch.", "$" + "BRANCH_NAME"), + PREFIX("Code before the cursor.", "$" + "PREFIX"), + SUFFIX("Code after the cursor.", "$" + "SUFFIX"), + FIM_PROMPT( + "Prebuilt Fill-In-The-Middle (FIM) prompt using the specified template.", + "$" + "FIM_PROMPT" + ), } interface PlaceholderStrategy {