public Task <Document> RefactorAsync( Document document, SelectedTextLineCollection lines, CancellationToken cancellationToken = default(CancellationToken)) { ImmutableArray <TextChange> textChanges = GetTextChanges(lines); return(document.WithTextChangesAsync(textChanges, cancellationToken)); }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, SyntaxNode node) { if (context.IsAnyRefactoringEnabled( RefactoringIdentifiers.WrapInRegion, RefactoringIdentifiers.WrapInIfDirective)) { SelectedTextLineCollection lines = await SelectedLinesRefactoring.GetSelectedLinesAsync(context, node).ConfigureAwait(false); if (lines?.Any() == true) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.WrapInRegion)) { context.RegisterRefactoring( "Wrap in region", cancellationToken => { var refactoring = new WrapInRegionRefactoring(); return(refactoring.RefactorAsync(context.Document, lines, cancellationToken)); }); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.WrapInIfDirective)) { context.RegisterRefactoring( "Wrap in #if", cancellationToken => { var refactoring = new WrapInIfDirectiveRefactoring(); return(refactoring.RefactorAsync(context.Document, lines, cancellationToken)); }); } } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.RemoveEmptyLines) && await RemoveEmptyLinesRefactoring.CanRefactorAsync(context, node).ConfigureAwait(false)) { context.RegisterRefactoring( "Remove empty lines", cancellationToken => { return(RemoveEmptyLinesRefactoring.RefactorAsync( context.Document, node, context.Span, cancellationToken)); }); } }