codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.92k stars 362 forks source link

Analyzer codefix action triggers CodeMaid cleanup, crash #811

Open osoviejo opened 3 years ago

osoviejo commented 3 years ago

Environment

Description

Roslyn analyzer codefix (at least for IDExxxx analyzers, maybe others) will trigger a CodeMaid cleanup on the file where the codefix is being applied. Neither the codefix nor the cleanup completes, and VS is non-responsive. After a few minutes, VS will crash and restart. While the attached repro is a Net5 Console, this also occurs with Framework 4.8 ASP.NET.

Steps to recreate

  1. Open the attached Net5 Console template app, which includes a CodeMaid.config and an .editorconfig.
  2. Open the Program.cs file, and observe the IDE1006 naming violation for the private const _foo.
  3. Apply the IDE1006 codefix to remove the leading underscore.

Current behavior

CodeMaid cleanup starts, neither it nor the codefix completes before VS crashes.

Expected behavior

CodeMaid cleanup should not be triggered by an analyzer codefix.

Template.zip VS CM crash

codecadwallader commented 3 years ago

Thanks for reporting the issue and for providing the sample solution. I am able to reproduce it.

What I believe is happening is that executing the code fix triggers a save, then if CodeMaid is configured for automatic cleanup on save it kicks in to further update the code. In the past where this particularly gets into a conflict between multiple write triggers is the undo API.

There's an option specifically for this scenario at CodeMaid->Options->General->Miscellaneous->Use undo transactions->Skip during automatic cleanup on save. If you re-enable this option it will bypass trying to group CodeMaid's cleanup activities in the undo log, and that effectively bypasses the loop that can cause the IDE to freeze up. I checked and confirmed with the sample solution that indeed this bypassed the issue.

Hope it helps!

osoviejo commented 3 years ago

Works perfectly, thank you so much!