Kotlin references in MultiHostInjector are not working correctly

Planned

Injected Kotlin code via MultiHostInjector has no references to project files by default (more info on my previous post). After a weekend of debugging, we noticed that this is caused by

KotlinCacheServiceImpl::createFacadeForFilesWithSpecialModuleInfo

creates a facade with library scope only. This is the debug info for the facade:

"facadeForSpecialModuleInfo(LibrarySourceInfo or NotUnderContentRootModuleInfo)"

As a workaround, we managed to to obtain the KtFile after MultiHostInjector::doneInjecting() via reflection and call

injectedFile.putUserData(UserDataModuleInfoKt.MODULE_ROOT_TYPE_KEY, JavaSourceRootType.SOURCE);

This is the commit with the workaround: https://github.com/casid/jte-intellij/commit/53fed086c70d6c6d6b6e4d8e1dae24d4f2b8083c#diff-44a62a2c26c176669e0a7068ebb0af07

We're pretty sure this can't be the intended way to get code completions for Kotlin injections working. Is there an official way to do it?

We also noticed that references only work one way. References in the template resolve to the correct Java or Kotlin classes.

However, the Java or Kotlin classes are not aware they are used within the templates. This means that refactorings or find usages are not working as intended.

Any help would be greatly appreciated!

Please sign in to leave a comment.