Skip to content

Commit

Permalink
feat(intention): add Shire Hobbit AI action support
Browse files Browse the repository at this point in the history
Add support for invoking Shire Hobbit AI action with Java hello, world generation.
  • Loading branch information
phodal committed Jun 7, 2024
1 parent 4fd33ed commit c1122e1
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.phodal.shirelang.actions.dynamic.DynamicShireActionService
import com.phodal.shirelang.compiler.hobbit.HobbitHole

object IntentionHelperUtil {
fun getAiAssistantIntentions(project: Project, editor: Editor, file: PsiFile): List<IntentionAction> {
fun getAiAssistantIntentions(project: Project, editor: Editor?, file: PsiFile): List<IntentionAction> {
val shireActionConfigs = DynamicShireActionService.getInstance().getAction(ShireActionLocation.INTENTION_MENU)
return shireActionConfigs.map { actionConfig ->
ShireIntentionAction(actionConfig.name, actionConfig.config, file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ class ShireIntentionHelper : IntentionAction, Iconable {
if (file == null) return false

val instance = InjectedLanguageManager.getInstance(project)
return instance.getTopLevelFile(file)?.virtualFile != null
if (instance.getTopLevelFile(file)?.virtualFile == null) {
return false
}

val intentions = IntentionHelperUtil.getAiAssistantIntentions(project, editor, file)
return intentions.isNotEmpty()
}

override fun invoke(project: Project, editor: Editor, file: PsiFile) {
Expand Down
5 changes: 5 additions & 0 deletions shirelang/src/main/resources/com.phodal.shirelang.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<idea-plugin package="com.phodal.shirelang">
<resource-bundle>messages.ShireBundle</resource-bundle>
<!--suppress PluginXmlValidity -->
<dependencies>
<plugin id="org.intellij.plugins.markdown"/>
Expand Down Expand Up @@ -45,6 +46,10 @@
<runLineMarkerContributor language="Shire"
implementationClass="com.phodal.shirelang.run.ShireRunLineMarkersProvider"/>

<intentionAction>
<className>com.phodal.shirelang.actions.intention.ShireIntentionHelper</className>
<categoryKey>shire.intention.category</categoryKey>
</intentionAction>
</extensions>

<actions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ shire.patch.cannot.read.patch=Cannot read a patch
inspection.group.name=Shire language
inspection.duplicate.agent=Duplicate agent calls detected. It is recommended to make only one call per agent. Please remove any duplicate agent calls.
shire.intention.name=Shire Assistant
shire.intention.category=Shire Intention
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
生成一个 Java hello, world:

```java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
生成一个 Java hello, world:
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invoke <b>Shire Hobbit</b> Action on here with AI ability.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
生成一个 Java hello, world:

```java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
生成一个 Java hello, world:
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invoke <b>Shire Hobbit</b> Action on here with AI ability.

0 comments on commit c1122e1

Please sign in to comment.