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.

https://github.com/kh-bd/interp4j-intellij-plugin/blob/main/src/main/java/dev/khbd/interp4j/intellij/language/AbstractInterpolationLanguageInjector.java

P.s. additionally I use `ImplicitUsageProvider` extension point but as I understand imports are not provided to this extension.

0

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 with order="last" to be ordered after JavaImportOptimizer.

Regarding unused import inspection, try implementing InspectionSuppressor and return true from isSuppressedFor if the toolId is UNUSED_IMPORT and the import is actually used in your injections.

0

Thank you very much for your help :)

I've tried to implement own ImportOptimizer and have some problem. As I can see in LanguageImportStatements.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 :(

0

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

0

thank you for your help :)

0

请先登录再写评论。