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.89k stars 356 forks source link

Multiple regions inserted #282

Open khorvat opened 8 years ago

khorvat commented 8 years ago

Environment

I have been playing around with settings while testing some other reported issue (#281) and turned off "Remove regions ..." now on every cleanup and reorganization I get new regions inserted multiple times.

Steps to recreate

  1. Turn off "Remove regions"
  2. Turn on "Insert regions"

    Current behavior

Multiple regions are inserted in the code.

Expected behavior

Only one region per type should be inserted.

codecadwallader commented 8 years ago

When "Insert regions" alone is turned on, we will do an in place addition of regions based on wherever the code elements are present. Regions do not participate in sorting and are effectively treated as a nesting level (think private class) so it's possible to have the following:

public void Method1() { }
#region Methods
public void Method2() { }
#endregion

In this case Method1 picks up a region wrapper but Method2 is left unaffected. This happens because Method1 and Method2 are not recognized as being at the same hierarchy level unless "Remove regions" is also enabled.

I think this highlights that we've allowed for too many configuration options, and some of the option combinations are not logically handled. Using insert without remove will cause the behavior you've described in the scenario above.

My first reaction is to remove the options to use insert without remove since it isn't handled by the existing logic.. but it needs further consideration.