Skip to content

Commit

Permalink
feat: fix no prompter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jul 18, 2023
1 parent b1e8ddb commit e667582
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 14 deletions.
Expand Up @@ -16,7 +16,7 @@ import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiManager

class JavaContextPrompter : ContextPrompter {
class JavaContextPrompter : ContextPrompter() {
private var additionContext: String = ""
private val autoDevSettingsState = AutoDevSettingsState.getInstance()
private var promptConfig: PromptConfig? = null
Expand Down
5 changes: 4 additions & 1 deletion idea/src/main/resources/cc.unitmesh.idea.xml
Expand Up @@ -18,7 +18,10 @@
<variableContextBuilder language="JAVA"
implementationClass="cc.unitmesh.ide.idea.context.JavaVariableContextBuilder"/>

<contextPrompter implementation="cc.unitmesh.ide.idea.provider.JavaContextPrompter"/>
<contextPrompter
language="JAVA"
implementation="cc.unitmesh.ide.idea.provider.JavaContextPrompter"/>

<techStackProvider implementation="cc.unitmesh.ide.idea.provider.JavaTechStackService"/>
<devFlowProvider implementation="cc.unitmesh.ide.idea.provider.JavaAutoDevFlow"/>
<promptStrategy implementation="cc.unitmesh.ide.idea.provider.PromptStrategyAdvisor"/>
Expand Down
Expand Up @@ -7,7 +7,7 @@ import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile

class PythonContextPrompter : ContextPrompter {
class PythonContextPrompter : ContextPrompter() {
private var action: ChatBotActionType? = null
private var selectedText: String = ""
private var file: PsiFile? = null
Expand Down
5 changes: 4 additions & 1 deletion pycharm/src/main/resources/cc.unitmesh.pycharm.xml
Expand Up @@ -14,7 +14,10 @@
<variableContextBuilder language="Python"
implementationClass="cc.unitmesh.ide.pycharm.context.PythonVariableContextBuilder"/>

<contextPrompter implementation="cc.unitmesh.ide.pycharm.provider.PythonContextPrompter"/>
<contextPrompter
language="Python"
implementation="cc.unitmesh.ide.pycharm.provider.PythonContextPrompter"/>

<techStackProvider implementation="cc.unitmesh.ide.pycharm.provider.PythonTechStackService"/>
<devFlowProvider implementation="cc.unitmesh.ide.pycharm.provider.PythonAutoDevFlow"/>
<promptStrategy implementation="cc.unitmesh.ide.pycharm.provider.PythonPromptStrategyAdvisor"/>
Expand Down
Expand Up @@ -45,7 +45,7 @@ abstract class ChatBaseAction : AnAction() {

val actionType = chatCodingService.actionType

val prompter = ContextPrompter.prompter()
val prompter = ContextPrompter.prompter(file?.language?.displayName ?: "")
prompter?.initContext(actionType, prefixText, file, project)

toolWindowManager?.activate {
Expand Down
Expand Up @@ -151,7 +151,7 @@ class ChatCodingComponent(private val chatCodingService: ChatCodingService) : JB
val context = ChatContext(null, "", "")

chatCodingService.actionType = ChatBotActionType.REFACTOR
chatCodingService.handlePromptAndResponse(this, object : ContextPrompter {
chatCodingService.handlePromptAndResponse(this, object : ContextPrompter() {
override fun getUIPrompt() = prompt
override fun getRequestPrompt() = prompt
}, context)
Expand Down
Expand Up @@ -58,7 +58,7 @@ abstract class AbstractChatIntention : IntentionAction {
contentManager.removeAllContents(true)
contentManager.addContent(content)
toolWindowManager.activate {
val prompter = ContextPrompter.prompter()
val prompter = ContextPrompter.prompter(file?.language?.displayName ?: "")
prompter?.initContext(actionType, selectedText, file, project)

chatCodingService.handlePromptAndResponse(contentPanel, prompter!!)
Expand Down
37 changes: 32 additions & 5 deletions src/main/kotlin/cc/unitmesh/devti/provider/ContextPrompter.kt
@@ -1,20 +1,47 @@
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
import com.intellij.serviceContainer.LazyExtensionInstance
import com.intellij.util.xmlb.annotations.Attribute

interface ContextPrompter {
fun getUIPrompt(): String
fun getRequestPrompt(): String
fun initContext(actionType: ChatBotActionType, prefixText: String, file: PsiFile?, project: Project) {}
abstract class ContextPrompter : LazyExtensionInstance<ContextPrompter>() {
@Attribute("language")
var language: String? = null

@Attribute("implementationClass")
var implementationClass: String? = null

override fun getImplementationClassName(): String? {
return implementationClass
}

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

companion object {
private val EP_NAME: ExtensionPointName<ContextPrompter> =
ExtensionPointName.create("cc.unitmesh.contextPrompter")

fun prompter(): ContextPrompter? = EP_NAME.extensionList.firstOrNull()
private val logger = Logger.getInstance(ContextPrompter::class.java)

fun prompter(lang: String): ContextPrompter? {
val extensionList = EP_NAME.extensionList
val contextPrompter = extensionList.filter {
it.language?.lowercase() == lang.lowercase()
}

return if (contextPrompter.isEmpty()) {
extensionList.first()
} else {
contextPrompter.first()
}
}
}
}

Expand Up @@ -5,7 +5,7 @@ import cc.unitmesh.devti.provider.ContextPrompter
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile

class JavaScriptContextPrompter : ContextPrompter {
class JavaScriptContextPrompter : ContextPrompter() {
private var action: ChatBotActionType? = null
private var selectedText: String = ""
private var file: PsiFile? = null
Expand Down
4 changes: 3 additions & 1 deletion webstorm/src/main/resources/cc.unitmesh.webstorm.xml
Expand Up @@ -5,7 +5,9 @@
</dependencies>

<extensions defaultExtensionNs="cc.unitmesh">
<contextPrompter implementation="cc.unitmesh.ide.webstorm.provider.JavaScriptContextPrompter"/>
<contextPrompter
language="JavaScript"
implementation="cc.unitmesh.ide.webstorm.provider.JavaScriptContextPrompter"/>
<techStackProvider implementation="cc.unitmesh.ide.webstorm.provider.JavaScriptTechStackService"/>
<devFlowProvider implementation="cc.unitmesh.ide.webstorm.provider.JavaScriptAutoDevFlow"/>
<promptStrategy implementation="cc.unitmesh.ide.webstorm.provider.JavaScriptPromptStrategyAdvisor"/>
Expand Down

0 comments on commit e667582

Please sign in to comment.