Skip to content

Commit

Permalink
feat: try to use refs
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 6, 2023
1 parent 6b79923 commit ce3c671
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -16,8 +16,8 @@
</a>
</p>

> AutoDev 是一款高度自动化的 AI 辅助编程工具。AutoDev 能够与您的需求管理系统(例如 Jira、Trello、Github Issue 等)直接对接。在
> IDE 中,您只需简单点击,AutoDev 会根据您的需求自动为您生成代码。您所需做的,仅仅是对生成的代码进行质量检查。
> 🧙‍♂️ AutoDev: The AI-powered coding wizard with multilingual support 🌐, auto code generation 🏗️, and a helpful
> bug-slaying assistant 🐞! Customizable prompts 🎨 and a magic Auto Testing feature 🧪 included! 🚀
features:

Expand Down
@@ -1,15 +1,20 @@
package cc.unitmesh.devti.actions.chat

import cc.unitmesh.devti.editor.LLMCoroutineScopeService
import cc.unitmesh.devti.getElementToAction
import cc.unitmesh.devti.gui.chat.ChatActionType
import cc.unitmesh.devti.gui.sendToChatWindow
import cc.unitmesh.devti.provider.ContextPrompter
import cc.unitmesh.devti.provider.context.ChatContextProvider
import cc.unitmesh.devti.provider.context.ChatCreationContext
import cc.unitmesh.devti.provider.context.ChatOrigin
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
import kotlinx.coroutines.launch

class ExplainBusinessAction : ChatBaseAction() {
override fun getActionType(): ChatActionType {
Expand All @@ -18,20 +23,30 @@ class ExplainBusinessAction : ChatBaseAction() {

override fun actionPerformed(event: AnActionEvent) {
val project = event.project ?: return
val caretModel = event.getData(CommonDataKeys.EDITOR)?.caretModel
val file = event.getData(CommonDataKeys.PSI_FILE)

val actionType = getActionType()
val editor = event.getData(CommonDataKeys.EDITOR) ?: return
val elementToChat = getElementToAction(project, editor) ?: return
val offset = caretModel?.offset ?: 0
val elementText = elementToChat.text
val creationContext = ChatCreationContext(ChatOrigin.ChatAction, actionType, file, listOf(), elementToChat)

sendToChatWindow(project, actionType) { panel, service ->
val prompter = ContextPrompter.prompter(file?.language?.displayName ?: "")
prompter.initContext(actionType, elementText, file, project, offset, elementToChat)
val lang = file?.language?.displayName ?: ""
val instruction = actionType.instruction(lang)

service.handlePromptAndResponse(panel, prompter)
LLMCoroutineScopeService.scope(project).launch {
var chatContext = ""

val contextItems = ChatContextProvider.collectChatContextList(project, creationContext)
contextItems.forEach {
chatContext += it.text + "\n" + elementText + "\n"
}

if (chatContext.isEmpty()) {
chatContext = elementText
}

println(instruction)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/cc/unitmesh/devti/context/MethodContext.kt
Expand Up @@ -19,7 +19,6 @@ class MethodContext(
) : NamedElementContext(
root, text, name
) {

private val classContext: ClassContext?

init {
Expand Down
Expand Up @@ -23,7 +23,7 @@ class AutoDevToolWindowFactory : ToolWindowFactory, DumbAware {
val contentPanel = ChatCodingPanel(chatCodingService, disposable)
val content =
ContentFactory.getInstance().createContent(contentPanel, AutoDevBundle.message("autodev.flow"), false)
toolWindow.getContentManager().addContent(content)
toolWindow.contentManager.addContent(content)
}

override fun init(toolWindow: ToolWindow) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/META-INF/autodev-core.xml
Expand Up @@ -190,10 +190,10 @@
description="Ask AutoDev create DDL code">
</action>

<action id="c.unitmesh.devti.actions.chat.ExplainBusinessAction"
class="cc.unitmesh.devti.actions.chat.ExplainBusinessAction" text="Explain Business"
description="Ask AutoDev explain with business">
</action>
<!-- <action id="c.unitmesh.devti.actions.chat.ExplainBusinessAction"-->
<!-- class="cc.unitmesh.devti.actions.chat.ExplainBusinessAction" text="Explain Business"-->
<!-- description="Ask AutoDev explain with business">-->
<!-- </action>-->

<add-to-group group-id="EditorPopupMenu" anchor="first"/>
</group>
Expand Down

0 comments on commit ce3c671

Please sign in to comment.