Skip to content

Commit 7d3f472

Browse files
committed
fix rename
1 parent 62865d9 commit 7d3f472

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class HbsLocalReference(private val leaf: PsiElement, val target: PsiElement?) :
123123
}
124124

125125
override fun isReferenceTo(element: PsiElement): Boolean {
126-
return getElement().getManager().areElementsEquivalent(target, element);
126+
return getElement().getManager().areElementsEquivalent(target, element) || super.isReferenceTo(element)
127127
}
128128

129129
override fun resolve(): PsiElement? {
@@ -392,9 +392,9 @@ class HbsLocalReference(private val leaf: PsiElement, val target: PsiElement?) :
392392
return HbsLocalRenameReference(element, importRef)
393393
}
394394

395-
if (element.parent is HbOpenBlockMustache && element.parent.children[0] != element) {
396-
return HbsLocalRenameReference(element, element)
397-
}
395+
// if (element.parent is HbOpenBlockMustache && element.parent.children[0] != element) {
396+
// return HbsLocalRenameReference(element, element)
397+
// }
398398

399399
return referenceBlocks(element, name)
400400
?: resolveToLocalJs(element)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ fun filter(element: PsiElement, fn: (PsiElement) -> PsiReference?): PsiReference
2626
if (element.text.contains(".")) {
2727
return null
2828
}
29-
if (HbsLocalReference.createReference(element) != null) {
29+
val res = HbsLocalReference.createReference(element)
30+
if (res != null && (res.resolve() as? EmberNamedElement)?.target != element) {
3031
return null
3132
}
3233
return fn(element)
@@ -258,7 +259,6 @@ class HbsReferenceContributor : PsiReferenceContributor() {
258259
register(PlatformPatterns.psiElement(XmlAttribute::class.java)) { toAttributeReference(it as XmlAttribute) }
259260
register(HbsPatterns.SIMPLE_MUSTACHE_NAME) { filter(it) { HbsComponentReference(it) } }
260261
register(HbsPatterns.BLOCK_MUSTACHE_NAME) { filter(it) { HbsComponentReference(it) } }
261-
register(HbsPatterns.BLOCK_MUSTACHE_NAME) { filter(it) { HbsModuleReference(it, "component") } }
262262
register(HbsPatterns.MUSTACHE_ID) { HbsLocalReference.createReference(it) }
263263
register(HbsPatterns.SIMPLE_MUSTACHE_NAME) { filter(it) { HbsModuleReference(it, "helper") } }
264264
register(HbsPatterns.SIMPLE_MUSTACHE_NAME) { filter(it) { HbsModuleReference(it, "modifier") } }

src/main/kotlin/com/emberjs/psi/EmberNamedElement.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -260,29 +260,24 @@ open class EmberNamedElement(val target: PsiElement, val range: IntRange? = null
260260
files.forEach { file ->
261261
val hbsView = file.viewProvider.getPsi(Language.findLanguageByID("Handlebars")!!)
262262
val htmlView = file.viewProvider.getPsi(Language.findLanguageByID("HTML")!!)
263-
if (target.language == Language.findLanguageByID("Handlebars")) {
263+
val htmlTarget = htmlView.findElementAt(target.startOffset+1)
264+
val hbsTarget = hbsView.findElementAt(target.startOffset+1)
265+
if (hbsTarget?.parents?.find { it is HbBlockWrapper } != null) {
264266
val hbs = target.parents.find { it is HbBlockWrapper }
265267
if (hbs != null) {
266-
val htmlElements = PsiTreeUtil.collectElements(htmlView) { hbs.textRange.contains(it.textRange) && it.references.any { it.isReferenceTo(target) } }
268+
val htmlElements = PsiTreeUtil.collectElements(htmlView) { hbs.textRange.contains(it.textRange) }
267269
elements.add(hbs)
268270
elements.addAll(htmlElements)
269271
}
270-
return@forEach
271272
}
272-
if (target.language == Language.findLanguageByID("HTML") && target.parents.find { it is XmlTag } != null) {
273+
if (htmlTarget?.parents?.find { it is XmlTag } != null) {
273274
val html = target.parents.find { it is XmlTag }
274275
if (html != null) {
275-
val hbsElements = PsiTreeUtil.collectElements(hbsView) { html.textRange.contains(it.textRange) && !it.references.any { it.isReferenceTo(target) } }
276+
val hbsElements = PsiTreeUtil.collectElements(hbsView) { html.textRange.contains(it.textRange) }
276277
elements.add(html)
277278
elements.addAll(hbsElements)
278279
}
279-
return@forEach
280280
}
281-
val htmlElements = PsiTreeUtil.collectElements(htmlView) { it.references.any { it.isReferenceTo(target) } }
282-
elements.addAll(htmlElements)
283-
284-
val hbsElements = PsiTreeUtil.collectElements(hbsView) { it.references.any { it.isReferenceTo(target) } }
285-
elements.addAll(hbsElements)
286281
}
287282

288283
if (elements.size == 0) {

0 commit comments

Comments
 (0)