SDK 8.2 -> 9.0. Types

62 views
Skip to first unread message

Dmitry Dolotovskikh

unread,
Dec 9, 2014, 5:48:36 AM12/9/14
to resharpe...@googlegroups.com
Hi

Could you please sort me out where are follow types:

1. class BulkItentionsBuilderEx
2. class BulkQuickFixWithCommonTransactionBuilder
3. extemsion method CreateBulkActions

Example code:
public override IEnumerable<IntentionAction> CreateBulbItems()
       
{
           
ISolution solution = _highlighting.Element.GetSolution();
           
IPsiFiles psiFiles = solution.GetComponent<IPsiFiles>();
           
IProjectFile projectFile = _highlighting.Element.GetSourceFile().ToProjectFile();


           
Action<IDocument, IPsiSourceFile, IProgressIndicator> processFileAction =
               
(document, psiSourceFile, indicator) =>
               
{
                   
if (!psiSourceFile.HasExcluded(psiSourceFile.GetSettingsStore()))
                   
{
                       
IEnumerable<IXmlFile> xmlFiles =
                            psiFiles
.GetPsiFiles<XmlLanguage>(psiSourceFile).OfType<IXmlFile>();
                       
foreach (IXmlFile xmlFile in xmlFiles)
                       
{
                           
new FieldIdShouldBeUppercaseFileHandler(document, xmlFile).Run(indicator);
                       
}
                   
}
               
};


           
var acceptProjectFilePredicate = BulkItentionsBuilderEx.CreateAcceptFilePredicateByPsiLanaguage<XmlLanguage>(solution);
           
var inFileFix = new BulkQuickFixInFileWithCommonPsiTransaction(projectFile, ACTION_TEXT, processFileAction);
           
var builder = new BulkQuickFixWithCommonTransactionBuilder(
               
this, inFileFix, solution, ACTION_TEXT, processFileAction, acceptProjectFilePredicate);


           
return builder.CreateBulkActions(projectFile,
             
IntentionsAnchors.QuickFixesAnchor, IntentionsAnchors.QuickFixesAnchorPosition);
       
}



Thanks

Matt Ellis

unread,
Dec 9, 2014, 11:57:53 AM12/9/14
to resharpe...@googlegroups.com
Hi Dmitry. Bulk actions have changed a lot, with ReSharper now handling more of the boilerplate stuff. Here's what you need to do:

1. If your quick fix/context action supports bulk actions, you now only need to return one item in CreateBulkItems - ReSharper will automatically add the rest. So stop calling into BulkIntentionsBuilderEx and stop using the BulkQuickFixWithCommonTransactionBuilder. You only need to return one item, so just return this.ToQuickFixAction, which is actually the default for QuickFixBase.CreateBulbItems, so you can actually just delete your implementation.
2. Instead, handle fixing one action, by overriding ExecutePsiTransaction and handling that file, in the same way you're handling it now (i.e. move the code out of the processFileAction lambda into ExecutePsiTransaction).
3. Now comes the magic. Your QuickFix needs to implement either ICodeCleanupAction, IHighlightingsSetAction, IOneHighlightingAction or IScopeBulkAction. Each of these interfaces derive from IBulkAction, and ReSharper uses this to tell that your action can also handle bulk actions, and it will automatically add the items to the menu for you.

In order to run the bulk options, you implement the interface that most closely matches how your quick fix/context action works.
  • ICodeCleanupAction returns a code cleanup profile that will perform just a single task - e.g. remove using statements, get rid of all usages of "this."
  • IHighlightingsSetAction is for actions that clean up based on a set of highlightings. This is most likely what you'll need. You'll need to implement the ExecuteAction method, that takes in a collection of HighlightingInfo items, from which you can get a list of elements that need processing, and you return an action that takes in an ITextControl and then runs the fixes for all elements
  • IOneHighlightingAction means your quick fix can only process one highlighting at a time, and ReSharper will create a new instance of the quick fix for each highlighting in the selected scope. This is nowhere near as efficient as IHighlightingsSetAction and no code in ReSharper uses it. You should use IHighlightingsSetAction.
  • IScopeBulkAction allows for processing the files that in the scope (whereas IHighlightingsSetAction gives you the highlightings and the elements they're attached to, and ICodeCleanupAction runs your code cleanup with your profile on the files in the scope for you). The ExecuteAction method should loop over the passed in scope parameter, with scope.GetFilesToProcess, and process each file as it sees fit. For example, ReSharper's remove regions uses this - there aren't any warnings to look for, code cleanup doesn't do it, so it has to process each file to remove the regions itself. This interface is more suited to a context action than a quick fix.
Hope that gets you started.

Regards
Matt
Reply all
Reply to author
Forward
0 new messages