Skip to content

Commit 035a3cb

Browse files
committed
feat(devin-lang): add DevInRunFileAction and related changes #101
This commit introduces a new action, `DevInRunFileAction`, which allows users to run a DevIn file directly from the IDE. It also includes modifications to the `cc.unitmesh.devti.language.xml` file to add the necessary configuration for the new action, as well as updates to the `AutoDevBundle.properties` file to include a new message for the run line marker. Additionally, a new file `DevInRunLineMarkersProvider.kt` is added to provide support for run line markers in DevIn files.
1 parent 1834fed commit 035a3cb

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cc.unitmesh.devti.language.actions
2+
3+
import cc.unitmesh.devti.AutoDevNotifications
4+
import com.intellij.execution.actions.ConfigurationContext
5+
import com.intellij.openapi.actionSystem.ActionUpdateThread
6+
import com.intellij.openapi.actionSystem.AnActionEvent
7+
import com.intellij.openapi.actionSystem.CommonDataKeys
8+
import com.intellij.openapi.project.DumbAwareAction
9+
import org.jetbrains.annotations.NonNls
10+
11+
class DevInRunFileAction : DumbAwareAction() {
12+
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
13+
14+
override fun update(e: AnActionEvent) {
15+
val file = e.getData(CommonDataKeys.PSI_FILE) ?: return
16+
if (e.presentation.text.isNullOrBlank()) {
17+
e.presentation.text = "Run DevIn file: ${file.name}"
18+
}
19+
}
20+
21+
override fun actionPerformed(e: AnActionEvent) {
22+
val file =
23+
e.getData(CommonDataKeys.PSI_FILE) ?: return
24+
val virtualFile = file.virtualFile ?: return
25+
26+
27+
val project = file.project
28+
val context = ConfigurationContext.getFromContext(e.dataContext, e.place)
29+
30+
AutoDevNotifications.notify(project, "Run file action")
31+
}
32+
33+
companion object {
34+
val ID: @NonNls String = "runDevInFileAction"
35+
}
36+
37+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cc.unitmesh.devti.language.run
2+
3+
import cc.unitmesh.devti.language.DevInLanguage
4+
import cc.unitmesh.devti.language.actions.DevInRunFileAction
5+
import cc.unitmesh.devti.language.psi.DevInFile
6+
import com.intellij.execution.lineMarker.RunLineMarkerContributor
7+
import com.intellij.icons.AllIcons
8+
import com.intellij.openapi.actionSystem.ActionManager
9+
import com.intellij.openapi.actionSystem.AnAction
10+
import com.intellij.psi.PsiElement
11+
12+
class DevInRunLineMarkersProvider : RunLineMarkerContributor() {
13+
override fun getInfo(element: PsiElement): Info? {
14+
if (element.language !is DevInLanguage || element.textRange.startOffset != 0) return null
15+
16+
val psiFile = element.containingFile
17+
if (psiFile !is DevInFile) return null
18+
19+
val actions = arrayOf<AnAction>(ActionManager.getInstance().getAction(DevInRunFileAction.ID))
20+
21+
return Info(
22+
AllIcons.RunConfigurations.TestState.Run, { "Run DevIn file: ${psiFile.name}" }, *actions
23+
)
24+
}
25+
}

exts/devin-lang/src/main/resources/cc.unitmesh.devti.language.xml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
<fileType name="DevInFile" implementationClass="cc.unitmesh.devti.language.DevInFileType" fieldName="INSTANCE"
99
language="DevIn" extensions="devin"/>
1010

11-
<lang.parserDefinition language="DevIn" implementationClass="cc.unitmesh.devti.language.parser.DevInParserDefinition"/>
11+
<lang.parserDefinition language="DevIn"
12+
implementationClass="cc.unitmesh.devti.language.parser.DevInParserDefinition"/>
1213
<lang.syntaxHighlighterFactory language="DevIn"
1314
implementationClass="cc.unitmesh.devti.language.highlight.DevInSyntaxHighlighterFactory"/>
1415

@@ -28,7 +29,18 @@
2829

2930
<languageInjector implementation="cc.unitmesh.devti.language.DevInLanguageInjector"/>
3031

31-
<configurationType implementation="cc.unitmesh.devti.language.run.AutoDevConfigurationType"/>
32-
<programRunner implementation="cc.unitmesh.devti.language.run.DevInCommandRunner"/>
32+
33+
<runLineMarkerContributor language="DevIn"
34+
implementationClass="cc.unitmesh.devti.language.run.DevInRunLineMarkersProvider"/>
35+
36+
<!-- <configurationType implementation="cc.unitmesh.devti.language.run.AutoDevConfigurationType"/>-->
37+
<!-- <programRunner implementation="cc.unitmesh.devti.language.run.DevInCommandRunner"/>-->
3338
</extensions>
39+
40+
<actions>
41+
<action id="runDevInFileAction"
42+
class="cc.unitmesh.devti.language.actions.DevInRunFileAction"
43+
use-shortcut-of="RunClass"
44+
/>
45+
</actions>
3446
</idea-plugin>

src/main/resources/messages/AutoDevBundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,4 @@ autoarkui.generate=Auto Generate ArkUI
147147
autoarkui.generate.clarify=Clarify Requirements
148148
autoarkui.generate.design=Design Page
149149
devin.ref.loading=Loading git revision
150+
line.marker.run.0=Run {0}

0 commit comments

Comments
 (0)