Skip to content

Commit

Permalink
feat(devin-lang): add DevInRunFileAction and related changes #101
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phodal committed Mar 15, 2024
1 parent 1834fed commit 035a3cb
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
@@ -0,0 +1,37 @@
package cc.unitmesh.devti.language.actions

import cc.unitmesh.devti.AutoDevNotifications
import com.intellij.execution.actions.ConfigurationContext
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.project.DumbAwareAction
import org.jetbrains.annotations.NonNls

class DevInRunFileAction : DumbAwareAction() {
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT

override fun update(e: AnActionEvent) {
val file = e.getData(CommonDataKeys.PSI_FILE) ?: return
if (e.presentation.text.isNullOrBlank()) {
e.presentation.text = "Run DevIn file: ${file.name}"
}
}

override fun actionPerformed(e: AnActionEvent) {
val file =
e.getData(CommonDataKeys.PSI_FILE) ?: return
val virtualFile = file.virtualFile ?: return


val project = file.project
val context = ConfigurationContext.getFromContext(e.dataContext, e.place)

AutoDevNotifications.notify(project, "Run file action")
}

companion object {
val ID: @NonNls String = "runDevInFileAction"
}

}
@@ -0,0 +1,25 @@
package cc.unitmesh.devti.language.run

import cc.unitmesh.devti.language.DevInLanguage
import cc.unitmesh.devti.language.actions.DevInRunFileAction
import cc.unitmesh.devti.language.psi.DevInFile
import com.intellij.execution.lineMarker.RunLineMarkerContributor
import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.psi.PsiElement

class DevInRunLineMarkersProvider : RunLineMarkerContributor() {
override fun getInfo(element: PsiElement): Info? {
if (element.language !is DevInLanguage || element.textRange.startOffset != 0) return null

val psiFile = element.containingFile
if (psiFile !is DevInFile) return null

val actions = arrayOf<AnAction>(ActionManager.getInstance().getAction(DevInRunFileAction.ID))

return Info(
AllIcons.RunConfigurations.TestState.Run, { "Run DevIn file: ${psiFile.name}" }, *actions
)
}
}
18 changes: 15 additions & 3 deletions exts/devin-lang/src/main/resources/cc.unitmesh.devti.language.xml
Expand Up @@ -8,7 +8,8 @@
<fileType name="DevInFile" implementationClass="cc.unitmesh.devti.language.DevInFileType" fieldName="INSTANCE"
language="DevIn" extensions="devin"/>

<lang.parserDefinition language="DevIn" implementationClass="cc.unitmesh.devti.language.parser.DevInParserDefinition"/>
<lang.parserDefinition language="DevIn"
implementationClass="cc.unitmesh.devti.language.parser.DevInParserDefinition"/>
<lang.syntaxHighlighterFactory language="DevIn"
implementationClass="cc.unitmesh.devti.language.highlight.DevInSyntaxHighlighterFactory"/>

Expand All @@ -28,7 +29,18 @@

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

<configurationType implementation="cc.unitmesh.devti.language.run.AutoDevConfigurationType"/>
<programRunner implementation="cc.unitmesh.devti.language.run.DevInCommandRunner"/>

<runLineMarkerContributor language="DevIn"
implementationClass="cc.unitmesh.devti.language.run.DevInRunLineMarkersProvider"/>

<!-- <configurationType implementation="cc.unitmesh.devti.language.run.AutoDevConfigurationType"/>-->
<!-- <programRunner implementation="cc.unitmesh.devti.language.run.DevInCommandRunner"/>-->
</extensions>

<actions>
<action id="runDevInFileAction"
class="cc.unitmesh.devti.language.actions.DevInRunFileAction"
use-shortcut-of="RunClass"
/>
</actions>
</idea-plugin>
1 change: 1 addition & 0 deletions src/main/resources/messages/AutoDevBundle.properties
Expand Up @@ -147,3 +147,4 @@ autoarkui.generate=Auto Generate ArkUI
autoarkui.generate.clarify=Clarify Requirements
autoarkui.generate.design=Design Page
devin.ref.loading=Loading git revision
line.marker.run.0=Run {0}

0 comments on commit 035a3cb

Please sign in to comment.