Conflicting Plugins

Answered

Hello,

I am developing language support plugin for Google Protobuf, and I have an issue with other plugin that provides similar functionality.

When user opens a proto file, IntelliJ IDEA suggests to install two plugins, and many users install both. They provide very similar functionality (same file type - syntax highlighting, annotators, etc), so when user opens proto file, only one plugin is used (actually, it is more like "undefined behavior").

I want to show a dialog to user with a suggestion to disable other plugins.

Question: is there any way to detect other plugins that provide support for the same language? 

I already tried to use PluginManager.getPlugins() and Language.getRegisteredLanguages(). I can find Language instance that provides support for same file extension that my plugin, but I cannot find a way to match language instance to plugin.

IdeaPluginDescriptor[] plugins = PluginManager.getPlugins();
Collection<Language> languages = Language.getRegisteredLanguages();
for (Language language : languages) {
LanguageFileType associatedFileType = language.getAssociatedFileType();
if (associatedFileType != null) {
String extension = associatedFileType.getDefaultExtension();
if (ProtoFileType.FILE_EXTENSION.equals(extension)) {
LOGGER.warn("Detected plugin for *.proto files: " + language );
// *******
// How to match language to plugin?
}
}
}
3 comments
Comment actions Permalink

There is one way, but I'm not sure that this code is reliable:

((PluginClassLoader)associatedFileType.getClass().getClassLoader()).getPluginId()

 

0
Comment actions Permalink

Hello,

Code for plugin detection by class is correct. I would recommend using "FileTypeFactory.FILE_TYPE_FACTORY_EP" for detecting other plugins that support some filetype. Something like:

for (FileTypeFactory typeFactory : Extensions.getRootArea().getExtensionPoint(FileTypeFactory.FILE_TYPE_FACTORY_EP).getExtensions()) {
typeFactory.createFileTypes(consumer);
}

You can use FileTypeConsumer like in FileTypeManagerImpl.initStandardFileTypes()

0
Comment actions Permalink

Thank you for quick response!

Final solution: ProtostuffPluginController.java 

0

Please sign in to leave a comment.