Skip to content

Code actions to configure severity and IDE code style options with .editorconfig#35691

Merged
mavasani merged 20 commits intodotnet:release/dev16.3-preview1from
mavasani:ConfigureEditorConfig
Jun 12, 2019
Merged

Code actions to configure severity and IDE code style options with .editorconfig#35691
mavasani merged 20 commits intodotnet:release/dev16.3-preview1from
mavasani:ConfigureEditorConfig

Conversation

@mavasani
Copy link
Copy Markdown
Contributor

@mavasani mavasani commented May 13, 2019

This PR revives the work done in #29332 to add a code action to configure severity of diagnostics and code action to configure code style option values. Unlike that PR, which relied on .editorconfig being marked as an additional file, this PR uses the newly added AnalyzerConfigDocument for .editorconfig files. Screenshots and a small working snippet is attached below:

Top level menu: Now we nest all configure and suppress code actions into a sub-menu to avoid clutter in lightbulb
image

Create new .editorconfig with configured code style option value:
image

Update existing .editorconfig with new code style option value:
image

Create new .editorconfig with configured severity (also works for 3rd party analyzers):
image

Update existing .editorconfig with new severity (also works for 3rd party analyzers):
image

Supports different syntax for IDE diagnostics with code style option(s):
image

Code action snippet:
Configure_Severity_Screenshot

NOTE: I also had to thread through AnalyzerConfigDocuments at bunch of places in the workspace layer to get the creating/updating of this new document kind via a code action to work as expected. I have added relevant tests.

Future enhancements:
Current code fix only adds/updates a single closest .editorconfig relative to the file with the diagnostic. In future, we might want to enable customization of this via options.

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.

i thought i wrote a comment why we have this behavior :) can we move it over as well?

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.

I did not find any comment in the original code, but I have tried to retain the original semantics.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Pausing on this to try to figure out a good way to order the review.

@jasonmalinowski
Copy link
Copy Markdown
Member

@mavasani Is this something we can break into multiple commits?

@mavasani
Copy link
Copy Markdown
Contributor Author

Is this something we can break into multiple commits?

Let me break this into separate commits and force push...

@mavasani mavasani force-pushed the ConfigureEditorConfig branch from 5c9bd54 to 35bf81b Compare May 14, 2019 23:36
@mavasani
Copy link
Copy Markdown
Contributor Author

@jasonmalinowski @CyrusNajmabadi I have updated the PR to be split into multiple commits, hopefully it is easier to review.

  1. Commits 1-3: All the analyzer config document plumbing through Workspaces, EditorFeatures and Visual Studio layers
  2. Commit 4: Analyzer config and additional document test infrastructure support
  3. Rest of the commits - Support for the new code action and unit tests

I will now work on refactoring/sharing more code for analyzer config documents. Note that it is likely going to lead to helper methods with bunch of ugly lambdas, but probably that is better then cloning large pieces of code.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

@mavasani Thanks for putting in that effort!

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

CyrusNajmabadi commented May 15, 2019

  • 4c0459a25a556db891b467ed713e53415374095b. Small nits, some concerns about default switch behavior. Strongly think we should invest in a non-duplicative approach to files. But that's a non-blocking concern.
  • d839a0623c8507bb562dd78079bd1dc2133eb530. Looks fine. As per the comments, there's opportunity for sharing. Would like to see that done, but it's non-blocking.
  • 061b7108b23e049f9b3eeb9c0ad7c30ba64cd564. Looks fine. Makes me def want a better way to pass around information about a Document. I think we should have the base TextDocument have an enum-kind on it stating what sort of doc it is.

Note: the above commits look like they could be broken out into their own PR without the feature. Up to you if you want to do that.

  • 9348874797c8020cfd213f4394cdc04cb78bcc00. LGTM
  • 9a0e198a61289262d9d0cbb06263e75bddd20dcf. Strong opposition. I think this is a cutting-corners approach to this problem to avoid a proper design that any analyzer could play in. I've given similar feedback in the past about how our features which should be isolated are now leaking all over the codebase to make other features work. This just continues that and i think it needs to stop.
  • 2d76f29044e0fe8dd5c7336f3a7b9cecbb00b69f. Don't hate me, but i think ISuppressionOrConfiguration is really superfluous. I think this could just be IConfiguratoinXXX or ICodeFixConfigurationXXX. Configuration (to me) implies being able to do things like suppress and/or change severity. I don't think all the sub-purposes need ot be elevated into the name of the type.
  • 3ac247f435ae0a63aa7e03f1db1f31e22ee4d7f2. Skipped reviewing tests for now.
  • 74ae159267b2a15c7a36b7e835d49d09d7527c46. Somewhat skimming at this point.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi - I have reverted 1fb9371 for tracking mapping of diagnostic IDs to code style options. I have taken an alternate approach in 5b6cee9, which now requires each analyzer to explicitly provide the associated option with each supported descriptor. I will look at your other review comments now.

@mavasani Thanks for the change! I'm much happier with it. It def satisfies at least one of my goals, which is that the beahvior and description of the feature is contained within the feature itself. My other goal (which is absolutely not required and can come later) would be that this be a general part of the code-fixer infrastructure, and not limited to just our internal features.

My objection is withdrawn on that commit now. Thanks!

@mavasani
Copy link
Copy Markdown
Contributor Author

@CyrusNajmabadi I have addressed most of your review feedback with the latest commit.

@dotnet/roslyn-ide @heejaechang - would you be able to review this PR?

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi I have addressed most of your review feedback with the latest commit.

@mavasani Thanks! Will try to review this this weekend. I don't expect any issues, your responses all seemed sensible to me :)

mavasani added 3 commits June 2, 2019 07:19
…values from the light bulb.

We support configuration for boolean and enum based code style option values. The only unsupported current code style option from this fixer is specification of modifiers order, which is a custom user supplied string.
@mavasani mavasani changed the title Code action to configure severity with .editorconfig Code actions to configure severity and IDE code style options with .editorconfig Jun 5, 2019
@mavasani
Copy link
Copy Markdown
Contributor Author

mavasani commented Jun 5, 2019

FYI: I have pushed a new commit f1511b8, which adds a configuration fixer to enable configuring IDE code style option values from the lightbulb. I have updated the PR description and screenshots.

Tagging @jinujoseph @kendrahavens @mikadumont

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

the pictures are awesome. Can you show what it looks like to change the severity in this case:

image

@mavasani
Copy link
Copy Markdown
Contributor Author

mavasani commented Jun 5, 2019

image

I currently chose the implementation to add/update all code style option based entries instead of using dotnet_diagnostic.IDE0008.severity = error, which might add confusion as a subsequent entry for code style option will conflict with this entry. I felt it would be good to stick to following principle:

  1. Always use code style option based syntax (i.e. optionName = optionValue:severity) for IDE code style diagnostics.
  2. Always use compiler based syntax (i.e. dotnet_diagnostic.ID.severity = severity) for 3rd party diagnostics and non-code style IDE diagnostics.

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.

4 participants