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

Fix Exception from Header when cleaning up all code #912

Open CrutchTheClutch opened 2 years ago

CrutchTheClutch commented 2 years ago

Attempts to fix #859

codecadwallader commented 2 years ago

Thanks for opening the PR, I appreciate it. The code changes look pretty straight forward and good to me. May I ask what kind of testing you did with these changes?

I'm not sure why the build failed, it just seems to have exited. Perhaps it was just an intermittent issue although we haven't usually seen those.

lflender commented 2 years ago

The build fails because it does not compile. Calling UIThread.Run on GetCurrentHeader does not return the expected return value.

There is an easier way to fix that issue, we only need to call UIThread.Run inside UpdateFileHeader, like this:


            switch ((HeaderUpdateMode)Settings.Default.Cleaning_UpdateFileHeader_HeaderUpdateMode)
            {
                case HeaderUpdateMode.Insert:
                    UIThread.Run(() =>
                    {
                        InsertFileHeader(textDocument, settingsFileHeader);
                    });
                    break;

                case HeaderUpdateMode.Replace:
                    UIThread.Run(() =>
                    {
                        ReplaceFileHeader(textDocument, settingsFileHeader);
                    });
                    break;

No further change is needed.

I encountered the issue (not sure why it didn't show up during my dev, I tested it dozens and dozens of times) and this change fixed it.