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

Move few CodeFixProviders to Analyzers layer #60524

Merged
merged 8 commits into from
Apr 5, 2022

Conversation

Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Apr 1, 2022

This doesn't move everything. I may open follow up PRs.

@mavasani Can you take a look please?

@Youssef1313 Youssef1313 requested a review from a team as a code owner April 1, 2022 14:25
@ghost ghost added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Apr 1, 2022
@Youssef1313
Copy link
Member Author

Making a draft for now since it doesn't yet build successfully. I'll be force-pushing so you can wait on reviewing until it builds.

@Youssef1313 Youssef1313 marked this pull request as draft April 1, 2022 14:36
@Youssef1313 Youssef1313 force-pushed the move-some-fixes branch 5 times, most recently from 92d4545 to e8c0ca8 Compare April 1, 2022 17:45
@Youssef1313 Youssef1313 changed the title Move few 'CodeFixProvider's to Analyzers layer Move few CodeFixProviders to Analyzers layer Apr 1, 2022
@Youssef1313 Youssef1313 force-pushed the move-some-fixes branch 3 times, most recently from 47ac429 to ece3473 Compare April 1, 2022 19:19
@Youssef1313
Copy link
Member Author

@mavasani One of the codefixes I'm moving in this PR is using ExpressionGenerator, which isn't available in CodeStyle. Any advice here? Should I add it as a public API in SyntaxGenerator?

@Youssef1313
Copy link
Member Author

@mavasani I attempted to move those CodeGeneration classes into the shared workspaces project, but:

  • There was many cascaded changes due to that.
  • It still doesn't build. Embarrassing that I don't understand the compile errors. They're like this:

4>C:\Users\PC\Desktop\Roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\CodeGeneration\CSharpSyntaxGenerator.cs(48,40,48,50): error CS0115: 'CSharpSyntaxGenerator.Whitespace(string)': no suitable method found to override
4>C:\Users\PC\Desktop\Roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\CodeGeneration\CSharpSyntaxGenerator.cs(27,20,27,41): error CS0534: 'CSharpSyntaxGenerator' does not implement inherited abstract member 'SyntaxGenerator.Whitespace(string)'

This is very confusing :(

var options = _document.Project.AnalyzerOptions.GetAnalyzerOptionSet(_node.SyntaxTree, cancellationToken);
#else
var options = await _document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

man, i would love an extension for this.

actions.ToImmutable(), isInlinable: false),
context.Diagnostics);
#pragma warning restore RS0005 // Do not use generic 'CodeAction.Create' to create 'CodeAction'
Copy link
Member

Choose a reason for hiding this comment

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

seems problematic.

var groupingTitle = string.Format(CodeFixesResources.Alias_ambiguous_type_0, diagnosticNode.ToString());
#pragma warning disable RS0005 // Do not use generic 'CodeAction.Create' to create 'CodeAction'
var groupingCodeAction = CodeAction.Create(groupingTitle, codeActionsBuilder.ToImmutable(), isInlinable: true);
#pragma warning restore RS0005 // Do not use generic 'CodeAction.Create' to create 'CodeAction'
Copy link
Member

Choose a reason for hiding this comment

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

seems problematic.

Copy link
Member Author

Choose a reason for hiding this comment

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

@CyrusNajmabadi I don't think there is a problem regarding the suppression.

The analyzer will be removed soon anyway when @mavasani PR that fixes telemetry is merged.

There are already few suppressions also anyway.

@CyrusNajmabadi
Copy link
Member

One of the codefixes I'm moving in this PR is using ExpressionGenerator, which isn't available in CodeStyle. Any advice here? Should I add it as a public API in SyntaxGenerator?

Source link the generator code

@Youssef1313
Copy link
Member Author

Youssef1313 commented Apr 2, 2022

One of the codefixes I'm moving in this PR is using ExpressionGenerator, which isn't available in CodeStyle. Any advice here? Should I add it as a public API in SyntaxGenerator?

Source link the generator code

