Not highlighted imports
Hi. I'm developing a library to support string interpolation feature in older java versions https://github.com/kh-bd/interp4j. In intellij plugin I am using `MultiHostInjector` extension point to add highlighting and completion for inlined expression. It works pretty well.

But, it does not work with static members from other classes.

References are resolved correctly. I can go to `UUID` class declaration or `randomUUID()` method declaration but imports are not highlighted properly

and if I can `optimize imports` action, this import will be removed and code will become incorrect.
I tried to find out an extension point to fix it but didn't manage. Is there any extension point I can use?
It's a link to language injector implementation. May be I have implemented it in wrong way.
P.s. additionally I use `ImplicitUsageProvider` extension point but as I understand imports are not provided to this extension.
Please sign in to leave a comment.
Hi,
I can't find any direct extension point for this problem.
Please try implementing
com.intellij.lang.ImportOptimizer
(EP:lang.importOptimizer
), which will add this import if it is referenced in your injection. It should be registered withorder="last"
to be ordered afterJavaImportOptimizer
.Regarding unused import inspection, try implementing
InspectionSuppressor
and return true fromisSuppressedFor
if thetoolId
isUNUSED_IMPORT
and the import is actually used in your injections.Thank you very much for your help :)
I've tried to implement own
ImportOptimizer
and have some problem. As I can see inLanguageImportStatements.forFile
only 1 optimizer can be selected for a file due to break statement in inner loop.So my optimizer wasn't selected, only the standard one.
If I register my optimizer with
order=first
it replaces the standard one.Is this behavior intentional? or I am doing something wrong?
I might replace the standard optimizer with my own implementation (which add imports as I want) but standard optimizer's class marked as final, so I can't extend it :(
Hi,
I'm sorry, but you are right. I checked the wrong code fragment, which didn't look like a single optimizer can be used:
https://github.com/JetBrains/intellij-community/blob/master/platform/lang-impl/src/com/intellij/codeInsight/actions/OptimizeImportsProcessor.java#L157-L169
It used the
LanguageImportStatements
under the hood. I don't see any other place, which would allow to hook in with custom additional imports. You can try requesting such a feature in the platform on https://youtrack.jetbrains.com/issues/IJPL.thank you for your help :)