@@ -7,13 +7,15 @@ import com.dmarcotte.handlebars.psi.HbParam
77import com.dmarcotte.handlebars.psi.HbStringLiteral
88import com.dmarcotte.handlebars.psi.impl.HbBlockWrapperImpl
99import com.dmarcotte.handlebars.psi.impl.HbPathImpl
10+ import com.emberjs.glint.GlintCompletionEntry
1011import com.emberjs.glint.GlintLanguageServiceProvider
1112import com.emberjs.lookup.HbsInsertHandler
1213import com.emberjs.psi.EmberNamedElement
1314import com.emberjs.utils.*
1415import com.intellij.codeInsight.completion.CompletionParameters
1516import com.intellij.codeInsight.completion.CompletionProvider
1617import com.intellij.codeInsight.completion.CompletionResultSet
18+ import com.intellij.ide.highlighter.HtmlFileType
1719import com.intellij.injected.editor.VirtualFileWindow
1820import com.intellij.lang.Language
1921import com.intellij.lang.ecmascript6.psi.ES6ImportDeclaration
@@ -33,6 +35,7 @@ import com.intellij.psi.impl.source.tree.LeafPsiElement
3335import com.intellij.psi.util.PsiTreeUtil
3436import com.intellij.psi.util.elementType
3537import com.intellij.psi.xml.XmlAttribute
38+ import com.intellij.util.FileContentUtil
3639import com.intellij.util.ProcessingContext
3740import com.intellij.codeInsight.lookup.LookupElementBuilder as IntelijLookupElementBuilder
3841
@@ -155,22 +158,14 @@ class HbsLocalCompletion : CompletionProvider<CompletionParameters>() {
155158
156159 fun addHelperCompletions (element : PsiElement , result : CompletionResultSet ) {
157160 val file = EmberUtils .followReferences(element.children.firstOrNull())
158- var func: JSFunction ? = null
159- if (file is JSFunction ) {
160- func = file
161- }
161+
162162 if (file is JSClass ) {
163163 val ref = EmberUtils .getComponentReferenceData(file.containingFile)
164164 result.addAllElements(ref.args.map { LookupElementBuilder .create(it.value + " =" ) })
165165 }
166- if (file is PsiFile ) {
167- func = EmberUtils .resolveHelper(file)
168- }
169-
170- if (func != null ) {
171- val hash = func.parameterList?.parameters?.last()
172- resolveJsType(hash?.jsType ? : hash?.inferredType, result, " =" )
173- }
166+ val map = EmberUtils .getArgsAndPositionals(element)
167+ val named = map.getOrDefault(" named" , listOf ())?.map { LookupElementBuilder .create(it + " =" ) }
168+ named?.let { result.addAllElements(it) }
174169 }
175170
176171 fun addImportPathCompletions (element : PsiElement , result : CompletionResultSet ) {
@@ -229,6 +224,8 @@ class HbsLocalCompletion : CompletionProvider<CompletionParameters>() {
229224 val importNames = it.children[2 ].text
230225 .replace(" \" " , " " )
231226 .replace(" '" , " " )
227+ .replace(" }" , " " )
228+ .replace(" {" , " " )
232229 if (importNames.contains(" *" )) {
233230 val name = importNames.split(" as " ).last()
234231 result.addElement(LookupElementBuilder .create(name))
@@ -285,8 +282,22 @@ class HbsLocalCompletion : CompletionProvider<CompletionParameters>() {
285282 element = element.parent
286283 }
287284 val languageService = GlintLanguageServiceProvider (element.project)
285+ val service = languageService.getService(element.originalVirtualFile!! )
288286 val txt = (element.parents.find { it is HbPathImpl || it is HbStringLiteral }?.text ? : element.text).replace(" IntellijIdeaRulezzz" , " " )
289287
288+ if (element.containingFile.fileType is HtmlFileType ) {
289+ val results = service?.updateAndGetCompletionItems(element.originalVirtualFile!! , parameters)?.get()?.map { it as GlintCompletionEntry }?.map {
290+ if (result.prefixMatcher.prefix == " @" ) {
291+ LookupElementBuilder .create(" @" + it.name)
292+ } else {
293+ LookupElementBuilder .create(it.name)
294+ }
295+
296+ }
297+ results?.let { result.addAllElements(it) }
298+ return
299+ }
300+
290301 val helperElement = EmberUtils .findFirstHbsParamFromParam(element)
291302 if (helperElement != null ) {
292303 addHelperCompletions(helperElement, result)
0 commit comments