Skip to content

Commit

Permalink
feat: try to add runner
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 28, 2022
1 parent 962a48f commit 583435f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package com.feakin.intellij.linemarkers

import com.feakin.intellij.ide.editor.elementType
import com.feakin.intellij.psi.FeakinStructDeclaration
import com.intellij.execution.lineMarker.ExecutorAction
import com.intellij.execution.lineMarker.RunLineMarkerContributor
Expand Down
45 changes: 45 additions & 0 deletions src/main/kotlin/com/feakin/intellij/runconfig/FkCommandRunner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.feakin.intellij.runconfig

import com.intellij.execution.ExecutionManager
import com.intellij.execution.ExecutionResult
import com.intellij.execution.configurations.RunProfile
import com.intellij.execution.configurations.RunProfileState
import com.intellij.execution.configurations.RunnerSettings
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.execution.runners.ProgramRunner
import com.intellij.execution.ui.ExecutionUiService
import com.intellij.execution.ui.RunContentDescriptor
import com.intellij.openapi.fileEditor.FileDocumentManager
import org.jetbrains.annotations.NonNls
import org.jetbrains.concurrency.resolvedPromise

class FkCommandRunner : ProgramRunner<RunnerSettings> {
override fun getRunnerId(): @NonNls String {
return "FkCommandRunner"
}

override fun canRun(executorId: String, profile: RunProfile): Boolean {
println("FkCommandRunner.canRun$profile")
return false
}

override fun execute(environment: ExecutionEnvironment) {
val state = environment.state ?: return
@Suppress("UnstableApiUsage")
ExecutionManager.getInstance(environment.project).startRunProfile(environment) {
resolvedPromise(doExecute(state, environment))
}
}

private fun doExecute(state: RunProfileState, environment: ExecutionEnvironment): RunContentDescriptor? {
FileDocumentManager.getInstance().saveAllDocuments()
return showRunContent(state.execute(environment.executor, this), environment)
}

@Suppress("UnstableApiUsage")
private fun showRunContent(executionResult: ExecutionResult?, environment: ExecutionEnvironment): RunContentDescriptor? {
return executionResult?.let {
ExecutionUiService.getInstance().showRunContent(it, environment)
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@
<runLineMarkerContributor language="Feakin"
implementationClass="com.feakin.intellij.linemarkers.FkCreateStructLineMarkerProvider"/>

<programRunner implementation="com.feakin.intellij.runconfig.FkCommandRunner"/>

</extensions>
</idea-plugin>

0 comments on commit 583435f

Please sign in to comment.