From a5a7a305f3059d23c950f3fb3a453c13945b289b Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Mon, 22 Sep 2025 22:28:34 +0400 Subject: [PATCH 1/2] feat: introduce routes indexer --- gradle.properties | 2 +- .../framework/TempestFrameworkClasses.kt | 5 ++ .../tempest/framework/router/AbstractIndex.kt | 22 +++++++++ .../tempest/framework/router/RoutesIndex.kt | 48 +++++++++++++++++++ src/main/resources/META-INF/plugin.xml | 3 ++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt create mode 100644 src/main/kotlin/com/github/tempest/framework/router/AbstractIndex.kt create mode 100644 src/main/kotlin/com/github/tempest/framework/router/RoutesIndex.kt diff --git a/gradle.properties b/gradle.properties index 5729e0d..d0b2d1a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ platformVersion = 2025.1.1 # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html # Example: platformPlugins = com.jetbrains.php:203.4449.22, org.intellij.scala:2023.3.27@EAP #platformPlugins=com.jetbrains.php:243.25659.59,com.jetbrains.hackathon.indices.viewer:1.28 -platformPlugins=com.jetbrains.php:251.25410.129,com.jetbrains.hackathon.indices.viewer:1.28 +platformPlugins=com.jetbrains.php:251.25410.129,com.jetbrains.hackathon.indices.viewer:1.30 # Example: platformBundledPlugins = com.intellij.java platformBundledPlugins = # Example: platformBundledModules = intellij.spellchecker diff --git a/src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt b/src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt new file mode 100644 index 0000000..5202dd7 --- /dev/null +++ b/src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt @@ -0,0 +1,5 @@ +package com.github.tempest.framework + +object TempestFrameworkClasses { + const val ConsoleCommand = "\\Tempest\\Console\\ConsoleCommand" +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/tempest/framework/router/AbstractIndex.kt b/src/main/kotlin/com/github/tempest/framework/router/AbstractIndex.kt new file mode 100644 index 0000000..c162515 --- /dev/null +++ b/src/main/kotlin/com/github/tempest/framework/router/AbstractIndex.kt @@ -0,0 +1,22 @@ +package com.github.tempest.framework.router + +import com.intellij.util.indexing.DataIndexer +import com.intellij.util.indexing.FileBasedIndex +import com.intellij.util.indexing.FileBasedIndexExtension +import com.intellij.util.indexing.FileContent +import com.intellij.util.indexing.ID +import com.intellij.util.io.EnumeratorStringDescriptor + +abstract class AbstractIndex : FileBasedIndexExtension() { + abstract override fun getName(): ID + + abstract override fun getInputFilter(): FileBasedIndex.InputFilter + + override fun dependsOnFileContent() = true + + abstract override fun getIndexer(): DataIndexer + + override fun getKeyDescriptor() = EnumeratorStringDescriptor.INSTANCE + + override fun getVersion() = 1 +} diff --git a/src/main/kotlin/com/github/tempest/framework/router/RoutesIndex.kt b/src/main/kotlin/com/github/tempest/framework/router/RoutesIndex.kt new file mode 100644 index 0000000..715dc62 --- /dev/null +++ b/src/main/kotlin/com/github/tempest/framework/router/RoutesIndex.kt @@ -0,0 +1,48 @@ +package com.github.tempest.framework.router + +import com.github.tempest.framework.TempestFrameworkClasses +import com.github.tempest.framework.TempestFrameworkUtil +import com.intellij.openapi.util.text.StringUtil +import com.intellij.psi.util.PsiTreeUtil +import com.intellij.util.indexing.DataIndexer +import com.intellij.util.indexing.FileBasedIndex +import com.intellij.util.indexing.FileContent +import com.intellij.util.indexing.ID +import com.intellij.util.io.EnumeratorStringDescriptor +import com.jetbrains.php.lang.PhpFileType +import com.jetbrains.php.lang.psi.elements.PhpAttribute + +private typealias RouteType = String + +class RoutesIndex : AbstractIndex() { + companion object { + val key = ID.create("Tempest.Routes") + } + + override fun getVersion() = 1 + + override fun getName() = key + + override fun getValueExternalizer() = EnumeratorStringDescriptor.INSTANCE + + override fun getInputFilter() = FileBasedIndex.InputFilter { + it.fileType == PhpFileType.INSTANCE && + !it.name.endsWith(TempestFrameworkUtil.TEMPLATE_SUFFIX) + } + + override fun getIndexer() = DataIndexer { inputData -> + inputData + .psiFile + .let { PsiTreeUtil.findChildrenOfType(it, PhpAttribute::class.java) } + .filter { it.fqn == TempestFrameworkClasses.ConsoleCommand } + .mapNotNull { attribute -> + attribute.arguments + .firstOrNull { it.name == "name" || it.name.isEmpty() } + ?.argument + ?.value + } + .map { StringUtil.unquoteString(it) } + .associateBy { it } +// .apply { println("file: ${inputData.file}, result: $this") } + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 48e0a1d..a08f7b8 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -26,6 +26,9 @@ + + From 72628192cd6de7b6f57ef546920b5cb8f8af2efa Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Mon, 22 Sep 2025 22:31:31 +0400 Subject: [PATCH 2/2] chore: rename to console --- .../{router => common/index}/AbstractIndex.kt | 4 ++-- .../index/ConsoleCommandsIndex.kt} | 11 ++++++----- src/main/resources/META-INF/plugin.xml | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) rename src/main/kotlin/com/github/tempest/framework/{router => common/index}/AbstractIndex.kt (93%) rename src/main/kotlin/com/github/tempest/framework/{router/RoutesIndex.kt => console/index/ConsoleCommandsIndex.kt} (77%) diff --git a/src/main/kotlin/com/github/tempest/framework/router/AbstractIndex.kt b/src/main/kotlin/com/github/tempest/framework/common/index/AbstractIndex.kt similarity index 93% rename from src/main/kotlin/com/github/tempest/framework/router/AbstractIndex.kt rename to src/main/kotlin/com/github/tempest/framework/common/index/AbstractIndex.kt index c162515..f9eb9f3 100644 --- a/src/main/kotlin/com/github/tempest/framework/router/AbstractIndex.kt +++ b/src/main/kotlin/com/github/tempest/framework/common/index/AbstractIndex.kt @@ -1,4 +1,4 @@ -package com.github.tempest.framework.router +package com.github.tempest.framework.common.index import com.intellij.util.indexing.DataIndexer import com.intellij.util.indexing.FileBasedIndex @@ -19,4 +19,4 @@ abstract class AbstractIndex : FileBasedIndexExtension() { override fun getKeyDescriptor() = EnumeratorStringDescriptor.INSTANCE override fun getVersion() = 1 -} +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/tempest/framework/router/RoutesIndex.kt b/src/main/kotlin/com/github/tempest/framework/console/index/ConsoleCommandsIndex.kt similarity index 77% rename from src/main/kotlin/com/github/tempest/framework/router/RoutesIndex.kt rename to src/main/kotlin/com/github/tempest/framework/console/index/ConsoleCommandsIndex.kt index 715dc62..c5f5639 100644 --- a/src/main/kotlin/com/github/tempest/framework/router/RoutesIndex.kt +++ b/src/main/kotlin/com/github/tempest/framework/console/index/ConsoleCommandsIndex.kt @@ -1,7 +1,8 @@ -package com.github.tempest.framework.router +package com.github.tempest.framework.console.index import com.github.tempest.framework.TempestFrameworkClasses import com.github.tempest.framework.TempestFrameworkUtil +import com.github.tempest.framework.common.index.AbstractIndex import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.util.PsiTreeUtil import com.intellij.util.indexing.DataIndexer @@ -12,11 +13,11 @@ import com.intellij.util.io.EnumeratorStringDescriptor import com.jetbrains.php.lang.PhpFileType import com.jetbrains.php.lang.psi.elements.PhpAttribute -private typealias RouteType = String +private typealias ConsoleCommandsIndexType = String -class RoutesIndex : AbstractIndex() { +class ConsoleCommandsIndex : AbstractIndex() { companion object { - val key = ID.create("Tempest.Routes") + val key = ID.create("Tempest.ConsoleCommands") } override fun getVersion() = 1 @@ -30,7 +31,7 @@ class RoutesIndex : AbstractIndex() { !it.name.endsWith(TempestFrameworkUtil.TEMPLATE_SUFFIX) } - override fun getIndexer() = DataIndexer { inputData -> + override fun getIndexer() = DataIndexer { inputData -> inputData .psiFile .let { PsiTreeUtil.findChildrenOfType(it, PhpAttribute::class.java) } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index a08f7b8..e4c2b08 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -28,7 +28,7 @@ implementationClass="com.github.tempest.framework.views.TempestComponentsInspectionSuppressor"/> + implementation="com.github.tempest.framework.console.index.ConsoleCommandsIndex" />