Skip to content

Commit b6423fb

Browse files
committed
- fix: correctly resolve paths from args and fix completion
1 parent 812c8f7 commit b6423fb

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
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+
## v2020.3.28
6+
- fix: correctly resolve paths from args and fix completion
7+
58
## v2020.3.27
69
- fix: correctly resolve paths in hash
710
- feature: add parameter autocompletion for `{{component x param=1 ...}}`

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,6 @@ class HbsLocalCompletion : CompletionProvider<CompletionParameters>() {
252252
}
253253
val txt = (element.parents.find { it is HbPathImpl || it is HbStringLiteral }?.text ?: element.text).replace("IntellijIdeaRulezzz", "")
254254

255-
if (element.parent is HbData) {
256-
addArgsCompletion(element, result)
257-
return
258-
}
259-
260255
val helperElement = EmberUtils.findFirstHbsParamFromParam(element)
261256
if (helperElement != null) {
262257
addHelperCompletions(helperElement, result)
@@ -271,6 +266,11 @@ class HbsLocalCompletion : CompletionProvider<CompletionParameters>() {
271266
return
272267
}
273268

269+
if (element.parent is HbData) {
270+
addArgsCompletion(element, result)
271+
return
272+
}
273+
274274
addArgsCompletion(element, result)
275275
addImportPathCompletions(element, result)
276276
addImportCompletions(element, result)

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ class HbsLocalReference(private val leaf: PsiElement, val target: PsiElement?) :
306306

307307
fun createReference(element: PsiElement): PsiReference? {
308308
val name = element.text.replace("IntellijIdeaRulezzz", "")
309-
if (element.parent is HbData) {
309+
310+
val sibling = PsiTreeUtil.findSiblingBackward(element, HbTokenTypes.ID, null)
311+
if (name == "this" && sibling == null) {
310312
val fname = element.containingFile.name.split(".").first()
311313
var fileName = fname
312314
if (fileName == "template") {
@@ -319,17 +321,21 @@ class HbsLocalReference(private val leaf: PsiElement, val target: PsiElement?) :
319321
?: dir?.findFile("controller.ts")
320322
?: dir?.findFile("controller.js")
321323
if (file != null) {
322-
val cls = EmberUtils.findDefaultExportClass(file)
323-
val args = EmberUtils.findComponentArgsType(cls as JSElement)
324-
val prop = args?.properties?.find { it.memberName == name }
325-
if (prop != null) {
326-
return HbsLocalReference(element, prop.memberSource.singleElement)
327-
}
328-
return null
324+
return HbsLocalReference(element, resolveToJs(file, listOf()))
329325
}
330326
}
331-
val sibling = PsiTreeUtil.findSiblingBackward(element, HbTokenTypes.ID, null)
332-
if (name == "this" && sibling == null) {
327+
328+
// for this.x.y
329+
if (sibling != null && sibling.references.find { it is HbsLocalReference } != null) {
330+
val ref = sibling.references.find { it is HbsLocalReference } as HbsLocalReference
331+
val yieldRef = ref.resolveYield()
332+
if (yieldRef != null) {
333+
return HbsLocalReference(element, resolveToJs(yieldRef, listOf(element.text)))
334+
}
335+
return HbsLocalReference(element, resolveToJs(ref.resolve(), listOf(element.text)))
336+
}
337+
338+
if (element.parent is HbData) {
333339
val fname = element.containingFile.name.split(".").first()
334340
var fileName = fname
335341
if (fileName == "template") {
@@ -342,7 +348,13 @@ class HbsLocalReference(private val leaf: PsiElement, val target: PsiElement?) :
342348
?: dir?.findFile("controller.ts")
343349
?: dir?.findFile("controller.js")
344350
if (file != null) {
345-
return HbsLocalReference(element, resolveToJs(file, listOf()))
351+
val cls = EmberUtils.findDefaultExportClass(file)
352+
val args = EmberUtils.findComponentArgsType(cls as JSElement)
353+
val prop = args?.properties?.find { it.memberName == name }
354+
if (prop != null) {
355+
return HbsLocalReference(element, prop.memberSource.singleElement)
356+
}
357+
return null
346358
}
347359
}
348360

@@ -351,16 +363,6 @@ class HbsLocalReference(private val leaf: PsiElement, val target: PsiElement?) :
351363
return HbsLocalRenameReference(element, importRef)
352364
}
353365

354-
// for this.x.y
355-
if (sibling != null && sibling.references.find { it is HbsLocalReference } != null) {
356-
val ref = sibling.references.find { it is HbsLocalReference } as HbsLocalReference
357-
val yieldRef = ref.resolveYield()
358-
if (yieldRef != null) {
359-
return HbsLocalReference(element, resolveToJs(yieldRef, listOf(element.text)))
360-
}
361-
return HbsLocalReference(element, resolveToJs(ref.resolve(), listOf(element.text)))
362-
}
363-
364366
if (element.parent is HbOpenBlockMustache) {
365367
return HbsLocalRenameReference(element, element)
366368
}

0 commit comments

Comments
 (0)