Skip to content

Commit d8381a9

Browse files
committed
lookup related for backing class
1 parent 6c6ee33 commit d8381a9

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
Changelog
44
===============================================================================
5+
## 2022.2.14
6+
- improvement: better lookup for related files of templates and controller
7+
58
## 2022.2.13
6-
- feaure: allow plugin reload without restart
9+
- feature: allow plugin reload without restart
710

811
## 2022.2.12
912
- improvement: resolve this context in tests

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 = "2022.2.13"
16+
version = "2022.2.14"
1717

1818
// Configure project's dependencies
1919
repositories {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ class HbsLocalCompletion : CompletionProvider<CompletionParameters>() {
267267
result.addAllElements(args.properties.map { LookupElementBuilder.create("@${it.memberName}") })
268268
}
269269
}
270+
val modelProp = (cls as? JSClass)?.let { it.jsType.asRecordType().properties.find { it.memberName == "model" } }
271+
modelProp?.let {
272+
if (element.parent is HbData && !result.prefixMatcher.prefix.startsWith("@")) {
273+
result.addElement(LookupElementBuilder.create(it.memberName))
274+
} else {
275+
result.addElement(LookupElementBuilder.create("@${it.memberName}"))
276+
}
277+
}
270278
}
271279
}
272280

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.intellij.lang.injection.InjectedLanguageManager
1919
import com.intellij.lang.javascript.psi.*
2020
import com.intellij.lang.javascript.psi.ecma6.ES6TaggedTemplateExpression
2121
import com.intellij.lang.javascript.psi.ecma6.JSTypedEntity
22+
import com.intellij.lang.javascript.psi.ecmal4.JSClass
2223
import com.intellij.lang.javascript.psi.impl.JSVariableImpl
2324
import com.intellij.lang.javascript.psi.jsdoc.impl.JSDocCommentImpl
2425
import com.intellij.lang.javascript.psi.resolve.JSContextResolver
@@ -378,6 +379,10 @@ class HbsLocalReference(private val leaf: PsiElement, val target: PsiElement?) :
378379
if (prop != null) {
379380
return HbsLocalReference(element, prop.memberSource.singleElement)
380381
}
382+
if (element.text == "model") {
383+
val modelProp = (cls as? JSClass)?.let { it.jsType.asRecordType().properties.find { it.memberName == "model" } }
384+
return modelProp?.let { HbsLocalReference(element, it.memberSource.singleElement) }
385+
}
381386
return null
382387
}
383388
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.emberjs.hbs.HbsLocalReference
1111
import com.emberjs.hbs.HbsModuleReference
1212
import com.emberjs.hbs.ImportNameReferences
1313
import com.emberjs.index.EmberNameIndex
14+
import com.emberjs.navigation.EmberGotoRelatedProvider
1415
import com.emberjs.psi.EmberNamedElement
1516
import com.emberjs.resolver.EmberJSModuleReference
1617
import com.intellij.injected.editor.VirtualFileWindow
@@ -28,6 +29,8 @@ import com.intellij.lang.javascript.psi.ecmal4.JSClass
2829
import com.intellij.lang.javascript.psi.jsdoc.JSDocComment
2930
import com.intellij.lang.javascript.psi.types.JSArrayType
3031
import com.intellij.lang.typescript.modules.TypeScriptFileModuleReference
32+
import com.intellij.navigation.GotoRelatedItem
33+
import com.intellij.navigation.GotoRelatedProvider
3134
import com.intellij.openapi.application.ApplicationManager
3235
import com.intellij.openapi.application.WriteAction
3336
import com.intellij.openapi.vfs.VirtualFile
@@ -217,7 +220,12 @@ class EmberUtils {
217220
?: dir?.findFile("$fileName.js")
218221
?: dir?.findFile("controller.ts")
219222
?: dir?.findFile("controller.js")
220-
return cls ?: file?.let { findDefaultExportClass(it) }
223+
val relatedItems = EmberGotoRelatedProvider().getItems(element.originalVirtualFile!!, element.project)
224+
val related = (relatedItems.find { it.first.type == "component" } ?:
225+
relatedItems.find { it.first.type == "controller" } ?:
226+
relatedItems.find { it.first.type == "router" })?.second
227+
val relatedFile = related?.let { PsiManager.getInstance(element.project).findFile(it) }
228+
return cls ?: file?.let { findDefaultExportClass(it) } ?: relatedFile?.let { findDefaultExportClass(it) }
221229
}
222230

223231
fun findComponentArgsType(element: JSElement): JSRecordType? {

0 commit comments

Comments
 (0)