Skip to content

Fix MakeLocalFunctionStatic for top-level local function#56473

Merged
jcouv merged 4 commits intodotnet:mainfrom
jcouv:static-localfunction
Sep 17, 2021
Merged

Fix MakeLocalFunctionStatic for top-level local function#56473
jcouv merged 4 commits intodotnet:mainfrom
jcouv:static-localfunction

Conversation

@jcouv
Copy link
Copy Markdown
Member

@jcouv jcouv commented Sep 17, 2021

Fixes #53179

@jcouv jcouv self-assigned this Sep 17, 2021
@ghost ghost added the Area-IDE label Sep 17, 2021
@jcouv jcouv marked this pull request as ready for review September 17, 2021 03:29
@jcouv jcouv requested a review from a team as a code owner September 17, 2021 03:29
Comment on lines +526 to +528

//await TestAsync(initialMarkup, expectedMarkup, WithRegularOptions(parameters));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
//await TestAsync(initialMarkup, expectedMarkup, WithRegularOptions(parameters));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oops, sorry about that


return Task.CompletedTask;

static SyntaxNode unwrapGlobalStatement(SyntaxNode node)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
static SyntaxNode unwrapGlobalStatement(SyntaxNode node)
static SyntaxNode UnwrapGlobalStatement(SyntaxNode node)

SyntaxEditor editor, CancellationToken cancellationToken)
{
var localFunctions = diagnostics.SelectAsArray(d => d.AdditionalLocations[0].FindNode(cancellationToken));
var localFunctions = diagnostics.SelectAsArray(d => unwrapGlobalStatement(d.AdditionalLocations[0].FindNode(cancellationToken)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
var localFunctions = diagnostics.SelectAsArray(d => unwrapGlobalStatement(d.AdditionalLocations[0].FindNode(cancellationToken)));
var localFunctions = diagnostics.SelectAsArray(d => d.AdditionalLocations[0].FindNode(getInnermostNodeForTie: true, cancellationToken));

Comment on lines +59 to +62
static SyntaxNode unwrapGlobalStatement(SyntaxNode node)
{
return node is GlobalStatementSyntax globalStatement ? globalStatement.Statement : node;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
static SyntaxNode unwrapGlobalStatement(SyntaxNode node)
{
return node is GlobalStatementSyntax globalStatement ? globalStatement.Statement : node;
}

}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeLocalFunctionStatic)]
[WorkItem(53179, "https://github.com/dotnet/roslyn/issues/53179")]
Copy link
Copy Markdown
Member

@Youssef1313 Youssef1313 Sep 17, 2021

Choose a reason for hiding this comment

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

This issue is about about the CodeRefactoringProvider, not the CodeFixProvider.

Might be good to add a test to the coderefactoring if it already works (or fix it if it doesn't).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, added a test. They do share the code so worked fine :-)

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Needed?

@jcouv jcouv enabled auto-merge (squash) September 17, 2021 16:13
@jcouv jcouv merged commit a73ef13 into dotnet:main Sep 17, 2021
@ghost ghost added this to the Next milestone Sep 17, 2021
@Cosifne Cosifne modified the milestones: Next, 17.0.P5 Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MakeLocalFunctionStaticCodeRefactoringProvider crashes casting LocalFunctionSymbol to SynthesizedSimpleProgramEntryPointSymbol

4 participants