From 654c0b33c7625d84b86835d6b9ca46a94a94db0e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 2 Dec 2024 10:59:25 -0800 Subject: [PATCH] Pass in computed data --- ...ctIntroduceUsingStatementCodeRefactoringProvider.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Features/Core/Portable/IntroduceUsingStatement/AbstractIntroduceUsingStatementCodeRefactoringProvider.cs b/src/Features/Core/Portable/IntroduceUsingStatement/AbstractIntroduceUsingStatementCodeRefactoringProvider.cs index 90f133be2a812..789fcb2f94aed 100644 --- a/src/Features/Core/Portable/IntroduceUsingStatement/AbstractIntroduceUsingStatementCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/IntroduceUsingStatement/AbstractIntroduceUsingStatementCodeRefactoringProvider.cs @@ -17,7 +17,6 @@ using Microsoft.CodeAnalysis.Operations; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Utilities; using Roslyn.Utilities; @@ -198,7 +197,7 @@ [.. surroundingStatements var usingStatement = CreateUsingStatement(declarationStatement, statementsToSurround); return await ReplaceWithUsingStatementAsync( - document, declarationStatement, statementsToSurround, usingStatement, cancellationToken).ConfigureAwait(false); + document, declarationStatement, statementsToSurround, usingStatement, surroundingStatements, declarationStatementIndex, cancellationToken).ConfigureAwait(false); } } } @@ -233,7 +232,7 @@ private async Task IntroduceUsingStatementAsync( var usingStatement = CreateUsingBlockStatement(expressionStatement, statementsToSurround); return await ReplaceWithUsingStatementAsync( - document, expressionStatement, statementsToSurround, usingStatement, cancellationToken).ConfigureAwait(false); + document, expressionStatement, statementsToSurround, usingStatement, surroundingStatements, statementIndex, cancellationToken).ConfigureAwait(false); } } @@ -242,13 +241,12 @@ private async Task ReplaceWithUsingStatementAsync( TStatementSyntax statementToReplace, SyntaxList statementsToSurround, TStatementSyntax usingStatement, + SyntaxList surroundingStatements, + int statementIndex, CancellationToken cancellationToken) { var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); - var surroundingStatements = GetSurroundingStatements(statementToReplace); - var statementIndex = surroundingStatements.IndexOf(statementToReplace); - if (statementsToSurround.Any()) { var newParent = WithStatements(