Self registering plugin in Resharper 7

Hi,

I'm trying to add support for Resharper 7 in OpenWrap . For previous versions of R# you could add the plugin by adding it to the plugin list in the plugins directory:

                var asm = GetType().Assembly;
#if v600 || v610
                _lifetimeDefinition = resharper::JetBrains.DataFlow.Lifetimes.Define(resharper::JetBrains.DataFlow.EternalLifetime.Instance, "OpenWrap Solution");
                _pluginsDirectory =
                    (resharper::JetBrains.Application.PluginSupport.PluginsDirectory)_host.Environment.Container.ResolveDynamic(typeof(resharper::JetBrains.Application.PluginSupport.PluginsDirectory)).Instance;

                _selfPlugin = new ResharperPlugin(_lifetimeDefinition.Lifetime, new[] { new resharper::JetBrains.Util.FileSystemPath(asm.Location) }, null, null, null);
                
                _pluginsDirectory.Plugins.Add(_selfPlugin);
#else


Since the Plugins property of the PluginsDirectory is an Enumerable in R# 7 this is now logger possible.

Is there a way to do self registratin of plugins in R# 7 ?

Simon

1 comment
Comment actions Permalink

Hi Simon. ReSharper 7 doesn't let you dynamically add plugins any more - plugins are collected up front from various IPluginSource implementations, and then loaded. However, you can still integrate with ReSharper, in the same way that dotCover and dotTrace integrate. Essentially, you need to add a new PartsCatalogue to the _host.Environment.FullPartCatalogSet property.

This is easily done by passing the list of assemblies to the constructor of MetadataPartsCatalogue:

new MetadataPartsCatalogue(pluginAssemblies, new FlyweightFactory(), lifetime => new DefaultAssemblyResolved(pluginPath, resharperInstallDirectory))

You can take a look at PluginLoader.PluginsToCatalogs for a more detailed implementation - it has a lot more error checking, and also wraps the created parts catalogue in a new instance of AttributeIndexedPartsCatalogue, which provides an optimisation to cache getting parts by attribute, which tends to happen a lot in plugins.

While I haven't tried it, PluginsManager.Plugins is a list, so you could probably add your own instances of Plugin for each plugin you dynamically load. This means they should display in the plugins options page, and the help/about information.

Thanks
Matt

0

Please sign in to leave a comment.