Skip to content

Commit

Permalink
Add AskIssueIntention
Browse files Browse the repository at this point in the history
  • Loading branch information
pplam committed Jul 19, 2024
1 parent b29e221 commit a5fb4cc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
39 changes: 39 additions & 0 deletions src/main/kotlin/ai/devchat/plugin/actions/AskIssueIntention.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ai.devchat.plugin.actions

import ai.devchat.core.DevChatActions
import ai.devchat.core.handlers.SendUserMessageHandler
import ai.devchat.plugin.DevChatToolWindow
import com.alibaba.fastjson.JSONObject
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInsight.intention.PriorityAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.psi.PsiFile

class AskIssueIntention : IntentionAction, PriorityAction {
override fun getText(): String = "Ask DevChat"
override fun getFamilyName(): String = "DevChat"
override fun getPriority(): PriorityAction.Priority = PriorityAction.Priority.HIGH
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean {
return true
}
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
editor?.let{
val line = it.document.getLineNumber(it.caretModel.offset)
val lineStartOffset: Int = it.document.getLineStartOffset(line)
val lineEndOffset: Int = it.document.getLineEndOffset(line)
it.selectionModel.setSelection(lineStartOffset, lineEndOffset)
val payload = JSONObject(mapOf("message" to "/ask_issue"))

ToolWindowManager.getInstance(editor.project!!).getToolWindow("DevChat")?.show {
if (DevChatToolWindow.loaded) {
SendUserMessageHandler(DevChatActions.SEND_USER_MESSAGE_REQUEST,null, payload).executeAction()
} else {
SendUserMessageHandler.cache = payload
}
}
}
}
override fun startInWriteAction(): Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.psi.PsiFile

class Intention : IntentionAction, PriorityAction {
class FixIssueIntention : IntentionAction, PriorityAction {
override fun getText(): String = "Fix using DevChat"
override fun getFamilyName(): String = "DevChat"
override fun getPriority(): PriorityAction.Priority = PriorityAction.Priority.HIGH
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
<editorFactoryListener implementation="ai.devchat.plugin.completion.editor.EditorListener" />
<actionPromoter order="last" implementation="ai.devchat.plugin.completion.editor.EditorActionPromoter"/>
<intentionAction>
<className>ai.devchat.plugin.actions.Intention</className>
<className>ai.devchat.plugin.actions.FixIssueIntention</className>
<category>DevChat</category>
</intentionAction>
<intentionAction>
<className>ai.devchat.plugin.actions.AskIssueIntention</className>
<category>DevChat</category>
</intentionAction>
</extensions>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Ask about this issue with DevChat.
</body>
</html>

0 comments on commit a5fb4cc

Please sign in to comment.