Skip to content

Commit

Permalink
fix template references to js function (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx authored Jan 2, 2024
1 parent ebf6977 commit bbcff49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/main/kotlin/com/emberjs/hbs/HbsLocalCompletion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class HbsLocalCompletion : CompletionProvider<CompletionParameters>() {
return
}

val children = PsiTreeUtil.collectElements(f) { it is JSVariable || it is ES6ImportDeclaration || it is JSClass}
val children = PsiTreeUtil.collectElements(f) { it is JSFunction || it is JSVariable || it is ES6ImportDeclaration || it is JSClass}
children.forEach {
if (it is JSVariable) {
val useScope = JSUseScopeProvider.getBlockScopeElement(it)
Expand All @@ -312,6 +312,13 @@ class HbsLocalCompletion : CompletionProvider<CompletionParameters>() {
}
}

if (it is JSFunction && it.parent !is JSVariable) {
val useScope = JSUseScopeProvider.getBlockScopeElement(it)
if (useScope.isAncestor(tpl)) {
result.addElement(LookupElementBuilder.create(it.name!!))
}
}

if (it is ES6ImportDeclaration) {
result.addAllElements(it.importSpecifiers.mapNotNull { it.alias?.name ?: it.name!! }.map { LookupElementBuilder.create(it)})
result.addAllElements(it.importedBindings.mapNotNull { it.name }.map { LookupElementBuilder.create(it)})
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/com/emberjs/hbs/HbsLocalReference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class HbsLocalReference(private val leaf: PsiElement, val resolved: Any?) : HbRe
if (parts.first() == "this") {
current = JSContextResolver.resolveThisReference(tpl as PsiElement)
} else {
val children = PsiTreeUtil.collectElements(f) { it is JSVariable || it is ES6ImportDeclaration || it is JSClass }
val children = PsiTreeUtil.collectElements(f) { it is JSFunction || it is JSVariable || it is ES6ImportDeclaration || it is JSClass }
current = children.mapNotNull {
if (it is JSVariable && it.name?.equals(parts.first()) == true) {
val useScope = JSUseScopeProvider.getBlockScopeElement(it)
Expand All @@ -155,6 +155,13 @@ class HbsLocalReference(private val leaf: PsiElement, val resolved: Any?) : HbRe
}
}

if (it is JSFunction && it.name?.equals(parts.first()) == true && it.parent !is JSVariable) {
val useScope = JSUseScopeProvider.getBlockScopeElement(it)
if (useScope.isAncestor(tpl as PsiElement)) {
return@mapNotNull it
}
}

if (it is JSClass && it.name?.equals(parts.first()) == true) {
val useScope = JSUseScopeProvider.getBlockScopeElement(it)
if (useScope.isAncestor(tpl as PsiElement)) {
Expand Down

0 comments on commit bbcff49

Please sign in to comment.