codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

File Header is inserted again, even if it already exists

Open VVander opened this issue 5 years ago • 3 comments

Environment

  • Visual Studio version: 2019 Pro
  • CodeMaid version: 11.1
  • Code language: C#

Description

The file header is being inserted multiple times, even when it's not changed at all.

Probably related to this issue, however I am seeing this behavior even without the leading/trailing lines.

I think it's probably because CodeMaid skips formatting for comments that start with no spaces e.g. //abc instead of // abc. However, we had to do this so that CodeMaid wouldn't mess up our copyright banner (also see issue 548)

See attached settings for repro.

Steps to recreate

  1. "Enable Automatic Cleanup On Save" (General->Features) and "Run format comments during cleanup" (Formating)
  2. Set the File Header for C# in the Cleaning->Update options to...
//%BANNER_BEGIN%
// ---------------------------------------------------------------------
//%COPYRIGHT_BEGIN%
//<copyright file="My File.cs" company="My Company">
//     Copyright (c) 2018-present, My Company, Inc. All Rights Reserved.
//</copyright>
//%COPYRIGHT_END%
// ---------------------------------------------------------------------
//%BANNER_END%
  1. Save the file w/ ctrl+s and watch your header multiply!

Current behavior

The header is being inserted again and again even though it's already there.

Expected behavior

The header should only exist once. CodeMaid Settings.zip

VVander avatar Oct 08 '20 23:10 VVander

Thanks for reporting the issue and for including your settings. I was able to reproduce it and trace it down to trailing whitespace similar (but a little different) to #310

The second line of hyphens includes a trailing space. Here's a screenshot of the settings with white space visible:

image

When cleanup runs, this end of line space is removed.. and then when cleanup next runs the copyright header is considered different and gets inserted again. Deleting that space resolved the issue for me.

Hope it helps!

codecadwallader avatar Oct 14 '20 12:10 codecadwallader

Hello! I noticed that if I save a file the header gets added correctly, but If run Cleanup All Code on a project the header is not added at all, while the rest of the cleanup is carried out as expected. Ideas?

lolodi avatar Apr 06 '23 00:04 lolodi

Thanks for reporting the issue, I have been able to reproduce it. I found this error message in diagnostics mode:

InsertFileHeaderDocumentStart must be called on the UI thread.

It sounds like we need to add logic to marshal back onto the UI thread for this cleanup operation.

codecadwallader avatar Apr 29 '23 19:04 codecadwallader