Skip to content

Commit 7c5f80c

Browse files
committed
feat: add run anything (ctrl ctrl) contributor
1 parent 3c40306 commit 7c5f80c

File tree

5 files changed

+81
-3
lines changed

5 files changed

+81
-3
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.github.tempest.framework.console.run
2+
3+
import com.github.tempest.framework.TempestBundle
4+
import com.github.tempest.framework.TempestIcons
5+
import com.github.tempest.framework.console.index.ConsoleCommandsIndex
6+
import com.intellij.icons.AllIcons
7+
import com.intellij.ide.actions.runAnything.activity.RunAnythingAnActionProvider
8+
import com.intellij.openapi.actionSystem.CommonDataKeys
9+
import com.intellij.openapi.actionSystem.DataContext
10+
import com.intellij.openapi.application.ReadAction
11+
import com.intellij.util.indexing.FileBasedIndex
12+
13+
class TempestRunAnythingProvider : RunAnythingAnActionProvider<TempestRunCommandAction>() {
14+
override fun getCommand(value: TempestRunCommandAction) =
15+
TempestBundle.message("action.run.target.command", value.commandName)
16+
17+
override fun getHelpCommandPlaceholder() = "tempest <command>"
18+
19+
override fun getCompletionGroupTitle() = "Tempest"
20+
21+
override fun getHelpCommand() = "tempest"
22+
23+
override fun getHelpGroupTitle() = "PHP"
24+
25+
override fun getHelpIcon() = TempestIcons.TEMPEST
26+
27+
override fun getIcon(value: TempestRunCommandAction) = AllIcons.Actions.Execute
28+
29+
override fun getValues(dataContext: DataContext, pattern: String): Collection<TempestRunCommandAction> {
30+
val project = CommonDataKeys.PROJECT.getData(dataContext) ?: return emptyList()
31+
32+
return ReadAction.compute<Collection<TempestRunCommandAction>, Throwable> {
33+
FileBasedIndex.getInstance()
34+
.getAllKeys(ConsoleCommandsIndex.key, project)
35+
.map { TempestRunCommandAction(it) }
36+
}
37+
}
38+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.github.tempest.framework.console.run
2+
3+
import com.github.tempest.framework.TempestBundle
4+
import com.intellij.execution.Executor
5+
import com.intellij.execution.RunManagerEx
6+
import com.intellij.execution.runners.ExecutionUtil
7+
import com.intellij.icons.AllIcons
8+
import com.intellij.openapi.actionSystem.AnAction
9+
import com.intellij.openapi.actionSystem.AnActionEvent
10+
11+
class TempestRunCommandAction(val commandName: String) : AnAction() {
12+
init {
13+
templatePresentation.setText(TempestBundle.message("action.run.target.text", commandName), false)
14+
templatePresentation.description = TempestBundle.message("action.run.target.description", commandName)
15+
templatePresentation.icon = AllIcons.Actions.Execute
16+
}
17+
18+
override fun actionPerformed(event: AnActionEvent) {
19+
val project = event.project ?: return
20+
21+
val runManager = RunManagerEx.getInstanceEx(project)
22+
val producer = TempestRunConfigurationProducer()
23+
val configurationFactory = producer.configurationFactory
24+
25+
val runConfiguration = TempestConsoleCommandRunConfiguration(
26+
project,
27+
configurationFactory,
28+
TempestBundle.message("action.run.target.command", commandName),
29+
)
30+
.apply { settings.commandName = commandName }
31+
32+
val configuration = runManager.createConfiguration(runConfiguration, configurationFactory)
33+
34+
runManager.setTemporaryConfiguration(configuration)
35+
ExecutionUtil.runConfiguration(configuration, Executor.EXECUTOR_EXTENSION_NAME.extensionList.first())
36+
}
37+
}

src/main/kotlin/com/github/tempest/framework/console/run/TempestRunTargetAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent
1313
import com.intellij.openapi.actionSystem.impl.SimpleDataContext
1414
import com.jetbrains.php.lang.psi.elements.Method
1515

16-
internal class TempestRunTargetAction(private val target: Method) : AnAction() {
16+
class TempestRunTargetAction(private val target: Method) : AnAction() {
1717
init {
1818
templatePresentation.setText(TempestBundle.message("action.run.target.text", target.name), false)
1919
templatePresentation.description = TempestBundle.message("action.run.target.description", target.name)

src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<runLineMarkerContributor
1616
language="PHP"
1717
implementationClass="com.github.tempest.framework.console.run.ConsoleCommandLineMarkerProvider" />
18+
<runAnything.executionProvider
19+
implementation="com.github.tempest.framework.console.run.TempestRunAnythingProvider" />
1820
<multiHostInjector
1921
implementation="com.github.tempest.framework.views.injection.PHPLanguageInjector"/>
2022
<webSymbols.webTypes
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
action.run.target.description=Run Tempest console command
2-
action.run.target.text=Run {command}
1+
action.run.target.text=Run {0}
2+
action.run.target.description=Tempest console command
3+
action.run.target.command=tempest {0}

0 commit comments

Comments
 (0)