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

Conversation

ToddGrun
Copy link
Contributor

Currently, all expression/body refactorings only work with an empty selection. I've started looking into #29495 which requests overload completion to set the selection upon commit. Upon commit (and setting the selection), it's desirable to be able to do the expression/body refactoring. This change should allow that.

1st commit == entirety of product code change.
2nd commit == new tests for each of the refactorings with selections
3rd commit == raw string changes in the modified test files

@ToddGrun ToddGrun requested a review from a team as a code owner January 30, 2025 01:30
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 30, 2025
ToddGrun added a commit to ToddGrun/roslyn that referenced this pull request Jan 31, 2025
This (along with dotnet#76969) will allow a user to commit an override completion and easily replace the default text (and still use the expression body fixers).

This required the CompletionChange class to now allow the data to represent a selection instead of just a cursor position.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants