Skip to content

Conversation

@jmarolf
Copy link
Contributor

@jmarolf jmarolf commented Feb 18, 2022

Fixes #58089

This options looks like this in the UI:

image

To enable this functionality the user needs to

  1. have set a specific set of analyzer diagnostics as warning or error
  2. Go to the "configure code cleanup" menu

image

  1. Explicitly opt into this setting

image

3. Run the code cleanup profile where they modified that setting

image

  1. Or run the code cleanup profile on their project/solution

image

  1. Or have configured the profile to run on save

image

Rules for whether we apply a code fix with this option are as follows:

  1. The diagnostic is a warning or error
  2. The code fix for this diagnostic supports fix-all in document scope
  3. When applying the fix-all in document scope nothing outside the document changes

TODO:

  • Add a new option that is a superset of this option that allows you to "fix all warnings and errors set in editorconfig" that included formatting, code-style, and third-party analyzers.

@ghost ghost added the Area-IDE label Feb 18, 2022
@jmarolf jmarolf force-pushed the feature/run-third-party-codefixes-in-code-cleanup branch 2 times, most recently from 6d115eb to 5f62616 Compare February 18, 2022 00:24
@jmarolf jmarolf force-pushed the feature/run-third-party-codefixes-in-code-cleanup branch from 5f62616 to 811e06b Compare February 18, 2022 03:54
@jmarolf jmarolf force-pushed the feature/run-third-party-codefixes-in-code-cleanup branch 2 times, most recently from 5bc89f6 to 024a5df Compare February 23, 2022 01:23
@jmarolf jmarolf marked this pull request as ready for review February 23, 2022 01:29
@jmarolf jmarolf requested a review from a team as a code owner February 23, 2022 01:29
if (enabledDiagnostics.RunThirdPartyFixers)
{
progressTracker.AddItems(1);
}
Copy link
Member

Choose a reason for hiding this comment

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

can we add an item per 3rd party fixer?

Copy link
Member

Choose a reason for hiding this comment

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

unresolving :)

return null;

using var resultDisposer = ArrayBuilder<CodeFixCollection>.GetInstance(out var result);
var spanToDiagnostics = new SortedDictionary<TextSpan, List<DiagnosticData>>
Copy link
Member

Choose a reason for hiding this comment

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

why a List and not an ImmutableArray?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

StreamFixesAsync takes an argument of type SortedDictionary<TextSpan, List<DiagnosticData>> here

SortedDictionary<TextSpan, List<DiagnosticData>> spanToDiagnostics,

@CyrusNajmabadi I believe you wrote this code, do you recall why you used List<DiagnosticData>? Happy to change it to ImmutableArray<<DiagnosticData>>

Copy link
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

In every analyzer package I've seen, at most a strict subset of analyzers had code fixes which could be safely applied without the risk of breaking code (or silently changing behavior). This feature blanket assumes that all code fixes are safe, and will either be unusable or require a complete rewrite of the analyzer severity in projects.

@CyrusNajmabadi
Copy link
Member

CyrusNajmabadi commented Feb 23, 2022

I feel like we need an opt in or opt out option here. Preferably the former. Also, i mean: each fixer should opt into if it is safe to be used in this fashion.

@jmarolf jmarolf dismissed sharwell’s stale review February 25, 2022 00:35

addressed feedback

@jmarolf jmarolf force-pushed the feature/run-third-party-codefixes-in-code-cleanup branch from 6e67de4 to 73f608a Compare June 7, 2022 21:46
Copy link
Contributor

@ryzngard ryzngard left a comment

Choose a reason for hiding this comment

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

Overall looks good. Hope to get start testing this soon!


// If changes were made to the solution snap shot outside the current document discard the changes.
// The assumption here is that if we are applying a third party code fix to a document it only affects the document.
// Symbol renames and other complex refactorings we do not want to include in code cleanup.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do a follow up item to potentially log telemetry when this happens and notify the user?

@jmarolf jmarolf merged commit 06f579b into dotnet:main Jun 14, 2022
@ghost ghost added this to the Next milestone Jun 14, 2022
chsienki added a commit to chsienki/roslyn that referenced this pull request Jun 20, 2022
…d-party-codefixes-in-code-cleanup"

This reverts commit 06f579b, reversing
changes made to 9f6d52d.
@RikkiGibson RikkiGibson modified the milestones: Next, 17.3 P3 Jun 28, 2022
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.

Code cleanup supports third party analyzers

10 participants