Skip to content

Commit

Permalink
feat: add offset for handle prompt text
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jul 20, 2023
1 parent 174afea commit 5bdf188
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 13 deletions.
Expand Up @@ -14,9 +14,9 @@ class KotlinContextPrompter : ContextPrompter() {
private var project: Project? = null
private var lang: String = ""

override fun initContext(actionType: ChatBotActionType, prefixText: String, file: PsiFile?, project: Project) {
override fun initContext(actionType: ChatBotActionType, text: String, file: PsiFile?, project: Project, offset: Int) {
this.action = actionType
this.selectedText = prefixText
this.selectedText = text
this.file = file
this.project = project
this.lang = file?.language?.displayName ?: ""
Expand Down
Expand Up @@ -33,9 +33,9 @@ class JavaContextPrompter : ContextPrompter() {
private val isService = fileName.endsWith("Service.java") || fileName.endsWith("ServiceImpl.java")
private lateinit var changeListManager: ChangeListManager

override fun initContext(actionType: ChatBotActionType, prefixText: String, file: PsiFile?, project: Project) {
override fun initContext(actionType: ChatBotActionType, text: String, file: PsiFile?, project: Project, offset: Int) {
this.action = actionType
this.prefixText = prefixText
this.prefixText = text
this.file = file
this.project = project
changeListManager = ChangeListManagerImpl.getInstance(project)
Expand Down
Expand Up @@ -14,9 +14,9 @@ class PythonContextPrompter : ContextPrompter() {
private var project: Project? = null
private var lang: String = ""

override fun initContext(actionType: ChatBotActionType, prefixText: String, file: PsiFile?, project: Project) {
override fun initContext(actionType: ChatBotActionType, text: String, file: PsiFile?, project: Project, offset: Int) {
this.action = actionType
this.selectedText = prefixText
this.selectedText = text
this.file = file
this.project = project
this.lang = file?.language?.displayName ?: ""
Expand Down
Expand Up @@ -53,7 +53,7 @@ abstract class ChatBaseAction : AnAction() {

val prompter = ContextPrompter.prompter(file?.language?.displayName ?: "")
logger.info("use prompter: ${prompter?.javaClass}")
prompter?.initContext(actionType, prefixText, file, project)
prompter?.initContext(actionType, prefixText, file, project, caretModel?.offset ?: 0)

toolWindowManager?.activate {
val chatContext = ChatContext(
Expand Down
Expand Up @@ -52,7 +52,7 @@ abstract class AbstractChatIntention : IntentionAction {


val prompter = ContextPrompter.prompter(file.language.displayName)
prompter?.initContext(actionType, selectedText, file, project)
prompter?.initContext(actionType, selectedText, file, project, editor.caretModel.offset)
sendToChat(project, actionType, prompter!!)
}

Expand Down
@@ -1,8 +1,6 @@
package cc.unitmesh.devti.provider

import cc.unitmesh.devti.gui.chat.ChatBotActionType
import cc.unitmesh.devti.prompting.model.PromptConfig
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile
Expand All @@ -22,7 +20,7 @@ abstract class ContextPrompter : LazyExtensionInstance<ContextPrompter>() {

open fun getUIPrompt(): String = ""
open fun getRequestPrompt(): String = ""
open fun initContext(actionType: ChatBotActionType, prefixText: String, file: PsiFile?, project: Project) {}
open fun initContext(actionType: ChatBotActionType, text: String, file: PsiFile?, project: Project, offset: Int) {}

companion object {
private val EP_NAME: ExtensionPointName<ContextPrompter> =
Expand Down
Expand Up @@ -12,9 +12,9 @@ class JavaScriptContextPrompter : ContextPrompter() {
private var project: Project? = null

private val lang: String = file?.language?.displayName ?: ""
override fun initContext(actionType: ChatBotActionType, prefixText: String, file: PsiFile?, project: Project) {
override fun initContext(actionType: ChatBotActionType, text: String, file: PsiFile?, project: Project, offset: Int) {
this.action = actionType
this.selectedText = prefixText
this.selectedText = text
this.file = file
this.project = project
}
Expand Down

0 comments on commit 5bdf188

Please sign in to comment.