generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(intention): add Shire Assistant with AI AutoAction
Add Shire Assistant with AI AutoAction for AutoDev category.
- Loading branch information
Showing
7 changed files
with
120 additions
and
3 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
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/phodal/shire/action/intention/IntentionHelperUtil.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,12 @@ | ||
package com.phodal.shire.action.intention | ||
|
||
import com.intellij.codeInsight.intention.IntentionAction | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiFile | ||
|
||
object IntentionHelperUtil { | ||
fun getAiAssistantIntentions(project: Project, editor: Editor, file: PsiFile): List<IntentionAction> { | ||
return emptyList() | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/kotlin/com/phodal/shire/action/intention/ShireIntentionHelper.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,37 @@ | ||
package com.phodal.shire.action.intention | ||
|
||
import com.intellij.codeInsight.intention.IntentionAction | ||
import com.intellij.lang.injection.InjectedLanguageManager | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.ui.popup.JBPopupFactory | ||
import com.intellij.openapi.util.Iconable | ||
import com.intellij.psi.PsiFile | ||
import javax.swing.Icon | ||
import com.phodal.shire.ShireMainBundle | ||
import com.phodal.shirelang.ShireIcons | ||
import com.phodal.shire.action.intention.ui.CustomPopupStep | ||
|
||
class ShireIntentionHelper : IntentionAction, Iconable { | ||
override fun startInWriteAction(): Boolean = false | ||
override fun getText(): String = ShireMainBundle.message("intentions.assistant.name") | ||
Check warning on line 17 in src/main/kotlin/com/phodal/shire/action/intention/ShireIntentionHelper.kt
|
||
override fun getFamilyName(): String = ShireMainBundle.message("intentions.assistant.name") | ||
Check warning on line 18 in src/main/kotlin/com/phodal/shire/action/intention/ShireIntentionHelper.kt
|
||
override fun getIcon(flags: Int): Icon = ShireIcons.DEFAULT | ||
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean { | ||
if (file == null) return false | ||
|
||
val instance = InjectedLanguageManager.getInstance(project) | ||
return instance.getTopLevelFile(file)?.virtualFile != null | ||
} | ||
|
||
override fun invoke(project: Project, editor: Editor, file: PsiFile) { | ||
val intentions = IntentionHelperUtil.getAiAssistantIntentions(project, editor, file) | ||
|
||
val title = ShireMainBundle.message("intentions.assistant.popup.title") | ||
val popupStep = CustomPopupStep(intentions, project, editor, file, title) | ||
val popup = JBPopupFactory.getInstance().createListPopup(popupStep) | ||
|
||
popup.showInBestPositionFor(editor) | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/com/phodal/shire/action/intention/ShireIntentionsActionGroup.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,29 @@ | ||
package com.phodal.shire.action.intention | ||
|
||
import com.intellij.codeInsight.intention.IntentionAction | ||
import com.intellij.openapi.actionSystem.ActionGroup | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.CommonDataKeys | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.project.DumbAware | ||
import com.intellij.openapi.project.DumbAwareAction | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiFile | ||
import com.phodal.shirelang.ShireBundle | ||
|
||
class ShireIntentionsActionGroup : ActionGroup(ShireBundle.message("shire.intention.name"), true), DumbAware { | ||
override fun getChildren(e: AnActionEvent?): Array<AnAction> { | ||
val project: Project = e?.project ?: return emptyArray() | ||
val editor: Editor = e.getData(CommonDataKeys.EDITOR) ?: return emptyArray() | ||
val file: PsiFile = e.getData(CommonDataKeys.PSI_FILE) ?: return emptyArray() | ||
|
||
val intentions: List<IntentionAction> = IntentionHelperUtil.getAiAssistantIntentions(project, editor, file) | ||
|
||
return intentions.map { action -> | ||
DumbAwareAction.create(action.text) { | ||
Check warning on line 24 in src/main/kotlin/com/phodal/shire/action/intention/ShireIntentionsActionGroup.kt
|
||
action.invoke(project, editor, file) | ||
} | ||
}.toTypedArray() | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/com/phodal/shire/action/intention/ui/CustomPopupStep.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,28 @@ | ||
package com.phodal.shire.action.intention.ui | ||
|
||
import com.intellij.codeInsight.intention.IntentionAction | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.ui.popup.ListSeparator | ||
import com.intellij.openapi.ui.popup.PopupStep | ||
import com.intellij.openapi.ui.popup.util.BaseListPopupStep | ||
import com.intellij.psi.PsiFile | ||
|
||
class CustomPopupStep( | ||
private val intentionAction: List<IntentionAction>, | ||
private val project: Project, | ||
private val editor: Editor, | ||
private val psiFile: PsiFile, | ||
private val popupTitle: String, | ||
) : BaseListPopupStep<IntentionAction>(popupTitle, intentionAction) { | ||
override fun getTextFor(value: IntentionAction): String = value.text | ||
|
||
override fun getSeparatorAbove(value: IntentionAction?): ListSeparator? = | ||
if (value != null && value == intentionAction) ListSeparator() else null | ||
|
||
override fun onChosen(selectedValue: IntentionAction?, finalChoice: Boolean): PopupStep<*>? { | ||
return doFinalStep { | ||
selectedValue!!.invoke(project, editor, psiFile) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
projectService=Project service: {0} | ||
randomLabel=The random number is: {0} | ||
shuffle=Shuffle | ||
intention.category.llm=AutoDev | ||
intentions.write.action=Generate code | ||
intentions.assistant.name=Shire Intention Action | ||
intentions.assistant.popup.title=Shire Intention Action |