-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
base: main
Are you sure you want to change the base?
Allow expression body refactorings on non empty selections #76969
Conversation
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); |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
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