I want to have js (or Typescript) code injected into my html files. I already have that part working and i also could add a context to the js code so intellij can resolve some of the methods and properties correctly.
The issue now is that i can only access public members of the controller class. I want to be able to access all members. The other issue is that it still has a generic js context for the injection. So pressing ctrl + space gives me all kinds of stuff that is not related to the controller.
So my question is basically how i can provide the context in such a way that i get completion and reference resolving as if the injected code where part of the controller class.
This is what i have so far:
class Injector : MultiHostInjector {
override fun getLanguagesToInject(registrar: MultiHostRegistrar, host: PsiElement) {
// ...
JSInjectionBracesUtil.injectInXmlTextByDelimiters(registrar, host, JavascriptLanguage.INSTANCE, "\${", "}")
}
override fun elementsToInjectIn(): List<Class<out PsiElement>> {
return listOf(XmlTextImpl::class.java, XmlAttributeValueImpl::class.java)
}
}
class FrameworkHandler : FrameworkIndexingHandler() {
override fun addContextType(info: JSTypeInfo, context: PsiElement) {
// ...
val controller = InjectionUtils.findControllerOfInjectedElement(context) ?: return
val namespace = JSQualifiedNameImpl.buildProvidedNamespace(controller)
info.addType(JSNamedTypeFactory.createNamespace(namespace, JSContext.INSTANCE, null, true), false)
}
override fun addContextNames(context: PsiElement, names: MutableList<String>) {
// ...
val controller = InjectionUtils.findControllerOfInjectedElement(context) ?: return
names.add(controller.qualifiedName!!)
}
}