@CyrusNajmabadi I ended up with the same compile errors after adding some needed files using <Compile Include="..." Link="..." />:

  <ItemGroup>
    <Compile Include="..\..\..\Workspaces\CSharp\Portable\CodeGeneration\ExpressionGenerator.cs" Link="CodeGeneration\CSharp\ExpressionGenerator.cs" />
    <Compile Include="..\..\..\Workspaces\CSharp\Portable\CodeGeneration\CSharpFlagsEnumGenerator.cs" Link="CodeGeneration\CSharp\CSharpFlagsEnumGenerator.cs" />
    <Compile Include="..\..\..\Workspaces\CSharp\Portable\CodeGeneration\CSharpSyntaxGenerator.cs" Link="CodeGeneration\CSharp\CSharpSyntaxGenerator.cs" />
    <Compile Include="..\..\..\Workspaces\Core\Portable\CodeGeneration\CodeGenerationHelpers.cs" Link="CodeGeneration\Core\ExpressionGenerator.cs" />
    <Compile Include="..\..\..\Workspaces\Core\Portable\CodeGeneration\CodeGenerationOptions.cs" Link="CodeGeneration\Core\CodeGenerationOptions.cs" />
    <Compile Include="..\..\..\Workspaces\Core\Portable\CodeGeneration\CodeGenerationContext.cs" Link="CodeGeneration\Core\CodeGenerationContext.cs" />
    <Compile Include="..\..\..\Workspaces\Core\Portable\CodeGeneration\LiteralSpecialValues.cs" Link="CodeGeneration\Core\LiteralSpecialValues.cs" />
    <Compile Include="..\..\..\Workspaces\Core\Portable\CodeGeneration\AbstractFlagsEnumGenerator.cs" Link="CodeGeneration\Core\AbstractFlagsEnumGenerator.cs" />
    <Compile Include="..\..\..\Workspaces\Core\Portable\CodeGeneration\CodeGenerator.cs" Link="CodeGeneration\Core\CodeGenerator.cs" />
    <Compile Include="..\..\..\Workspaces\Core\Portable\CodeGeneration\ICodeGenerationService.cs" Link="CodeGeneration\Core\ICodeGenerationService.cs" />
    <Compile Include="..\..\..\Workspaces\Core\Portable\CodeGeneration\Symbols\CodeGenerationSymbol.cs" Link="CodeGeneration\Core\Symbols\CodeGenerationContext.cs" />
    <Compile Include="..\..\..\Workspaces\Core\Portable\CodeGeneration\CodeGenerationDestination.cs" Link="CodeGeneration\Core\CodeGenerationDestination.cs" />
  </ItemGroup>

@Youssef1313
Copy link
Member Author

@CyrusNajmabadi I think I understood why it doesn't compile. The members that have the errors I mentioned above are internal abstract. The type SyntaxGenerator is already visible since it's public, so it doesn't need to be source-linked. Hence, there is no way to implement the internal abstract methods.

I tried adding IVT, but I get too many errors similar to:

9>C:\Users\PC\Desktop\Roslyn\src\Workspaces\Core\Portable\CodeGeneration\Symbols\CodeGenerationSymbol.cs(19,47,19,67): warning CS0436: The type 'CodeGenerationSymbol' in 'C:\Users\PC\Desktop\Roslyn\src\Workspaces\Core\Portable\CodeGeneration\Symbols\CodeGenerationSymbol.cs' conflicts with the imported type 'CodeGenerationSymbol' in 'Microsoft.CodeAnalysis.Workspaces, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Using the type defined in 'C:\Users\PC\Desktop\Roslyn\src\Workspaces\Core\Portable\CodeGeneration\Symbols\CodeGenerationSymbol.cs'.
9>C:\Users\PC\Desktop\Roslyn\src\Analyzers\CSharp\CodeFixes\UsePatternMatching\CSharpUseNotPatternCodeFixProvider.cs(24,65,24,97): error CS0433: The type 'SyntaxEditorBasedCodeFixProvider' exists in both 'Microsoft.CodeAnalysis.CodeStyle.Fixes, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'Microsoft.CodeAnalysis.Workspaces, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

@Youssef1313
Copy link
Member Author

@mavasani @CyrusNajmabadi I'm going to move the specific problematic CodeFixProvider to Features back.

@Youssef1313
Copy link
Member Author

@CyrusNajmabadi @mavasani This is ready for review.

@Youssef1313 Youssef1313 marked this pull request as ready for review April 2, 2022 14:23
@CyrusNajmabadi
Copy link
Member

I believe we have SyntaxGenerator and SyntaxGeneratorInternal for this reason.

@Youssef1313
Copy link
Member Author

@CyrusNajmabadi I'll take a look into that in another PR. There are lots of work to move everything to Analyzers anyway :)

@mavasani
Copy link
Contributor

mavasani commented Apr 4, 2022

@Youssef1313 I had taken a stab at moving CodeGeneration pieces down to the shared layer, and just as you disccovered, it leads to a lot of cascading changes. I also filed #43056 for making relevant APIs public, but that would need a design proposal and discussion. If you are interested, feel free to take a stab at coming up with the API proposal.

Additionally, this issue tracks bunch more cleanup/porting/follow-up items for the move down to the shared analyzers/fixes layer. Feel free to pick up anything from there if you are interested.

Thank you again for your efforts here!

Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

Mostly LGTM - have a code refactoring suggestion. Once you address/respond, I can merge the PR. Thanks!

@Youssef1313
Copy link
Member Author

@mavasani Thanks for review! Can you take another look?

@mavasani
Copy link
Contributor

mavasani commented Apr 5, 2022

@Youssef1313 You also have merge conflicts.

@mavasani mavasani merged commit 60a165c into dotnet:main Apr 5, 2022
@ghost ghost added this to the Next milestone Apr 5, 2022
@Youssef1313 Youssef1313 deleted the move-some-fixes branch April 5, 2022 23:00
@dibarbet dibarbet modified the milestones: Next, 17.3.P1 Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants