Skip to content

Commit 47a25fa

Browse files
committed
feat: provide components names
1 parent 87cfeae commit 47a25fa

File tree

7 files changed

+129
-3
lines changed

7 files changed

+129
-3
lines changed

src/main/kotlin/com/github/tempest/framework/ComponentReferenceContributor.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import com.intellij.psi.search.GlobalSearchScope
1414
import com.intellij.psi.xml.XmlChildRole
1515
import com.intellij.util.ProcessingContext
1616

17-
private const val TEMPLATE_PREFIX = ".view.php"
18-
1917
class ComponentReferenceContributor : PsiReferenceContributor() {
2018
override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) {
2119
registrar.registerReferenceProvider(
@@ -35,7 +33,7 @@ class ComponentReferenceContributor : PsiReferenceContributor() {
3533
val result = mutableListOf<PsiReference>()
3634

3735
FilenameIndex.processFilesByName(
38-
element.name + TEMPLATE_PREFIX,
36+
element.name + TempestFrameworkUtil.TEMPLATE_PREFIX,
3937
true,
4038
GlobalSearchScope.projectScope(project),
4139
{
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.github.tempest.framework
2+
3+
import com.intellij.codeInsight.lookup.LookupElement
4+
import com.intellij.codeInsight.lookup.LookupElementBuilder
5+
import com.intellij.psi.search.FilenameIndex
6+
import com.intellij.psi.search.GlobalSearchScope
7+
import com.intellij.psi.xml.XmlTag
8+
import com.intellij.xml.XmlTagNameProvider
9+
10+
class ComponentTagNameProvider : XmlTagNameProvider {
11+
override fun addTagNameVariants(
12+
elements: MutableList<LookupElement>,
13+
tag: XmlTag,
14+
prefix: String?
15+
) {
16+
val project = tag.project
17+
18+
val result = mutableListOf<String>()
19+
FilenameIndex.processAllFileNames(
20+
{
21+
if (it.startsWith("x-") && it.endsWith(TempestFrameworkUtil.TEMPLATE_PREFIX)) {
22+
result.add(it.removeSuffix(TempestFrameworkUtil.TEMPLATE_PREFIX))
23+
}
24+
25+
true
26+
},
27+
GlobalSearchScope.projectScope(project),
28+
null,
29+
)
30+
31+
result
32+
.distinct()
33+
.map {
34+
LookupElementBuilder.create(it)
35+
.withIcon(TempestIcons.TEMPEST)
36+
.withTypeText("Tempest Component")
37+
}
38+
.apply { elements.addAll(this) }
39+
}
40+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.tempest.framework
2+
3+
object TempestFrameworkUtil {
4+
const val TEMPLATE_PREFIX = ".view.php"
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.github.tempest.framework
2+
3+
import com.intellij.openapi.util.IconLoader
4+
5+
object TempestIcons {
6+
@JvmField
7+
val TEMPEST = IconLoader.getIcon("/icons/tempest/icon.svg", TempestIcons::class.java)
8+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<webSymbols.webTypes
1616
source="META-INF/webTypes.json"
1717
enableByDefault="true"/>
18+
<xml.tagNameProvider implementation="com.github.tempest.framework.ComponentTagNameProvider" />
1819
<psi.referenceContributor language="HTML" implementation="com.github.tempest.framework.ComponentReferenceContributor" />
1920
<spellchecker.bundledDictionaryProvider
2021
implementation="com.github.tempest.framework.SpellcheckingDictionaryProvider"/>
Lines changed: 37 additions & 0 deletions
Loading
Lines changed: 37 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)