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

Do syntactic cleanup during the initial pass of producing fixed documents in fix-all. #73383

Merged
merged 15 commits into from
May 8, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented May 8, 2024

Followup to #73385.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels May 8, 2024
@@ -163,7 +163,7 @@ class C
void M(int? x, int? y)
{
var z1 = x ?? y;
var z2 = x ?? y ;
var z2 = x ?? y;
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixed an issue here where we had errant whitespace.

@@ -46,7 +46,6 @@ class C
void Goo()
{
a?.Invoke();

a?.Invoke();
Copy link
Member Author

Choose a reason for hiding this comment

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

these changed because the code that was generated was (a)?.Invoke(); with elastic trivia on the parens. But when the parens were removed in the simplification pass, we lost that trivia. So we weren't formatting properly. the new formatting follows the expected formatting rules now.

@@ -93,15 +92,7 @@ public sealed override IEnumerable<FixAllScope> GetSupportedFixAllScopes()
return;

var newDocument = await this.FixAllAsync(fixAllContext, document, documentDiagnostics).ConfigureAwait(false);
if (newDocument == null || newDocument == document)
Copy link
Member Author

Choose a reason for hiding this comment

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

this code was duplicated in the CodeFix FixAllProvider, and the CodeRefactoring FixAllProvider. It was been extracted and is run when this code calls into onDocumentFixed.

@@ -28,6 +28,8 @@ internal class CSharpMakeMethodAsynchronousCodeFixProvider : AbstractMakeMethodA
private const string CS4034 = nameof(CS4034); // The 'await' operator can only be used within an async lambda expression. Consider marking this method with the 'async' modifier.
private const string CS0246 = nameof(CS0246); // The type or namespace name 'await' could not be found

private static readonly SyntaxToken s_asyncKeywordWithSpace = AsyncKeyword.WithoutTrivia().WithTrailingTrivia(Space);
Copy link
Member Author

Choose a reason for hiding this comment

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

fixing up the feature so it consistently emits async without messing with other trivia.

@@ -902,7 +902,8 @@ class C
{
public void M1()
{
Func<int, Task> foo = x => {
Func<int, Task> foo = x =>
{
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the correct formatting ew want. the previous results were undesirable.

@@ -49,7 +49,7 @@ class C
{
void M(int? x, int? y)
{
var z = x ?? y ;
var z = x ?? y;
Copy link
Member Author

Choose a reason for hiding this comment

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

same. the old results were undesirable.

/* 14 */// 15
/* 16 *//* 17 */
let y /* 18 */ = /* 19 */ x + 1/* 20 *///21
select y)/* 24 *//*27*///28
Copy link
Member Author

Choose a reason for hiding this comment

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

these results are expected. the other clauses align with the from now.

Copy link
Member Author

Choose a reason for hiding this comment

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

aside; these tests are insane. they don't reflect any sort of real code, and it's nigh impossible to reason about them.

{
3.ToString(); }
""");
CSharpParseOptions.Default);
Copy link
Member Author

Choose a reason for hiding this comment

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

this test was impossible to understand in its original form (due to how it concats strings). The updated test shows the full code sample, and shows the desired behavior (we don't touch the { on the method when inlining here.

@@ -690,7 +696,7 @@ class Program
static void Main()
{
int x = 2;
Bar(x < x, x > 1+2);
Bar(x < x, x > 1 + 2);
Copy link
Member Author

Choose a reason for hiding this comment

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

formatting this now because it's parsed as an arithmetic + binexpr.

@CyrusNajmabadi
Copy link
Member Author

@ToddGrun ptal

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review May 8, 2024 05:55
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 8, 2024 05:55
@CyrusNajmabadi
Copy link
Member Author

@ToddGrun this one is ready.

@ToddGrun
Copy link
Contributor

ToddGrun commented May 8, 2024

LGTM (I'll trust you on the behavior changes being desired, they seem good to me)

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge May 8, 2024 16:25
@CyrusNajmabadi CyrusNajmabadi merged commit c0a3973 into dotnet:main May 8, 2024
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the cleanupSyntax branch May 8, 2024 18:01
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 8, 2024
@CyrusNajmabadi
Copy link
Member Author

@jasonmalinowski For review when you get back.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants