Skip to content

Commit a8e6d5a

Browse files
authored
fix toc args and named blocks (#242)
* fix toc args completions and refs * fix toc named block completions and refs
1 parent 66b8747 commit a8e6d5a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.emberjs.hbs
22

3+
import com.dmarcotte.handlebars.parsing.HbTokenTypes
34
import com.dmarcotte.handlebars.psi.impl.HbPathImpl
45
import com.emberjs.lookup.EmberLookupInternalElementBuilder
56
import com.emberjs.utils.originalVirtualFile
@@ -9,6 +10,7 @@ import com.intellij.codeInsight.completion.CompletionResultSet
910
import com.intellij.injected.editor.VirtualFileWindow
1011
import com.intellij.javascript.nodejs.reference.NodeModuleManager
1112
import com.intellij.psi.PsiManager
13+
import com.intellij.psi.util.elementType
1214
import com.intellij.psi.util.parentsWithSelf
1315
import com.intellij.util.ProcessingContext
1416

@@ -27,6 +29,9 @@ class HbsBuiltinHelperCompletionProvider(val helpers: List<String>) : Completion
2729
val useImports = hasHbsImports != null
2830
val path = parameters.position.parentsWithSelf.toList().find { it is HbPathImpl }
2931
if (path != null && path.text.contains(".")) return
32+
if (parameters.position.parent.prevSibling.elementType == HbTokenTypes.SEP) {
33+
return
34+
}
3035
result.addAllElements(lookupElements.map { EmberLookupInternalElementBuilder.create(parameters.originalFile, it, useImports) })
3136
}
3237
}

src/main/kotlin/com/emberjs/utils/EmberUtils.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import com.dmarcotte.handlebars.parsing.HbTokenTypes
66
import com.dmarcotte.handlebars.psi.*
77
import com.dmarcotte.handlebars.psi.impl.HbPathImpl
88
import com.emberjs.cli.EmberCliFrameworkDetector
9+
import com.emberjs.gts.GjsLanguage
910
import com.emberjs.gts.GtsElementTypes
1011
import com.emberjs.gts.GtsFile
1112
import com.emberjs.gts.GtsFileViewProvider
13+
import com.emberjs.gts.GtsLanguage
1214
import com.emberjs.hbs.*
1315
import com.emberjs.index.EmberNameIndex
1416
import com.emberjs.navigation.EmberGotoRelatedProvider
@@ -285,6 +287,10 @@ class EmberUtils {
285287
fun findComponentArgsType(element: JSElement): JSRecordType? {
286288
var cls: PsiElement? = element
287289
if (cls is TypeScriptVariable) {
290+
if (cls.jsType.toString().startsWith("TOC<") || cls.jsType.toString().startsWith("TemplateOnlyComponent<")) {
291+
val arg = (cls.jsType as JSGenericTypeImpl).arguments[0]
292+
return arg.asRecordType().properties.find { it.memberName == "Args" }?.jsType?.asRecordType()
293+
}
288294
return cls.jsType?.asRecordType()?.callSignatures?.firstOrNull()?.returnType?.asRecordType()?.properties?.find { it.memberName == "Context" }?.jsType?.asRecordType()?.properties?.find { it.memberName == "args" }?.jsType?.asRecordType()
289295
}
290296
if (cls is TypeScriptAsExpression) {
@@ -840,6 +846,12 @@ class EmberUtils {
840846
}
841847
}
842848
}
849+
850+
if (cls is TypeScriptVariable) {
851+
jsTemplate = f.containingFile.viewProvider.findElementAt(cls.children[1].textOffset, JavaScriptSupportLoader.TYPESCRIPT)
852+
} else if (cls is JSVariable) {
853+
jsTemplate = f.containingFile.viewProvider.findElementAt(cls.children[1].textOffset, JavaScriptSupportLoader.ECMA_SCRIPT_6)
854+
}
843855
}
844856

845857
template = dir?.findFile("$name.hbs") ?: dir?.findFile("template.hbs") ?: dir?.findFile("template.ts") ?: dir?.findFile("template.js")
@@ -932,6 +944,13 @@ class EmberUtils {
932944
}
933945
}
934946
}
947+
if (cls is TypeScriptVariable) {
948+
if (cls.jsType.toString().startsWith("TOC<") || cls.jsType.toString().startsWith("TemplateOnlyComponent<")) {
949+
val arg = (cls.jsType as JSGenericTypeImpl).arguments[0]
950+
blocks = arg.asRecordType().properties.find { it.memberName == "Blocks" }
951+
args = arg.asRecordType().properties.find { it.memberName == "Args" }
952+
}
953+
}
935954
if (blocks != null) {
936955
val yields = blocks?.jsType?.asRecordType()?.properties
937956
yields?.forEach {

0 commit comments

Comments
 (0)