Skip to content

Commit 73ecefd

Browse files
committed
- fix: array index error exception
- fix: null ptr exception (gts)
1 parent 70de06f commit 73ecefd

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Changelog
44
===============================================================================
5+
## 2023.1.26
6+
- fix: array index error exception
7+
- fix: null ptr exception (gts)
8+
59
## 2023.1.25
610
- fix: support eslint "fix file" for gts
711
- add yield and in-element references

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ plugins {
1313

1414

1515
group = "com.emberjs"
16-
version = "2023.1.25"
16+
version = "2023.1.26"
1717

1818
// Configure project's dependencies
1919
repositories {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class HbsLocalCompletion : CompletionProvider<CompletionParameters>() {
349349
candidates.addAll(elements.filterNotNull())
350350
}
351351
}
352-
completionResultSet.addAllElements(candidates.map { EmberLookupElementBuilderWithCandidate.create(it, file) })
352+
completionResultSet.addAllElements(candidates.mapNotNull { EmberLookupElementBuilderWithCandidate.create(it, file) })
353353
}
354354

355355
override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext, completionResultSet: CompletionResultSet) {

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.emberjs.utils
22

33

4+
import com.dmarcotte.handlebars.HbLanguage
45
import com.dmarcotte.handlebars.parsing.HbTokenTypes
56
import com.dmarcotte.handlebars.psi.*
67
import com.dmarcotte.handlebars.psi.impl.HbDataImpl
78
import com.dmarcotte.handlebars.psi.impl.HbPathImpl
89
import com.emberjs.cli.EmberCliFrameworkDetector
10+
import com.emberjs.gts.GtsElementTypes
911
import com.emberjs.gts.GtsFile
1012
import com.emberjs.gts.GtsFileViewProvider
1113
import com.emberjs.hbs.HbReference
@@ -29,7 +31,10 @@ import com.intellij.lang.ecmascript6.psi.ES6ImportSpecifier
2931
import com.intellij.lang.ecmascript6.psi.ES6ImportedBinding
3032
import com.intellij.lang.ecmascript6.resolve.ES6PsiUtil
3133
import com.intellij.lang.injection.InjectedLanguageManager
34+
import com.intellij.lang.javascript.JSLanguageDialect
3235
import com.intellij.lang.javascript.JavaScriptSupportLoader
36+
import com.intellij.lang.javascript.JavascriptLanguage
37+
import com.intellij.lang.javascript.dialects.TypeScriptLanguageDialect
3338
import com.intellij.lang.javascript.frameworks.modules.JSFileModuleReference
3439
import com.intellij.lang.javascript.psi.*
3540
import com.intellij.lang.javascript.psi.ecma6.*
@@ -348,10 +353,12 @@ class EmberUtils {
348353
val angleBracketBlock = element.parent as XmlTag
349354
val startIdx = angleBracketBlock.attributes.indexOfFirst { it.text.startsWith("|") }
350355
val endIdx = angleBracketBlock.attributes.size
351-
val params = angleBracketBlock.attributes.toList().subList(startIdx, endIdx)
352-
val refPsi = params.find { Regex("\\|*.*\\b$name\\b.*\\|*").matches(it.text) }
353-
val blockParamIdx = params.indexOf(refPsi)
354-
return followReferences(yieldParams.getOrNull(blockParamIdx), path)
356+
if (startIdx > -1 && startIdx < endIdx) {
357+
val params = angleBracketBlock.attributes.toList().subList(startIdx, endIdx)
358+
val refPsi = params.find { Regex("\\|*.*\\b$name\\b.*\\|*").matches(it.text) }
359+
val blockParamIdx = params.indexOf(refPsi)
360+
return followReferences(yieldParams.getOrNull(blockParamIdx), path)
361+
}
355362
}
356363

357364
if (element?.references != null && element.references.isNotEmpty()) {
@@ -450,7 +457,8 @@ class EmberUtils {
450457
return data
451458
}
452459

453-
if ((func is Helper || func is Modifier) && (func as PsiElementDelegate<*>).element as? JSFunction != null || func?.originalVirtualFile is LightVirtualFile || func?.containingFile is ProjectFile) {
460+
val ovf = func?.originalVirtualFile
461+
if ((func is Helper || func is Modifier) && (func as PsiElementDelegate<*>).element as? JSFunction != null || (ovf is LightVirtualFile && ovf.language is JSLanguageDialect) || func?.containingFile is ProjectFile) {
454462
func = ((func as? PsiElementDelegate<*>)?.element ?: func) as JSFunction
455463
var arrayName: String? = null
456464
var array: JSType?
@@ -785,6 +793,9 @@ class EmberUtils {
785793
jsTemplate = cls.fields.find { it.name == "layout" } ?: jsTemplate
786794
jsTemplate = jsTemplate ?: cls.fields.find { it.name == "template" }
787795
jsTemplate = followReferences(jsTemplate as PsiElement?)
796+
jsTemplate = jsTemplate
797+
?:
798+
PsiTreeUtil.collectElements(cls) { it.elementType == GtsElementTypes.GTS_OUTER_ELEMENT_TYPE && it.parent == cls }.firstOrNull()
788799
}
789800
}
790801

@@ -813,6 +824,13 @@ class EmberUtils {
813824
jsTemplate = PsiFileFactory.getInstance(file.project).createFileFromText("$name-virtual", Language.findLanguageByID("Handlebars")!!, jsTemplate)
814825
}
815826

827+
var psiRange = template?.textRange
828+
829+
if (jsTemplate is PsiElement && jsTemplate.elementType == GtsElementTypes.GTS_OUTER_ELEMENT_TYPE) {
830+
template = jsTemplate.containingFile.viewProvider.getPsi(HbLanguage.INSTANCE)
831+
psiRange = jsTemplate.textRange
832+
}
833+
816834
if (dir != null || jsTemplate != null) {
817835
// co-located
818836
if (name == "component") {
@@ -843,16 +861,16 @@ class EmberUtils {
843861
?: getFileByPath(parentModule, fullPathToHbs.replace("/components/", "/templates/components/"))
844862

845863

846-
if (template?.node?.psi != null) {
847-
val args = PsiTreeUtil.collectElementsOfType(template.node.psi, HbDataImpl::class.java)
864+
if (template?.node?.psi != null && psiRange != null) {
865+
val args = PsiTreeUtil.collectElements(template.node.psi) { it is HbData && psiRange.contains(it.textRange) }
848866
for (arg in args) {
849867
val argName = arg.text.split(".").first()
850868
if (tplArgs.find { it.value == argName } == null) {
851869
tplArgs.add(ArgData(argName, "", AttrPsiReference(arg)))
852870
}
853871
}
854872

855-
val yields = PsiTreeUtil.collectElements(template.node.psi, { it is HbPathImpl && it.text == "yield" })
873+
val yields = PsiTreeUtil.collectElements(template.node.psi) { it is HbPathImpl && it.text == "yield" && psiRange.contains(it.textRange) }
856874
for (y in yields) {
857875
tplYields.add(EmberXmlElementDescriptor.YieldReference(y))
858876
}

0 commit comments

Comments
 (0)