Skip to content

Commit a91d969

Browse files
committed
feat: support unnamed console commands
1 parent 2907021 commit a91d969

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import com.jetbrains.php.lang.psi.elements.Method
1111

1212
class ConsoleCommandLineMarkerProvider : RunLineMarkerContributor() {
1313
override fun getInfo(element: PsiElement) = when {
14-
element !is Method -> null
14+
element.parent !is Method -> null
15+
(element.parent as? Method)?.nameIdentifier != element -> null
1516
else -> {
16-
val commandName = element.getConsoleCommandName() ?: return null
17+
val commandName = (element.parent as? Method)?.getConsoleCommandName() ?: return null
1718
Info(
1819
AllIcons.Actions.Execute,
1920
ExecutorAction.getActions(1),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TempestRunConfigurationProducer : LazyRunConfigurationProducer<TempestCons
1414
context: ConfigurationContext,
1515
sourceElement: Ref<PsiElement>
1616
): Boolean {
17-
val element = context.psiLocation as? Method ?: return false
17+
val element = context.psiLocation?.parent as? Method ?: return false
1818
val commandName = element.getConsoleCommandName() ?: return false
1919

2020
configuration.settings.commandName = commandName
@@ -25,9 +25,9 @@ class TempestRunConfigurationProducer : LazyRunConfigurationProducer<TempestCons
2525

2626
override fun isConfigurationFromContext(
2727
configuration: TempestConsoleCommandRunConfiguration,
28-
context: ConfigurationContext
28+
context: ConfigurationContext,
2929
): Boolean {
30-
val method = context.psiLocation as? Method ?: return false
30+
val method = context.psiLocation?.parent as? Method ?: return false
3131

3232
return configuration.settings.commandName == method.getConsoleCommandName()
3333
}

src/main/kotlin/com/github/tempest/framework/php/mixin.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.intellij.psi.util.PsiTreeUtil
66
import com.jetbrains.php.PhpIndex
77
import com.jetbrains.php.lang.psi.PhpFile
88
import com.jetbrains.php.lang.psi.elements.Method
9+
import com.jetbrains.php.lang.psi.elements.PhpClass
910
import com.jetbrains.php.lang.psi.elements.Variable
1011

1112
fun PhpFile.getPhpViewVariables(): Set<Variable> {
@@ -17,14 +18,19 @@ fun PhpFile.getPhpViewVariables(): Set<Variable> {
1718
}
1819

1920
fun Method.getConsoleCommandName(): String? {
20-
return this
21-
.getAttributes(TempestFrameworkClasses.ConsoleCommand)
21+
return getAttributes(TempestFrameworkClasses.ConsoleCommand)
22+
.apply { if (this.isEmpty()) return null }
2223
.firstOrNull()
2324
?.arguments
2425
?.run { this.find { it.name == "name" } ?: firstOrNull() }
2526
?.argument
2627
?.value
2728
?.run { StringUtil.unquoteString(this) }
29+
?: "${containingClass?.getConsoleCommandNamePrefix()}:${name}"
30+
}
31+
32+
fun PhpClass.getConsoleCommandNamePrefix(): String {
33+
return name.substringBefore("Command").lowercase()
2834
}
2935

3036
fun PhpIndex.getMethodsByFQN(fqn:String): Collection<Method> {

0 commit comments

Comments
 (0)