-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from devchat-ai/support-ask-issue
Support ask issue
- Loading branch information
Showing
6 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/ai/devchat/plugin/actions/AskIssueIntention.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/resources/intentionDescriptions/AskIssueIntention/description.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<body> | ||
Ask about this issue with DevChat. | ||
</body> | ||
</html> |
File renamed without changes.