Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.emberjs.hbs

import com.dmarcotte.handlebars.parsing.HbTokenTypes
import com.dmarcotte.handlebars.psi.impl.HbPathImpl
import com.emberjs.lookup.EmberLookupInternalElementBuilder
import com.emberjs.utils.originalVirtualFile
Expand All @@ -9,6 +10,7 @@ import com.intellij.codeInsight.completion.CompletionResultSet
import com.intellij.injected.editor.VirtualFileWindow
import com.intellij.javascript.nodejs.reference.NodeModuleManager
import com.intellij.psi.PsiManager
import com.intellij.psi.util.elementType
import com.intellij.psi.util.parentsWithSelf
import com.intellij.util.ProcessingContext

Expand All @@ -27,6 +29,9 @@ class HbsBuiltinHelperCompletionProvider(val helpers: List<String>) : Completion
val useImports = hasHbsImports != null
val path = parameters.position.parentsWithSelf.toList().find { it is HbPathImpl }
if (path != null && path.text.contains(".")) return
if (parameters.position.parent.prevSibling.elementType == HbTokenTypes.SEP) {
return
}
result.addAllElements(lookupElements.map { EmberLookupInternalElementBuilder.create(parameters.originalFile, it, useImports) })
}
}
19 changes: 19 additions & 0 deletions src/main/kotlin/com/emberjs/utils/EmberUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import com.dmarcotte.handlebars.parsing.HbTokenTypes
import com.dmarcotte.handlebars.psi.*
import com.dmarcotte.handlebars.psi.impl.HbPathImpl
import com.emberjs.cli.EmberCliFrameworkDetector
import com.emberjs.gts.GjsLanguage
import com.emberjs.gts.GtsElementTypes
import com.emberjs.gts.GtsFile
import com.emberjs.gts.GtsFileViewProvider
import com.emberjs.gts.GtsLanguage
import com.emberjs.hbs.*
import com.emberjs.index.EmberNameIndex
import com.emberjs.navigation.EmberGotoRelatedProvider
Expand Down Expand Up @@ -285,6 +287,10 @@ class EmberUtils {
fun findComponentArgsType(element: JSElement): JSRecordType? {
var cls: PsiElement? = element
if (cls is TypeScriptVariable) {
if (cls.jsType.toString().startsWith("TOC<") || cls.jsType.toString().startsWith("TemplateOnlyComponent<")) {
val arg = (cls.jsType as JSGenericTypeImpl).arguments[0]
return arg.asRecordType().properties.find { it.memberName == "Args" }?.jsType?.asRecordType()
}
return cls.jsType?.asRecordType()?.callSignatures?.firstOrNull()?.returnType?.asRecordType()?.properties?.find { it.memberName == "Context" }?.jsType?.asRecordType()?.properties?.find { it.memberName == "args" }?.jsType?.asRecordType()
}
if (cls is TypeScriptAsExpression) {
Expand Down Expand Up @@ -840,6 +846,12 @@ class EmberUtils {
}
}
}

if (cls is TypeScriptVariable) {
jsTemplate = f.containingFile.viewProvider.findElementAt(cls.children[1].textOffset, JavaScriptSupportLoader.TYPESCRIPT)
} else if (cls is JSVariable) {
jsTemplate = f.containingFile.viewProvider.findElementAt(cls.children[1].textOffset, JavaScriptSupportLoader.ECMA_SCRIPT_6)
}
}

template = dir?.findFile("$name.hbs") ?: dir?.findFile("template.hbs") ?: dir?.findFile("template.ts") ?: dir?.findFile("template.js")
Expand Down Expand Up @@ -932,6 +944,13 @@ class EmberUtils {
}
}
}
if (cls is TypeScriptVariable) {
if (cls.jsType.toString().startsWith("TOC<") || cls.jsType.toString().startsWith("TemplateOnlyComponent<")) {
val arg = (cls.jsType as JSGenericTypeImpl).arguments[0]
blocks = arg.asRecordType().properties.find { it.memberName == "Blocks" }
args = arg.asRecordType().properties.find { it.memberName == "Args" }
}
}
if (blocks != null) {
val yields = blocks?.jsType?.asRecordType()?.properties
yields?.forEach {
Expand Down
Loading