codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

Analyzer codefix action triggers CodeMaid cleanup, crash

Open osoviejo opened this issue 4 years ago • 2 comments

Environment

  • Visual Studio version: 2019 Community 16.9.4
  • CodeMaid version: 11.2, or 11.2.247 (issue 795 proposed fix)
  • Code language: C#

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

osoviejo avatar May 15 '21 02:05 osoviejo

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!

codecadwallader avatar May 20 '21 12:05 codecadwallader

Works perfectly, thank you so much!

osoviejo avatar May 20 '21 13:05 osoviejo