Skip to content

Commit 678df62

Browse files
committed
feat: add template path to admin component index #57
1 parent 9feabec commit 678df62

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/main/kotlin/de/shyim/shopware6/index/AdminComponentIndex.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.shyim.shopware6.index
22

3+
import com.intellij.lang.ecmascript6.psi.ES6ImportDeclaration
4+
import com.intellij.lang.ecmascript6.psi.ES6Property
35
import com.intellij.lang.javascript.JSTokenTypes
46
import com.intellij.lang.javascript.JavaScriptFileType
57
import com.intellij.lang.javascript.psi.JSCallExpression
@@ -15,6 +17,7 @@ import com.intellij.util.io.EnumeratorStringDescriptor
1517
import com.intellij.util.io.KeyDescriptor
1618
import de.shyim.shopware6.index.dict.AdminComponent
1719
import de.shyim.shopware6.index.externalizer.ObjectStreamDataExternalizer
20+
import de.shyim.shopware6.util.StringUtil
1821
import gnu.trove.THashMap
1922

2023
class AdminComponentIndex : FileBasedIndexExtension<String, AdminComponent>() {
@@ -25,7 +28,7 @@ class AdminComponentIndex : FileBasedIndexExtension<String, AdminComponent>() {
2528
}
2629

2730
override fun getVersion(): Int {
28-
return 1
31+
return 2
2932
}
3033

3134
override fun dependsOnFileContent(): Boolean {
@@ -49,6 +52,7 @@ class AdminComponentIndex : FileBasedIndexExtension<String, AdminComponent>() {
4952
if (element.methodExpression!!.lastChild is LeafPsiElement && (element.methodExpression!!.lastChild.text == "register" || element.methodExpression!!.lastChild.text == "extend")) {
5053
val arguments = element.argumentList!!.arguments
5154
var extendsFrom: String? = null
55+
var templatePath: String? = null
5256

5357
val componentName = arguments[0].firstChild
5458

@@ -76,6 +80,7 @@ class AdminComponentIndex : FileBasedIndexExtension<String, AdminComponent>() {
7680

7781
if (visitObject != null) {
7882
val props = visitObject.findProperty("props")
83+
val template = visitObject.findProperty("template")
7984

8085
if (props is JSProperty && props.value is JSObjectLiteralExpression) {
8186
val properties = (props.value as JSObjectLiteralExpression).properties
@@ -86,11 +91,25 @@ class AdminComponentIndex : FileBasedIndexExtension<String, AdminComponent>() {
8691
}
8792
}
8893
}
94+
95+
if (template is ES6Property) {
96+
inputData.psiFile.children.forEach {
97+
if (it is ES6ImportDeclaration && it.importedBindings.size == 1 && it.importedBindings[0].name == "template" && it.fromClause?.referenceText != null) {
98+
templatePath = StringUtil.stripQuotes(it.fromClause!!.referenceText.toString())
99+
100+
if (templatePath!!.startsWith("./")) {
101+
val path = templatePath!!.substring(2)
102+
templatePath = "${inputData.file.parent.path}/${path}"
103+
}
104+
}
105+
}
106+
}
89107
}
90108

91109
val component = AdminComponent(
92110
componentName.text.replace("'", "").replace("\"", ""),
93111
extendsFrom,
112+
templatePath,
94113
propsSet,
95114
inputData.file.path
96115
)

src/main/kotlin/de/shyim/shopware6/index/dict/AdminComponent.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java.util.*
77
class AdminComponent(
88
var name: String,
99
var extends: String?,
10+
var templatePath: String?,
1011
var props: Set<String>,
1112
val file: String
1213
) : Serializable {
@@ -23,6 +24,7 @@ class AdminComponent(
2324
return other is AdminComponent &&
2425
Objects.equals(other.name, this.name) &&
2526
Objects.equals(other.extends, this.extends) &&
27+
Objects.equals(other.templatePath, this.templatePath) &&
2628
Objects.equals(other.props, this.props) &&
2729
Objects.equals(other.file, this.file)
2830
}

src/test/kotlin/de/shyim/shopware6/test/index/AdminComponentIndexTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class AdminComponentIndexTest: BasePlatformTestCase() {
2626

2727
TestCase.assertEquals("sw-button", button.name)
2828
TestCase.assertEquals(null, button.extends)
29+
TestCase.assertEquals("/src/button.js", button.file)
30+
TestCase.assertEquals("/src/sw-button.html.twig", button.templatePath)
2931
TestCase.assertEquals(3, button.props.size)
3032

3133
val sorted = button.props.sortedDescending()
@@ -39,6 +41,7 @@ class AdminComponentIndexTest: BasePlatformTestCase() {
3941

4042
TestCase.assertEquals("sw-extended-button", extendedButton.name)
4143
TestCase.assertEquals("sw-button", extendedButton.extends)
44+
TestCase.assertEquals(null, extendedButton.templatePath)
4245
TestCase.assertEquals(0, extendedButton.props.size)
4346
}
4447
}

0 commit comments

Comments
 (0)