codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

Checking "automatically run cleanup on file save" causes CSHTML file to not save.

Open falcon397 opened this issue 3 years ago • 1 comments

Environment

  • Visual Studio version: 2022 Professional
  • CodeMaid version: 12.0
  • Code language: HTML, C#

Description

I checked the box in the options to "automatically run cleanup on file save". Then I go into my CSHTML file, make some formatting changes, and save the file. The formatting changes happen, but the file remains unsaved. Or perhaps the save is causing a change to occur after the format completes and saves. This seems to be unique to CSHTML files, going to my CS files the save/cleanup works as expected.

Steps to recreate

  1. Create CSHTML file.
  2. Create some poorly formatted HTML markup.
  3. Enable "automatically run cleanup on file save" in the CodeMaid options.
  4. Save CSHTML file.

Current behavior

The file saves, but I think it is modified after the save in some way, and the IDE puts an * in the VS tab indicating the file has content to save. The images below are the before and after of saving the file with no additional edits on my part. I put a poorly formatted label tag in the file, CodeMaid fixed it correctly, but it leaves unsaved modifications after the save happens. The tab in the resulting image shows the file is modified. The * flashed, so it appears that CodeMaid saved the file, and time stamp on the file suggests this is the case. I'm thinking CodeMaid must be altering the file after the save happens.

image

image

Expected behavior

The file should format itself, and save, and not have any further edits to the file.

falcon397 avatar Apr 18 '22 15:04 falcon397

Thanks for reporting the issue. I have been able to reproduce it. I've looked at the CodeMaid diagnostics panel and confirmed the save event is only being triggered and executing once. I'm not sure what other behavior is kicking in after that event to cause it to modify further.

codecadwallader avatar May 03 '22 12:05 codecadwallader

@codecadwallader I have recently seen a related issue on plain .CS files. What I've seen is:

  1. have "automatically run cleanup on file save" enabled on the Code Main extension
  2. Modify an exisitng .CS file
  3. Save the file
  4. OUTCOME: file is saved correctly, but automatically set to an unsaved state in VS

cklogs avatar Oct 05 '22 21:10 cklogs

I'm seeing the exact same behavior as @codecadwallader

brooksca avatar Oct 07 '22 12:10 brooksca

I have not been able to reproduce the issue with C# files (using VS 17.4.0 Preview 2.1). Is it possible you have any other extensions installed that may also be triggered on save events?

codecadwallader avatar Oct 10 '22 15:10 codecadwallader

It's happening to me and to another collegue (plain CS). VS2022 + CodeMaid + XAML Styler and the default set of extensions (Live share, ML.NET, Xamarin, ..)

codingdna2 avatar Oct 10 '22 20:10 codingdna2

I have the same problem VS 17.3.5. I disabled all extras except xaml styler. When I turn on code maid, files stop saving. Only on manual closing the file modal window appear with question. For me, this is a fatal error because it is impossible to work and debug normally.

image

pchrist84 avatar Oct 11 '22 05:10 pchrist84

I have had the same experience as cklogs.

This same save behavior has affected .cs files and .xaml files for me.

kyleruddbiz avatar Oct 20 '22 20:10 kyleruddbiz

I have the same issue with cs files. Hope it will get fixed soon.

rmdg82 avatar Oct 21 '22 23:10 rmdg82

Same issue with cs files. I'm using VS Enterprise 2022 (64-bit) Version 17.3.6 and CodeMaid Version 12.0.300

ernestfolch avatar Oct 24 '22 08:10 ernestfolch

Same on every file in solution

yborisovp avatar Nov 04 '22 12:11 yborisovp

Same issue here

Visual Studio 2022 v17.3.2 Project: Net Framework 4.8 Codemaid v12.0.300

Tried disabling every extension i have installed, only the moment codemaid is enabled does the issue occure. Happens in both .cs and .cshtml files (not tried other file types)

AKruimink avatar Nov 05 '22 00:11 AKruimink

Thanks all for chiming in.

I was previously able to reproduce the issue with .cshtml but not .cs or .xaml.

I am no longer able to reproduce the issue in .cshtml files (nor other file types) using the latest preview version of Visual Studio 2022 v17.4.0 Preview 6.0. Can anyone who is regularly seeing the issue try the latest version of Visual Studio to see if it resolves it for them as well?

codecadwallader avatar Nov 10 '22 13:11 codecadwallader

Thanks all for chiming in.

I was previously able to reproduce the issue with .cshtml but not .cs or .xaml.

I am no longer able to reproduce the issue in .cshtml files (nor other file types) using the latest preview version of Visual Studio 2022 v17.4.0 Preview 6.0. Can anyone who is regularly seeing the issue try the latest version of Visual Studio to see if it resolves it for them as well?

Today I've updated my Visual Studio to the lastest version v17.4.0 and I'm not having the issue with the .cs files, now I'm able to use the Automatic Cleaup On Save without issues.

ernestfolch avatar Nov 10 '22 16:11 ernestfolch

After using this for a while it does seem to be fixed for me as well. Thanks for the help!

kyleruddbiz avatar Nov 27 '22 15:11 kyleruddbiz

As @ernestfolch says, I couldn't reproduce it too after update

yborisovp avatar Dec 26 '22 09:12 yborisovp