Skip to content

Add feature to convert from top-level-statements to Program.Main form#60383

Merged
JoeRobich merged 69 commits intodotnet:mainfrom
CyrusNajmabadi:programMain
Apr 6, 2022
Merged

Add feature to convert from top-level-statements to Program.Main form#60383
JoeRobich merged 69 commits intodotnet:mainfrom
CyrusNajmabadi:programMain

Conversation

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Mar 25, 2022

Comes with style option: csharp_style_prefer_top_level_statements

Looks like:

image

Todo:

  • Provide way to go from Program.Main to top-level-statements
  • Provide refactoring on top of fixer to go the other direction if the style is there, but set to hidden
  • Have the new-file generation code respect this option if present.

@ghost ghost added the Area-IDE label Mar 25, 2022
namespace Microsoft.CodeAnalysis.CSharp.ConvertProgram
{
[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ConvertToProgramMain), Shared]
internal class ConvertToProgramMainCodeFixProvider : SyntaxEditorBasedCodeFixProvider
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That should be in Analyzers layer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this matches the ConvertNamespace fixer work. we can move both over at the same time if appropriate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@CyrusNajmabadi This causes bugs like #45569

There are many codefixes that are misplaced in Features. I think it's better if future codefixes are placed properly making the future work to move everything to Analyzers more manageable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so, i'm amenable to that, but i think ti should be done as a general work item that also ensures that the analyzer/fixer layer has all the appropraite other extensions/modules needed to make that work.

CyrusNajmabadi and others added 4 commits March 25, 2022 11:16
Co-authored-by: Youssef Victor <youssefvictor00@gmail.com>
…MainDiagnosticAnalyzer.cs

Co-authored-by: Youssef Victor <youssefvictor00@gmail.com>
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Perhaps a test or two with a file that has a file header, just to make sure that is maintained?

Will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants