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

Clean up does NOT work in Visual Studio 2022 #908

Open Duelbat opened 2 years ago

Duelbat commented 2 years ago

UPDATE: After updating to the latest Visual Studio 2022 (17.1.0) and reinstalling Codemaid, everything is working!!!

brogdogg commented 2 years ago

💯

This was working for a while, but recently it has stopped working. We are using a solution configuration file for our settings.

brogdogg commented 2 years ago

If I can find time this week, I may try to debug this myself. I'm new to CodeMaid, but like the concept thus far.

codecadwallader commented 2 years ago

Thanks for reporting the issue. I have not been able to reproduce it. Can you please enable diagnostics mode (CodeMaid->Options->Diagnostics mode) and see if any useful information is provided in the Output tool window?

Some other information that would be helpful to provide:

jasonnissen commented 2 years ago

@codecadwallader

I am encountering this issue on an Azure Functions project. Here is the CodeMaid output:

[CodeMaid Handled Exception 10:56:53 AM] CodeMaid Cleanup for 'Function1.cs' was stopped: System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.VisualStudio.LanguageServices.Implementation.Utilities.Exceptions.ThrowEFail()
   at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.InternalElements.AbstractCodeElement.LookupNode()
   at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.InternalElements.AbstractCodeElement.GetStartPoint(vsCMPart part)
   at EnvDTE.CodeElement.GetStartPoint(vsCMPart Part)
   at SteveCadwallader.CodeMaid.Model.CodeItems.BaseCodeItemElement.get_StartPoint() in C:\src\codemaid\CodeMaidShared\Model\CodeItems\BaseCodeItemElement.cs:line 43
   at SteveCadwallader.CodeMaid.Logic.Cleaning.InsertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements[T](IEnumerable`1 codeElements) in C:\src\codemaid\CodeMaidShared\Logic\Cleaning\InsertBlankLinePaddingLogic.cs:line 254
   at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.RunCodeCleanupCSharp(Document document) in C:\src\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 283
   at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.<>c__DisplayClass19_0.<Cleanup>b__0() in C:\src\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 170
   at SteveCadwallader.CodeMaid.Helpers.UndoTransactionHelper.Run(Action tryAction, Action`1 catchAction) in C:\src\codemaid\CodeMaidShared\Helpers\UndoTransactionHelper.cs:line 55
Duelbat commented 2 years ago

@codecadwallader Thank you so much for getting back to me. I luuuuuuuuv this magic utility and worked with it in VS 2019. I am happy to report that after uninstalling VS 2022 PREVIEW and running the latest Visual Studio 2022 update to Version 17.1.0 then reinstalling CODEMAID, EVERYTHING is working !!!!!!!
P.S. If you ever change to a pricing model, I amongst many others would be happy to pay!! Many thanks, appreciate your time and efforts!

Duelbat commented 2 years ago

I have to report that this is once again not working. There was some strange behavior of it not allowing me to save a Razor page in my Blazor project. I then uninstalled it and reinstalled it. After new installation, it does not work again.

codecadwallader commented 2 years ago

Can you please enable diagnostics mode (CodeMaid->Options->Diagnostics mode) and see if any useful information is provided in the Output tool window?

xiaoyuvax commented 2 years ago

met the same problem, no action is functioning. Diagnostics mode enabled, no output seen. 17.1.3

brogdonm commented 2 years ago

I finally was able to get something from the diagnostic messages:

[CodeMaid Handled Exception 07:38:06 PM] CodeMaid Cleanup for '*****Controller.cs' was stopped: System.Runtime.InteropServices.COMException (0x8001010E): ReplaceFileHeaderDocumentStart must be called on the UI thread.
   at Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(String callerMemberName)
   at SteveCadwallader.CodeMaid.Logic.Cleaning.FileHeaderLogic.ReplaceFileHeaderDocumentStart(TextDocument textDocument, String settingsFileHeader) in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\FileHeaderLogic.cs:line 237
   at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.RunCodeCleanupCSharp(Document document) in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 264
   at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.<>c__DisplayClass19_0.<Cleanup>b__0() in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 170
   at SteveCadwallader.CodeMaid.Helpers.UndoTransactionHelper.Run(Action tryAction, Action`1 catchAction) in C:\projects\codemaid\CodeMaidShared\Helpers\UndoTransactionHelper.cs:line 55
codecadwallader commented 2 years ago

That most recent call stack error message I believe is fixed in the upcoming version. You can check the VS2022 CI build here to see if it helps. https://www.vsixgallery.com/extension/9079e73d-3fbb-4e07-8dab-f44fa5d8e8b5

xiaoyuvax commented 2 years ago

Now the maid is back, thx.

LVNov commented 2 years ago

Hi there. Just updated to VS2022, installed the extension and got this exception:

[CodeMaid Handled Exception 09:54:33 PM] CodeMaid Cleanup for 'DebugStuff.cs' was stopped: System.ArgumentException: startingPosition (14139) must lie inside searchRange ([0..14138))
Parameter name: startingPosition
   at Microsoft.VisualStudio.Text.Find.Implementation.BaseFinderForSnapshot.AdjustSearchRange(Int32 startingPosition, Span searchRange)
   at Microsoft.VisualStudio.Text.Find.Implementation.BaseFinderForSnapshot.TryFind(Int32 startingPosition, Span searchRange, Span& result)
   at Microsoft.VisualStudio.Text.Find.Implementation.BaseFinderForSnapshot.TryFind(Int32 startingPosition, Span& result)
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.<>c__DisplayClass4_0.<TryFindNextMatch>b__0() in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 130
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.<>c__DisplayClass20_0.<<RunOnUIThread>b__0>d.MoveNext() in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 448
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.RunOnUIThread(Action action) in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 450
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.TryFindNextMatch(EditPoint startPoint, EditPoint& endPoint, String patternString) in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 144
   at SteveCadwallader.CodeMaid.Logic.Cleaning.UpdateLogic.UpdateEndRegionDirectives(TextDocument textDocument) in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\UpdateLogic.cs:line 72
   at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.RunCodeCleanupCSharp(Document document) in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 335
   at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.<>c__DisplayClass19_0.<Cleanup>b__0() in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 170
   at SteveCadwallader.CodeMaid.Helpers.UndoTransactionHelper.Run(Action tryAction, Action`1 catchAction) in C:\projects\codemaid\CodeMaidShared\Helpers\UndoTransactionHelper.cs:line 55
Duelbat commented 2 years ago

Hi there. Just updated to VS2022, installed the extension and got this exception:

[CodeMaid Handled Exception 09:54:33 PM] CodeMaid Cleanup for 'DebugStuff.cs' was stopped: System.ArgumentException: startingPosition (14139) must lie inside searchRange ([0..14138))
Parameter name: startingPosition
   at Microsoft.VisualStudio.Text.Find.Implementation.BaseFinderForSnapshot.AdjustSearchRange(Int32 startingPosition, Span searchRange)
   at Microsoft.VisualStudio.Text.Find.Implementation.BaseFinderForSnapshot.TryFind(Int32 startingPosition, Span searchRange, Span& result)
   at Microsoft.VisualStudio.Text.Find.Implementation.BaseFinderForSnapshot.TryFind(Int32 startingPosition, Span& result)
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.<>c__DisplayClass4_0.<TryFindNextMatch>b__0() in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 130
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.<>c__DisplayClass20_0.<<RunOnUIThread>b__0>d.MoveNext() in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 448
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.RunOnUIThread(Action action) in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 450
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.TryFindNextMatch(EditPoint startPoint, EditPoint& endPoint, String patternString) in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 144
   at SteveCadwallader.CodeMaid.Logic.Cleaning.UpdateLogic.UpdateEndRegionDirectives(TextDocument textDocument) in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\UpdateLogic.cs:line 72
   at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.RunCodeCleanupCSharp(Document document) in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 335
   at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.<>c__DisplayClass19_0.<Cleanup>b__0() in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 170
   at SteveCadwallader.CodeMaid.Helpers.UndoTransactionHelper.Run(Action tryAction, Action`1 catchAction) in C:\projects\codemaid\CodeMaidShared\Helpers\UndoTransactionHelper.cs:line 55

Just pop over to Devexpress and download its CODERUSH. It's now free and will do everything that you need. I am afraid that Codemaid has been on shaky ground ever since VS 2022 got released. See link: https://www.devexpress.com/

LVNov commented 2 years ago

@Duelbat thanks, but I'm a faithful CodeMaid user.

@codecadwallader hey man, is there any update on the situation? Can I help somehow?

Duelbat commented 2 years ago

@LVNov I was also a very faithful user of CodeMaid in VS 2019. But code clean up was a mandatory feature. It does not work in 2022. So Devexpress to to the resuce.

lolodi commented 1 year ago

I was having problems where CodeMaid was not able to cleanup projects if I rich click clean. But it was able to clean up single files on save. After some trial and error, I found out that removing the file header in the Update portion of the Options fixed the problem. I'm now able to clean all the files in a project at once. The error I was getting was: image

Leuconoe commented 1 year ago

It happened when I wrapped it in a preprocessor to briefly backup the code I was working on.

For example.

#if backup
//backups
#else
//Error here?
#endif
OculiViridi commented 7 months ago

The issue still persists on CodeMaid v12.0.300 on Visual Studio 2022 v17.8.4.

fdrumondwoolworths commented 4 months ago

The issue also happens in VS 2022 Version 17.9.6