Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow expression body refactorings on non empty selections #76969

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ internal sealed class UseExpressionBodyCodeRefactoringProvider() : SyntaxEditorB
public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, textSpan, cancellationToken) = context;
if (textSpan.Length > 0)
return;

var position = textSpan.Start;
var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var node = root.FindToken(position).Parent!;
var node = root.FindNode(textSpan);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we now use the refactoring helper in this code (the code that locates a node of a particular type in th ecurrent context)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've verified that this code path is utilized for both body->expression and expression->body conversions (required setting csharp_style_expression_bodied_methods to true/false to see both ways come through). I think I'd prefer not to use TryGetRelevantNodeAsync is it isn't completely clear to me which type to be using in both cases, and throwing in the lambda expression check right below it.


var containingLambda = node.FirstAncestorOrSelf<LambdaExpressionSyntax>();
if (containingLambda != null &&
Expand Down
Loading
Loading