Merge pull request #1017 from jasonmalinowski/add-createcoderefactoringcontext

Add a CreateCodeRefactoringContext overload
This commit is contained in:
Jason Malinowski 2022-09-12 15:33:25 -07:00 коммит произвёл GitHub
Родитель 716a2ce25b 09434786d8
Коммит 2d8a5e55ee
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 13 добавлений и 1 удалений

Просмотреть файл

@ -65,6 +65,17 @@ namespace Microsoft.CodeAnalysis.Testing
/// <returns>The <see cref="CodeRefactoringProvider"/> to be used.</returns>
protected abstract IEnumerable<CodeRefactoringProvider> GetCodeRefactoringProviders();
/// <summary>
/// Creates a code refactoring context to be used for testing.
/// </summary>
/// <param name="document">Document to refactor.</param>
/// <param name="span">Text span within the <paramref name="document"/> to refactor.</param>
/// <param name="registerRefactoring">Delegate to register a <see cref="CodeAction"/> for the refactoring.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>New <see cref="CodeRefactoringContext"/>.</returns>
protected virtual CodeRefactoringContext CreateCodeRefactoringContext(Document document, TextSpan span, Action<CodeAction> registerRefactoring, CancellationToken cancellationToken)
=> new CodeRefactoringContext(document, span, registerRefactoring, cancellationToken);
protected override async Task RunImplAsync(CancellationToken cancellationToken)
{
Verify.NotEmpty($"{nameof(TestState)}.{nameof(SolutionState.Sources)}", TestState.Sources);
@ -258,7 +269,7 @@ namespace Microsoft.CodeAnalysis.Testing
foreach (var codeRefactoringProvider in codeRefactoringProviders)
{
var context = new CodeRefactoringContext(triggerDocument, location.SourceSpan, actions.Add, cancellationToken);
var context = CreateCodeRefactoringContext(triggerDocument, location.SourceSpan, actions.Add, cancellationToken);
await codeRefactoringProvider.ComputeRefactoringsAsync(context).ConfigureAwait(false);
}

Просмотреть файл

@ -18,3 +18,4 @@ static Microsoft.CodeAnalysis.Testing.CodeRefactoringTest<TVerifier>.TriggerSpan
static Microsoft.CodeAnalysis.Testing.CodeRefactoringVerifier<TCodeRefactoring, TTest, TVerifier>.VerifyRefactoringAsync(string source, Microsoft.CodeAnalysis.Testing.DiagnosticResult expected, string fixedSource) -> System.Threading.Tasks.Task
static Microsoft.CodeAnalysis.Testing.CodeRefactoringVerifier<TCodeRefactoring, TTest, TVerifier>.VerifyRefactoringAsync(string source, Microsoft.CodeAnalysis.Testing.DiagnosticResult[] expected, string fixedSource) -> System.Threading.Tasks.Task
static Microsoft.CodeAnalysis.Testing.CodeRefactoringVerifier<TCodeRefactoring, TTest, TVerifier>.VerifyRefactoringAsync(string source, string fixedSource) -> System.Threading.Tasks.Task
virtual Microsoft.CodeAnalysis.Testing.CodeRefactoringTest<TVerifier>.CreateCodeRefactoringContext(Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan span, System.Action<Microsoft.CodeAnalysis.CodeActions.CodeAction> registerRefactoring, System.Threading.CancellationToken cancellationToken) -> Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringContext