@@ -9,6 +9,8 @@ import com.emberjs.psi.EmberNamedAttribute
99import com.emberjs.psi.EmberNamedElement
1010import com.emberjs.refactoring.SimpleNodeFactory
1111import com.emberjs.utils.EmberUtils
12+ import com.emberjs.utils.ifFalse
13+ import com.emberjs.utils.ifTrue
1214import com.emberjs.utils.originalVirtualFile
1315import com.emberjs.xml.EmberAttrDec
1416import com.intellij.injected.editor.VirtualFileWindow
@@ -26,6 +28,7 @@ import com.intellij.lang.javascript.psi.impl.JSVariableImpl
2628import com.intellij.lang.javascript.psi.jsdoc.impl.JSDocCommentImpl
2729import com.intellij.lang.javascript.psi.resolve.JSContextResolver
2830import com.intellij.lang.javascript.psi.types.JSRecordTypeImpl
31+ import com.intellij.lang.javascript.psi.types.recordImpl.PropertySignatureImpl
2932import com.intellij.openapi.util.TextRange
3033import com.intellij.psi.*
3134import com.intellij.psi.css.CssRulesetList
@@ -329,7 +332,12 @@ class HbsLocalReference(private val leaf: PsiElement, val resolved: Any?) : HbRe
329332 }
330333 }
331334 }
332- val followed = EmberUtils .followReferences(any as PsiElement ? )
335+
336+ if (any is PropertySignatureImpl ) {
337+ return resolveToJs(any.memberSource.singleElement, path.subList(1 , max(path.lastIndex, 1 )), resolveIncomplete, recursionCounter + 1 )
338+ }
339+
340+ val followed = (any as ? PsiElement ? )?.let { EmberUtils .followReferences(it) } ? : any
333341 if (followed != = null && followed != any) {
334342 return resolveToJs(followed, path, resolveIncomplete, recursionCounter + 1 )
335343 }
@@ -382,9 +390,14 @@ class HbsLocalReference(private val leaf: PsiElement, val resolved: Any?) : HbRe
382390 }
383391
384392 fun findReference (element : PsiElement ): PsiReference ? {
385- val psiFile = PsiManager .getInstance(element.project).findFile(element.originalVirtualFile!! )
386- val document = PsiDocumentManager .getInstance(element.project).getDocument(psiFile!! )!!
387- val service = GlintLanguageServiceProvider (element.project).getService(element.originalVirtualFile!! )
393+ var isValid = element.originalVirtualFile?.isValid.ifTrue { true }
394+ val psiFile = isValid?.let { PsiManager .getInstance(element.project).findFile(element.originalVirtualFile!! ) }
395+ isValid = isValid?.and (psiFile != null ).ifTrue { true }
396+ val document = isValid?.let { PsiDocumentManager .getInstance(element.project).getDocument(psiFile!! ) }
397+ isValid = isValid?.and (document != null ).ifTrue { true }
398+ val service = isValid?.let {
399+ GlintLanguageServiceProvider (element.project).getService(element.originalVirtualFile!! )
400+ }
388401
389402 val name = element.text.replace(" IntellijIdeaRulezzz" , " " )
390403
@@ -415,15 +428,15 @@ class HbsLocalReference(private val leaf: PsiElement, val resolved: Any?) : HbRe
415428 val yieldRef = (ref as ? HbsLocalReference )?.resolveYield()
416429 if (yieldRef != null ) {
417430 val res = resolveToJs(yieldRef, listOf (element.text))
418- return HbsLocalReference (element, res ? : service?.getNavigationFor(document, element, true )?.firstOrNull()?.parent)
431+ return HbsLocalReference (element, res ? : service?.getNavigationFor(document!! , element, true )?.firstOrNull()?.parent)
419432 }
420433 val sig = (ref as ? HbsLocalReference )?.resolved as ? JSRecordType .PropertySignature
421434 if (ref != null && resolveToJs(sig ? : ref.resolve(), listOf (element.text)) != null ) {
422435 return HbsLocalReference (element, resolveToJs(sig ? : ref.resolve(), listOf (element.text)))
423436 }
424437 val ref2 = sibling.references.find { it is HbReference } as HbReference ?
425438 val res = resolveToJs(ref2?.resolve(), listOf (element.text))
426- return HbsLocalReference (element, res ? : service?.getNavigationFor(document, element, true )?.firstOrNull()?.parent)
439+ return HbsLocalReference (element, res ? : service?.getNavigationFor(document!! , element, true )?.firstOrNull()?.parent)
427440 }
428441
429442 if (element.parent is HbData ) {
@@ -438,7 +451,7 @@ class HbsLocalReference(private val leaf: PsiElement, val resolved: Any?) : HbRe
438451 val modelProp = (cls as ? JSClass )?.let { it.jsType.asRecordType().properties.find { it.memberName == " model" } }
439452 return modelProp?.let { HbsLocalReference (element, it.memberSource.singleElement) }
440453 }
441- val resolved = service?.getNavigationFor(document, element, true )?.firstOrNull()?.parent
454+ val resolved = service?.getNavigationFor(document!! , element, true )?.firstOrNull()?.parent
442455 return resolved?.let { HbsLocalReference (element, it) }
443456 }
444457 }
@@ -463,7 +476,7 @@ class HbsLocalReference(private val leaf: PsiElement, val resolved: Any?) : HbRe
463476 return referenceBlocks(element, name)
464477 ? : resolveToLocalJs(element)
465478 ? : let {
466- val resolved = service?.getNavigationFor(document, element, true )?.firstOrNull()?.parent
479+ val resolved = service?.getNavigationFor(document!! , element, true )?.firstOrNull()?.parent
467480 resolved?.let { HbsLocalReference (element, it) }
468481 }
469482 }
0 commit comments