Skip to content

Commit f56df0b

Browse files
committed
fix: add reference to internal components
1 parent aefce18 commit f56df0b

File tree

7 files changed

+25
-11
lines changed

7 files changed

+25
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Changelog
44
===============================================================================
5+
## 2020.3.31
6+
- fix: add reference to internal components
7+
58
## 2021.3.11
69
- fix: another assertion
710

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ plugins {
1313

1414

1515
group = "com.emberjs"
16-
version = "2020.3.30"
16+
version = "2020.3.31"
1717

1818
// Configure project's dependencies
1919
repositories {

src/main/kotlin/com/emberjs/hbs/HbsComponentReference.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class HbsComponentReference(element: PsiElement) : HbsModuleReference(element, "
1616
val prop = internalComponents.properties.find { it.name == element.text }
1717
return createResults((prop?.jsType?.sourceElement as JSReferenceExpression).resolve())
1818
}
19+
if (internalHelpers.properties.map { it.name }.contains(element.text)) {
20+
val prop = internalHelpers.properties.find { it.name == element.text }
21+
return createResults((prop?.jsType?.sourceElement as JSReferenceExpression).resolve())
22+
}
1923
return super.multiResolve(incompleteCode)
2024
}
2125
}

src/main/kotlin/com/emberjs/hbs/HbsLocalReference.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class HbsLocalReference(private val leaf: PsiElement, val target: PsiElement?) :
365365
return HbsLocalRenameReference(element, importRef)
366366
}
367367

368-
if (element.parent is HbOpenBlockMustache) {
368+
if (element.parent is HbOpenBlockMustache && element.parent.children[0] != element) {
369369
return HbsLocalRenameReference(element, element)
370370
}
371371

src/main/kotlin/com/emberjs/hbs/HbsModuleReference.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open class HbsModuleReference(element: PsiElement, val moduleType: String) :
2121
private val internalModifiersFile = PsiFileFactory.getInstance(project).createFileFromText("intellij-emberjs/internal/modifiers-stub", Language.findLanguageByID("TypeScript")!!, this::class.java.getResource("/com/emberjs/external/ember-modifiers.ts").readText())
2222
private val internalComponentsFile = PsiFileFactory.getInstance(project).createFileFromText("intellij-emberjs/internal/components-stub", Language.findLanguageByID("TypeScript")!!, this::class.java.getResource("/com/emberjs/external/ember-components.ts").readText())
2323

24-
private val internalHelpers = EmberUtils.resolveDefaultExport(internalHelpersFile) as JSObjectLiteralExpression
24+
protected val internalHelpers = EmberUtils.resolveDefaultExport(internalHelpersFile) as JSObjectLiteralExpression
2525
private val internalModifiers = EmberUtils.resolveDefaultExport(internalModifiersFile) as JSObjectLiteralExpression
2626
protected val internalComponents = EmberUtils.resolveDefaultExport(internalComponentsFile) as JSObjectLiteralExpression
2727

@@ -33,7 +33,14 @@ open class HbsModuleReference(element: PsiElement, val moduleType: String) :
3333
override fun multiResolve(incompleteCode: Boolean): Array<out ResolveResult> {
3434
// Collect all components from the index
3535

36-
if (moduleType == "helper") {
36+
if (moduleType == "helper") {
37+
if (internalHelpers.properties.map { it.name }.contains(element.text)) {
38+
val prop = internalHelpers.properties.find { it.name == element.text }
39+
return createResults((prop?.jsType?.sourceElement as JSReferenceExpression).resolve())
40+
}
41+
}
42+
43+
if (moduleType == "component") {
3744
if (internalHelpers.properties.map { it.name }.contains(element.text)) {
3845
val prop = internalHelpers.properties.find { it.name == element.text }
3946
return createResults((prop?.jsType?.sourceElement as JSReferenceExpression).resolve())

src/main/kotlin/com/emberjs/hbs/HbsPatterns.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.intellij.psi.PsiElement
88
import com.intellij.psi.PsiWhiteSpace
99

1010
object HbsPatterns {
11-
val SIMPLE_MUSTACHE_NAME: Capture<HbMustacheName> = psiElement(HbMustacheName::class.java)
11+
val SIMPLE_MUSTACHE_NAME: Capture<PsiElement> = psiElement(HbTokenTypes.MUSTACHE_NAME)
1212
.withTextLengthLongerThan(0)
1313
.withParent(psiElement(HbTokenTypes.MUSTACHE))
1414
.afterLeaf(psiElement(HbTokenTypes.OPEN))
@@ -17,7 +17,7 @@ object HbsPatterns {
1717
.withTextLengthLongerThan(0)
1818
.withSuperParent(3, SIMPLE_MUSTACHE_NAME)
1919

20-
val BLOCK_MUSTACHE_NAME: Capture<HbMustacheName> = psiElement(HbMustacheName::class.java)
20+
val BLOCK_MUSTACHE_NAME: Capture<PsiElement> = psiElement(HbTokenTypes.MUSTACHE_NAME)
2121
.withTextLengthLongerThan(0)
2222
.withParent(psiElement(HbTokenTypes.OPEN_BLOCK_STACHE))
2323
.afterLeaf(psiElement(HbTokenTypes.OPEN_BLOCK))
@@ -33,7 +33,7 @@ object HbsPatterns {
3333
val MUSTACHE_ID_MISSING: Capture<PsiElement> = psiElement(HbTokenTypes.ID).withParent(psiElement(HbPsiElement::class.java)
3434
.afterSibling(psiElement(HbTokenTypes.SEP).afterSibling(psiElement(HbTokenTypes.ID))))
3535

36-
val SUB_EXPR_NAME: Capture<HbMustacheName> = psiElement(HbMustacheName::class.java)
36+
val SUB_EXPR_NAME: Capture<PsiElement> = psiElement(HbTokenTypes.MUSTACHE_NAME)
3737
.withParent(psiElement(HbTokenTypes.PARAM)
3838
.afterLeaf(psiElement(HbTokenTypes.OPEN_SEXPR)))
3939

src/test/kotlin/com/emberjs/index/EmberNameIndexTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class EmberNameIndexTest : BasePlatformTestCase() {
2121
}
2222

2323
fun testExample() = doTest(
24-
"controller:application",
25-
"controller:user/index",
26-
"controller:user/new",
27-
"route:index",
24+
"controller:application:~/controllers/application",
25+
"controller:user/index:~/controllers/user/index",
26+
"controller:user/new:~/controllers/user/new",
27+
"route:index:~/routes/index",
2828
"helper-test:format-number",
2929
"acceptance-test:user-page")
3030

0 commit comments

Comments
 (0)