resharperresharper-pluginsresharper-sdk

Resharper run configurations


I'm trying to make a reshaprer plugin to add one (or more) configurations, besides executable, static method, project, at resharper's build/run window. Any guidelines where to start? Or how to access build's context and configure? Currently examining the JetBrains.IDE.RunConfig, SolutionBuilders etc but one help would be appreciated. Should this plugin be a SolutionComponent or a SolutionInstanceComponent? Resharper's sdk help lucks documentation on build/run component.

Thank in advance!


Solution

  • You can extend the available run configuration types by implementing IRunConfig and IRunConfigProvider.

    The IRunConfigProvider class needs to be marked as [ShellComponent], and can derive from the RunConfigProviderBase abstract base class. You get to specify a name, e.g. "Executable", a type identifier, e.g. "exe" and an icon ID. There's also the CreateNew method, which will create a new instance of your IRunConfig class, which will be mostly unconfigured, at this point.

    The IRunConfig interface doesn't need to marked as a component, and should also derive from RunConfigBase - take a look at RunConfigExe in dotPeek to see an example of how to implement. You should override Execute in order to actually run whatever it is you need to run. You can use the RunConfigContext class passed in to actually execute a process from a ProcessStartInfo, or an IProject - this will execute it either by running the process, debugging it, or something else, such as code coverage or profiling.

    For an .exe, this is as simple as:

    public override void Execute(RunConfigContext context)
    {
      context.ExecutionProvider.Execute(GetStartInfo(context), context, this);
    }
    

    But for a more complicated example, look at RunConfigMethod.Execute, which uses its own standalone launcher executable, and passes in command line parameters to load the correct assembly and execute the given static method.

    Settings are implemented with ReadSpecific/SaveSpecific, and you can provide an editor view model with CreateEditor. You'll need a settings class, something like:

    [SettingsKey(typeof (ConfigSettings), ".exe config")]
    public class ExeSettings
    {
      [SettingsEntry(null, "Path to .exe")] public string Executable;
      [SettingsEntry(null, "Working directory")] public string WorkingDirectory;
      [SettingsEntry(null, "Command line arguments")] public string Arguments;
    }
    

    The view for the editor is provided by a WPF control that is displayed in a dialog that ReSharper controls. The view needs to be decorated with the [View] attribute and must implement IView<T> where T is the concrete class returned from CreateEditor. This is how ReSharper will locate the view for the view model returned by CreateEditor. Again, take a look at RunConfigMethodView in dotPeek for some more idea of what's going on (and if you look in the resources, you'll be able to see the XAML itself).